Zabbix Bulk Add host monitoring-zabbix API calls

Source: Internet
Author: User

Calling the Zabbix API using Python

#!/usr/bin/env python#Version = 3.6.1#__auth__ = ' Warren 'ImportJSON fromUrllibImportrequest, Parsezabbix_url='Http://192.168.22.22/zabbix'Zabbix_username="Admin"Zabbix_password="123456"#define the host information to be added in list formhostlist=["192.168.22.111","192.168.22.112"]#Traverse host list defines the host group ID and template ID to add forHostinchHostlist:url="{}/api_jsonrpc.php". Format (zabbix_url) header= {"Content-type":"Application/json"}    #auth user and passworddata = {        "Jsonrpc":"2.0",        "Method":"host.create",        "params": {            "Host": Host,"Interfaces": [                {                    "type": 1,                    "Main": 1,                    "Useip": 1,                    "IP": Host,"DNS":"",                    "Port":"10050"                }            ],            "groups": [                {                    "GroupID":" +"                }            ],            "Templates": [                {                    "TemplateID":"10081"                }            ],            "Inventory_mode": 0,"Inventory": {                "macaddress_a":"01234",                "Macaddress_b":"56768"            }        },        "Auth":"9afc764edb5b6bbd09369f7028231b70",        "ID": 1    }    #because the API receives a JSON string, you need to convertValue = Json.dumps (data). Encode ('Utf-8')    #wrapping the requestreq = Request. Request (URL, Headers=header, data=value)#Verify and obtain the Auth ID    Try:        #open a wrapped URLresult =Request.urlopen (req)exceptException as E:Print("Auth Failed, please Check Your Name and Password:", E)Else: Response=Result.read ()#The above is the bytes type data, it needs to decode converted into a stringpage = Response.decode ('Utf-8')        #Convert This JSON string to a python dictionarypage =json.loads (page) result.close ()#Printing Information        Print("Create host successful. The host ID is: {}". Format (Page.get ('result')))         #If added repeatedly, the host ID will be returned Is:none

Zabbix Bulk Add host monitoring-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.