查看zabbix监控系统的api接口
vim zabbix-api
curl -s -XPOST -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "Admin",
"password": "redhat"
},
"id": 1,
"auth": null
}' http://172.25.76.1/zabbix/api_jsonrpc.php | python -m json.tool
添加执行权限
[root@server1 ~]# chmod +x zabbix-api
[root@server1 ~]# ./zabbix-api
{
"id": 1,
"jsonrpc": "2.0",
"result": "08776f19049167f7c0ccb8a6ca728c0d"
}
查看zabbix主机监控信息
[root@server1 ~]# vim zabbix-api
curl -s -XPOST -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"hostid",
"host"
],
"selectInterfaces": [
"interfaceid",
"ip"
]
},
"id": 2,
"auth": "08776f19049167f7c0ccb8a6ca728c0d"
}' http://172.25.76.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api
{
"id": 2,
"jsonrpc": "2.0",
"result": [
{
"host": "Zabbix server",
"hostid": "10084",
"interfaces": [
{
"interfaceid": "1",
"ip": "127.0.0.1"
}
]
},
{
"host": "server2",
"hostid": "10264",
"interfaces": [
{
"interfaceid": "3",
"ip": "172.25.76.2"
}
]
}
]
}
删除主机
[root@server1 ~]# vim zabbix-api
curl -s -XPOST -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc": "2.0",
"method": "host.delete",
"params": [
"10264" ##根据被监控主机hostid
],
"id": 2,
"auth": "08776f19049167f7c0ccb8a6ca728c0d"
}' http://172.25.76.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api
{
"id": 2,
"jsonrpc": "2.0",
"result": {
"hostids": [
"10264"
]
}
}
#添加主机
curl -s -XPOST -H "Content-Type: application/json-rpc" -d '
{
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": "server2",
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": "172.25.76.2",
"dns": "",
"port": "10050"
}
],
"groups": [
{
"groupid": "2" ##根据组id
}
],
"templates": [
{
"templateid": "10001" ##根据模板id
}
]
},
"id": 2,
"auth": "08776f19049167f7c0ccb8a6ca728c0d"
}' http://172.25.76.1/zabbix/api_jsonrpc.php | python -m json.tool
[root@server1 ~]# ./zabbix-api
{
"id": 2,
"jsonrpc": "2.0",
"result": {
"hostids": [
"10266"
]
}
}