Zabbix API calls

Source: Internet
Author: User

What Zabbix API call API can do

Zabbix API allows programmatically retrieve and modify the configuration of Zabbix and provides access to Historica L data.
It is widely used to:

    • Create new applications to work with Zabbix;
    • Integrate Zabbix with the third party software;
    • Automate routine tasks.

My own understanding is that can be programmed to operate the Zabbix, such as the creation of the host Ah, create graphics, of course, not only to create, delete and change the basic support.

Protocol for API

Created in PHP based on the JSON-RPC 2.0
means that the request and reply formats for the API are encoded in JSON

A module that the Python authoring program calls the API to call
    1. Urllib2
    2. Json
Steps are broadly divided into two steps, authentication, access to AC (authentication token)
{    "jsonrpc"2.0",    "method"user.login",    "params{        "user": "Admin",        "password": "zabbix"    },    "id1,    "authnull}

Return is

{    "jsonrpc"2.0",    "result"0424bd59b807674191e7d77572075f33",    "id1}
Sends the API request body.
{    "Jsonrpc":"2.0",    "Method":"Host.get",    "params":{"output": [ "HostID", "host" ], "  Selectinterfaces": [ " InterfaceID ", " IP " ] },    "ID":2,    "Auth":"0424bd59b807674191e7d77572075f33"}

Return:

{    "Jsonrpc":"2.0",    "result":[{"HostID": "10084", "host": "Zabbix Server",                    "Interfaces": [{"InterfaceID": "1", "IP": "127.0.0.1"                } ]}],    "ID":2}

Written in the program is

Python Example
ImportUrllib2ImportJsonzabbix_url="http://zabbix.xxx.com/api_jsonrpc.php"api_pass=' xxxx 'auth_data={' Jsonrpc ':' 2.0 ',' method ':' User.login ',' params ':{' user ':' API ',' Password ': Api_pass},' id ':1}#auth function def Get_auth():Request=urllib2. Request (Zabbix_url,json.dumps (Auth_data)) Request.add_header (' Content-type ',' Application/json ') Response=urllib2.urlopen (Request) Var1=json.loads (Response.read ())returnvar1[' Result ']#get Auth SessionSession=get_auth ()

JSON requests to follow the API document HTTPS://WWW.ZABBIX.COM/DOCUMENTATION/2.2/MANUAL/API inside the copy is OK. Note that the Zabbix version, the API request content of 2.0,2.2 and 2.4 are different.

The ID order is incremented, and the next API request ID is 2. You can do it with Urllib2.urlopen. For the use of URLLIB2, refer to my previous article. Python urllib2 module

Zabbix API calls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.