I'm trying to remotely stop/start services using systemctl
inside Zabbix's system.run[]
request/item but it doesn't seem to work.
I'm using Zabbix 3.0 JSON-RPC API and my JSON looks like this:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"filter": {
"host": "host-name",
"key_": "system.run[sudo systemctl stop nginx.service]"
}
},
"id": 1,
"auth": "my-token"
}
Result:
{"jsonrpc":"2.0","result":[],"id":1}
But I'm not too sure about validity of this request because all the information I've seen on system.run[]
so far was related to zabbix_get. Is it even possible to execute system.run[]
this way? What am I doing wrong?
This is obviously just filtering items but I have no idea how to replicate what zabbix_get does using Zabbix JSON-RPC API. There is no information I could find about this.
This works well for gathering data, tho:
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"filter": {
"host": "host-name",
"key_": "vm.memory.size[used]"
}
},
"id": 1,
"auth": "my-token"
}
Result:
{
"jsonrpc": "2.0",
"result": [
{
"itemid": "455",
"type": "0",
"snmp_community": "",
"snmp_oid": "",
"hostid": "12241",
"name": "Used memory",
"key_": "vm.memory.size[used]",
"delay": "60",
"history": "90",
"trends": "365",
"status": "0",
"value_type": "3",
"trapper_hosts": "",
"units": "B",
"multiplier": "0",
"delta": "0",
"snmpv3_securityname": "",
"snmpv3_securitylevel": "0",
"snmpv3_authpassphrase": "",
"snmpv3_privpassphrase": "",
"formula": "1",
"error": "",
"lastlogsize": "0",
"logtimefmt": "",
"templateid": "106",
"valuemapid": "0",
"delay_flex": "",
"params": "",
"ipmi_sensor": "",
"data_type": "0",
"authtype": "0",
"username": "",
"password": "",
"publickey": "",
"privatekey": "",
"mtime": "0",
"flags": "0",
"interfaceid": "2",
"port": "",
"description": "",
"inventory_link": "0",
"lifetime": "30",
"snmpv3_authprotocol": "0",
"snmpv3_privprotocol": "0",
"state": "0",
"snmpv3_contextname": "",
"evaltype": "0",
"lastclock": "1466142275",
"lastns": "142277413",
"lastvalue": "3971121455",
"prevvalue": "3971001230"
}
],
"id": 1
}
If someone managed to execute system.run[]
using JSON-RPC API, please, share your solution.
Thank you.