The Zabbix API can obtain historical data through the json rpc protocol.
You can use a script or any tool that supports json rpc to use APIs.
Basic request format
The simplified JSON request of Zabbix API is as follows:
{
"Jsonrpc": "2.0 ",
"Method": "method. name ",
"Params ":{
"Param_1_name": "param_1_value ",
"Param_2_name": "param_2_value"
},
"Id": 1,
"Auth": "a826fca79a0795ccc1224dc7610972f ",
}
See the following line:
● "Jsonrpc": "2.0"-this is a standard json rpc parameter to indicate the Protocol version. All requests remain unchanged.
● "Method": "method. name"-this parameter defines the operations actually executed. For example, host. create, item. update, history. get, etc.
● "Params"-Here, the JSON object is passed as a parameter for a specific method. If you want to create a metric item, the "name" and "key _" parameters are required. The parameters required for each method are described in the Zabbix API documentation.
● "Id": 1-this field is used to bind the JSON request and response. The response will have the same "id" as the request ". It is useful when sending multiple requests at a time. These do not need to be unique or continuous.
● "Auth": "a826fca79a0795ccc1224dc7610972f"-this is an authentication token used to identify users and access APIs. This is also the prerequisite for using APIs for related operations-to obtain the authentication ID.
Instance: obtains the cpu idle value of 192.168.211.60 from 14:00:00 to 14:10:00.
Curl-based command:
(1): Authenticate and obtain encrypted Fields
Curl-I-X POST-H 'content-Type: application/json'-d' {"jsonrpc ":
"2.0", "method": "user. login", "params": {"user": "xxxx", "password": "xxxx"}, "auth ":
Null, "id": 0} 'http://x.x.x.x/api_jsonrpc.php
# A string of outputs will be obtained: {"jsonrpc": "2.0", "result": "a826fca79a0795ccc1224dc7610972f", "id": 0 }. Remember this output.
(2) obtain the hostids of the monitored host
Curl-I-X POST-H 'content-Type: application/json'-d' {"jsonrpc": "2.0", "method": "host. get "," params ": {" output ": [" hostid "]," filter ": {" host ":" 192.168.211.60 "}}," auth ": "a826fca79a0795ccc1224dc7610972f", "id": 0} 'http://x.x.x.x/api_jsonrpc.php
# "Hostid": "10243"
(3) Obtain itemids
Curl-I-X POST-H 'content-Type: application/json'-d' {"jsonrpc": "2.0", "method": "item. get "," params ": {" output ":" itemids "," hostids ":" 10243 "," search ": {" key _ ":" system. cpu. util
[, Idle, avg1] "}}," auth ":" a826fca79a0795ccc1224dc7610972f "," id ": 0} 'http://x.x.x.x/api_jsonrpc.php
# "Item": "24526"
(4) obtain the metric item "system. cpu. util [, idle, avg1]" from ~ Value
Curl-I-X POST-H 'content-Type: application/json'-d' {"jsonrpc": "2.0", "method": "history. get "," params ": {" history ": 0," itemids ": [" 24526 "]," time_from ":" 1392789600 "," time_till ":" 1392790200 ", "output": "extend"}, "auth": "a826fca79a0795ccc1224dc7610972f", "id": 0} 'http://x.x.x.x/api_jsonrpc.php
# Output:
[{"Itemid": "24526", "clock": "1392789646", "value": "95.7539", "ns": "138978589 "},
{"Itemid": "24526", "clock": "1392789706", "value": "84.9595", "ns": "578198422 "},
{"Itemid": "24526", "clock": "1392789766", "value": "94.5259", "ns": "186216653 "},
{"Itemid": "24526", "clock": "1392789826", "value": "96.2286", "ns": "789434167 "},
{"Itemid": "24526", "clock": "1392789886", "value": "94.7712", "ns": "191954191 "},
{"Itemid": "24526", "clock": "1392789946", "value": "90.8338", "ns": "781241168 "},
{"Itemid": "24526", "clock": "1392790006", "value": "89.1735", "ns": "294674458 "},
{"Itemid": "24526", "clock": "1392790066", "value": "92.3015", "ns": "877714419 "},
{"Itemid": "24526", "clock": "1392790126", "value": "96.3051", "ns": "426421789 "},
{"Itemid": "24526", "clock": "1392790186", "value": "97.7931", "ns": "174500891"}]
# "Value" indicates the cpu idle value. The sampling interval is the same as the data update time of the metric item.
Supplement: obtain the value of 192.168.211.60 metric item "system. cpu. util [, idle, avg1]" at 2:02:46, January 1, February 19, 2014.
Curl-I-X POST-H 'content-Type: application/json'-d' {"jsonrpc": "2.0", "method": "history. get "," params ": {" history ": 0," itemids ": [" 24526 "]," time_from ":" 1392789600 "," time_till ":" 1392790200 ", "output": "extend", "filter": {"clock": "1392789766" }}, "auth": "a826fca79a0795ccc1224dc7610972f", "id": 0} 'http://x.x.x.x/api_jsonrpc.php
# "Value": "94.5259" value to be obtained
Refer:
Zabbix API documentation: https://www.zabbix.com/documentation/2.2/manual/api
ZABBIX details: click here
ZABBIX: click here
Install and deploy the distributed monitoring system Zabbix 2.06
Install and deploy the distributed monitoring system Zabbix 2.06
Install and deploy Zabbix in CentOS 6.3
Zabbix distributed monitoring system practice
Under CentOS 6.3, Zabbix monitors apache server-status
Monitoring MySQL database Parameters Using Zabbix in CentOS 6.3