The URL to access the Zabbix API is:
http://x.x.x.x/zabbix/api_jsonrpc.php
x.x.x.x may be your IP or domain name
Overview of the Access process:
1, first Login
2. Zabbix server returns a token after successful authentication
3, with this token to access a variety of data, do a variety of operations
4, Complete!
First, log in with Restclient
In the body of the JSON request, you have the following properties:
jsonrpc
-Version of the JSON-RPC protocol used by the API; Zabbix API Implementation JSON-RPC version 2.0;
method
-called API method;
params
-parameters that will be passed to the API method;
id
-Any identifier of the request;
auth
-user authentication token; Because we haven't got one, it's set to null.
After the credentials are correctly supplied, the response returned by the API will contain the user authentication token (in JSON format):
{
"Jsonrpc": "2.0",
"Result": "140f4524c02e2731dd74c48d29aa5ce8", #这个就是token
"id": 1
}
Ii. sign in with Python
# -*- coding:utf-8 -*-import urllib2import jsonurl = ' Http://x.x.x.x/zabbix /api_jsonrpc.php ' header = {' content-type ': ' Application/json '}req = json.dumps ( { "Jsonrpc": "2.0", "Method": "User.login", " Params ": { " user ": " Admin ", "Password": "Your password" }, "id": 0, }) Def auth (): r = urllib2. Request (url=url, headers=header, data=req) response = Urllib2.urlopen (R) token = json.loAds (Response.read ()) print (token) if __name__ == ' __main__ ': auth ()
The resulting response:
(ii) Python calls the Zabbix API from getting started to discarding--log in and get an authentication token