Eu tento monitorar o serviço através de reator de sal e beacon. Se o evento acontecer (por exemplo: parada do serviço nginx em um lacaio), é necessário gravá-lo em um arquivo no mestre de sal.
Não tenho ideia de como chamar os dados do evento e passá-los para write_file.sls
. Alguém pode me ajudar?
root@SALTMASTERLOCAL:/var/log/salt# salt-run reactor.list
event:
----------
suffix:
salt/reactors/manage/list
|_
----------
salt/beacon/*/service/:
- /srv/salt/monitoring/9spokesBeaconN.sls
O arquivo /srv/salt/monitoring/9spokesBeaconN.sls
:
load_service_monitoring:
local.state.apply:
- tgt: '*MASTER*'
- arg:
- monitoring.write_file
- kwarg:
new_minion: {{ data }}
O arquivo monitoring/write_file.sls
:
{% from "monitoring/9spokesBeaconN.sls" import new_minion %}
create /root/beacons_load.confvg file:
file.append:
- name: /root/beacons_load.confvg
- text: {{ new_minion }}
Resultado / Saída:
Event fired at Sun Dec 4 20:27:02 2016
*************************
Tag: salt/beacon/minion1/service/
Data:
{'_stamp': '2016-12-04T20:27:02.762722',
'data': {'id': 'minion1',
'nginx': {'running': False, 'uncleanshutdown': False}},
'tag': 'salt/beacon/minion1/service/'}
Event fired at Sun Dec 4 20:27:02 2016
*************************
Tag: 20161204202702853337
Data:
{'_stamp': '2016-12-04T20:27:02.853564', 'minions': ['SALTMASTERLOCAL']}
Event fired at Sun Dec 4 20:27:02 2016
*************************
Tag: salt/job/20161204202702853337/new
Data:
{'_stamp': '2016-12-04T20:27:02.853982',
'arg': ['monitoring.write_file',
{'__kwarg__': True,
'new_minion': {'_stamp': '2016-12-04T20:27:02.762722',
'data': {'id': 'minion1',
'nginx': {'running': False,
'uncleanshutdown': False}},
'tag': 'salt/beacon/minion1/service/'}}],
'fun': 'state.apply',
'jid': '20161204202702853337',
'minions': ['SALTMASTERLOCAL'],
'tgt': '*MASTER*',
'tgt_type': 'glob',
'user': 'root'}
Event fired at Sun Dec 4 20:27:04 2016
*************************
Tag: salt/job/20161204202702853337/ret/SALTMASTERLOCAL
Data:
{'_stamp': '2016-12-04T20:27:04.120195',
'cmd': '_return',
'fun': 'state.apply',
'fun_args': ['monitoring.write_file',
{'new_minion': {'_stamp': '2016-12-04T20:27:02.762722',
'data': {'id': 'minion1',
'nginx': {'running': False,
'uncleanshutdown': False}},
'tag': 'salt/beacon/minion1/service/'}}],
'id': 'SALTMASTERLOCAL',
'jid': '20161204202702853337',
'out': 'highstate',
'retcode': 1,
'return': ["Rendering SLS 'base:monitoring.write_file' failed: Jinja variable 'data' is undefined\n/var/cache/salt/minion/files/base/monitoring/9spokesBeaconN.sls(7):\n---\n[...]\n local.state.apply:\n - tgt: '*MASTER*'\n - arg:\n - monitoring.write_file\n - kwarg:\n new_minion: {{ data }} <======================\n---"],
'success': True}
Logs:
2016-12-04 20:27:04,114 [salt.state ][CRITICAL][7773] Rendering SLS 'base:monitoring.write_file' failed: Jinja variable 'data' is undefined
/var/cache/salt/minion/files/base/monitoring/9spokesBeaconN.sls(7):
---
[...]
local.state.apply:
- tgt: '*MASTER*'
- arg:
- monitoring.write_file
- kwarg:
new_minion: {{ data }} <======================
---