资料参考:https://www.zabbix.com/documentation/4.0/zh/manual/api
看api文档就可以了,粘两个例子吧,如果配置了域名,可以请求域名
[root@node ~]# vi zabbix_login.api
curl -XPOST -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "zabbix"
},
"id": 1,
"auth": null
}' http://serverIP/zabbix/api_jsonrpc.php
[root@node ~]# sh zabbix.api
{"jsonrpc":"2.0","result":"8b16faa2f8c9d02f0a6694d667774bac","id":1}
拿到用户用户认证令牌后,就可以使用令牌来操作了
[root@node ~]# vi zabbix_gethost.api
curl -XPOST -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"hostid",
"host"
],
"selectInterfaces": [
"interfaceid",
"ip"
]
},
"id": 2,
"auth": "8b16faa2f8c9d02f0a6694d667774bac"
}
' http://serverIP/zabbix/api_jsonrpc.php
[root@node ~]# sh zabbix_gethost.api
{"jsonrpc":"2.0","result":[{"hostid":"10442","host":"zbx-agent","interfaces":[{"interfaceid":"11","ip":"x.x.x.x"}]}],"id":2}