官网介绍:
Zabbix API allows you to programmatically retrieve and modify the configuration of Zabbix and provides access to historical data. It is widely used to:
- Create new applications to work with Zabbix;
- Integrate Zabbix with third party software;
- Automate routine tasks.
The Zabbix API is a web based API and is shipped as part of the web frontend. It uses the JSON-RPC 2.0 protocol which means two things:
- The API consists of a set of separate methods;
- Requests and responses between the clients and the API are encoded using the JSON format.
===================================
1. 获取auth
curl -i -X POST -H 'Content-Type:application/json' -d '{"jsonrpc":"2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"auth":null,"id":0}' http://192.168.4.142/api_jsonrpc.php
HTTP/1.1 200 OK
Date: Fri, 24 May 2019 00:29:31 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 68
Connection: close
Content-Type: application/json
{"jsonrpc":"2.0","result":"aab4f7f7be4778f2fab229980f4a95c4","id":0}
2. 获取主机信息
curl -i -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["host","hostid"],
"filter": {
"host": [
"dbw01at.daodao.com",
"dbw01bt.daodao.com"
]
}
},
"auth": "aab4f7f7be4778f2fab229980f4a95c4",
"id": 1
}' http://192.168.4.142/api_jsonrpc.php
3. 获取主机组信息
curl -i -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "hostgroup.get",
"params": {
"output": ["groupid","name"],
"selectGroups": "extend",
"filter": {
"name": [
"DataCenter T"
]
}
},
"auth": "aab4f7f7be4778f2fab229980f4a95c4",
"id": 1
}' http://192.168.4.142/api_jsonrpc.php
4. 获取监控项id
curl -i -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "item.get",
"params": {
"output": ["itemid", "name", "key_"],
"hostids": "10138",
"search": {
"key_": "cpu"
}
},
"auth": "aab4f7f7be4778f2fab229980f4a95c4",
"id": 1
}' http://192.168.4.142/api_jsonrpc.php
5. 获取某项监控数据
curl -i -X POST -H 'Content-Type:application/json' -d '
{
"jsonrpc": "2.0",
"method": "history.get",
"params": {
"output": "extend",
"history": 0,
"itemids": "33583",
"sortfield": "clock",
"sortorder": "DESC",
"limit": 10
},
"auth": "aab4f7f7be4778f2fab229980f4a95c4",
"id": 1
}' http://192.168.4.142/api_jsonrpc.php