-
创建新的应用程序以使用Zabbix;
-
将Zabbix与第三方软件集成;
-
POST http://company.com/zabbix/api_jsonrpc.php HTTP/1.1 Content-Type: application/json-rpc
{"jsonrpc":"2.0","method":"apiinfo.version","id":1,"auth":null,"params":{}}
请求方法如下:
{ "jsonrpc": "2.0", "method": "user.login", "params": { "user": "Admin", "password": "zabbix" }, "id": 1, "auth": null }
curl -X POST -H "Content-Type: application/json" -d ‘ { "jsonrpc": "2.0", "method": "user.login", "params": { "user": "Admin", "password": "zabbix" }, "id": 1, "auth": null }‘ http://10.0.0.71/zabbix/api_jsonrpc.php #拿到的token {"jsonrpc":"2.0","result":"37ebe2e28ecca09c855e832e1a226d99","id":1} token=37ebe2e28ecca09c855e832e1a226d99
curl -X POST -H "Content-Type: application/json-rpc" -d ‘ { "jsonrpc": "2.0", "method": "item.get", "params": { "output": "extend", "hostids": "10304", "search": { "key_": "agent" }, "sortfield": "name" }, "auth": "37ebe2e28ecca09c855e832e1a226d99", "id": 1 }‘ http://10.0.0.71/zabbix/api_jsonrpc.php
注: 每一个监控项都有它的ID值
curl -X POST -H "Content-Type: application/json-rpc" -d ‘ { "jsonrpc": "2.0", "method": "item.create", "params": { "name": "oldboy", "key_": "test", "hostid": "10304", "type": 0, "value_type": 3, "interfaceid": "32", "delay": "30s" }, "auth": "37ebe2e28ecca09c855e832e1a226d99", "id": 3 }‘ http://10.0.0.71/zabbix/api_jsonrpc.php
curl -X POST -H "Content-Type: application/json-rpc" -d ‘ { "jsonrpc": "2.0", "method": "item.create", "params": { "name": "wei", "key_": "wei123", "hostid": "10304", "type": 0, "applications": ["1466"], "value_type": 3, "interfaceid": "32", "delay": "30s" }, "auth": "37ebe2e28ecca09c855e832e1a226d99", "id": 3 }‘ http://10.0.0.71/zabbix/api_jsonrpc.php
-
创建一个应用集,并 记录ID值 (这里id值是:1469)
-
创建脚本 (是一种状态)
-
执行脚本
$ vim piliang_create_item.sh #!/bin/bash cat piliang_create_item.sh for n in ESTABLISHED SYN_SENT SYN_RECV FIN_WAIT1 FIN_WAIT2 TIME_WAIT CLOSE CLOSE_WAIT LAST_ACK LISTEN CLOSING do curl -X POST -H "Content-Type: application/json-rpc" -d ‘ { "jsonrpc": "2.0", "method": "item.create", "params": { "name": "‘$n‘数量状态数量", "key_": "‘$n‘", "hostid": "10304", "type": 0, "applications": ["1469"], "value_type": 3, "interfaceid": "32", "delay": "30s" }, "auth": "37ebe2e28ecca09c855e832e1a226d99", "id": 3 }‘ http://10.0.0.71/zabbix/api_jsonrpc.php done
#!/bin/bash for i in 10.0.0.{1..100} do curl -X POST -H "Content-Type: application/json-rpc" -d ‘ { "jsonrpc": "2.0", "method": "host.create", "params": { "host": "‘$i‘", "interfaces": [ { "type": 1, "main": 1, "useip": 1, "ip": "‘$i‘", "dns": "", "port": "10050" } ], "groups": [ { "groupid": "21" } ], "templates": [ { "templateid": "10001" } ] }, "auth": "37ebe2e28ecca09c855e832e1a226d99", "id": 1 }‘ http://10.0.0.71/zabbix/api_jsonrpc.php done
效果图