Original: Batch add Web monitoring with Zabbix API

Source: Internet
Author: User

Code as follows, offensive everyone reference, reproduced the words explained the source

The first 5 variables are self-filled,

#!/usr/local/python3.51/bin/python3# author:         [email  protected]# Mail:           [email  Protected]from pyzabbix import zabbixapiimport sysfrom re import compile, ignorecasezabbix_server =  "user = " "password = " "hostname = " "  Url= "" Def login (Zabbix_server,user,password):   zapi = zabbixapi (ZABBIX_SERVER)    zapi.login (User,password)   return zapidef gethostid (Auth,HOSTNAME):   Request = zabbixapi.do_request (auth,  ' host.get ', params={  "filter":  {"host": HOSTNAME}})   if request[' result ']:    return request[' result '][0][' HostID ']  else:    print  ("Cannot find this host")     sys.exit (1) def  getapplicationid (Auth,hostid):   try:    request = zabbixapi.do_request (auth,  ' Application.create ',  params={"name":  "Web Monitoring", "HostID":  hostid})   except  Exception as e:    print (e)   request = zabbixapi.do_request ( auth,  ' Application.get ',  params={"Hostids":  hostid})   for num in range (0,len  (request[' result ')):     if request[' result '][num][' name '] ==  ' Web monitoring ":       return request[' result '][num][' ApplicationID ']def create_ Web_scenario (Auth,url,hostid,applicationid):   request = zabbixapi.do_request (auth,  ' Httptest.get ', params={  "filter":  {"name":  url}})   if request[' result ']:     print (' The Web Monitor has been added '   '   else:    try:       zabbixapi.do_rEquest (auth,  ' httptest.create ', params={"name":  url, "HostID":  hostid, "ApplicationID":  applicationid,  "delay":  ' $ ', "retries":  ' 3 ',  "steps": [ {  ' name ':  url,   ' url ': url,  ' no ':  ' 1 '} ] } )     except exception  as e:      print (e) Def create_trigger (Auth,HOSTNAME,URL):   expression= "{" + "{0}:web.test.fail[{1}].last ()". Format (Hostname,url) + "}" + "<>0"   try:     zabbixapi.do_request (auth,  ' trigger.create ',  params={"description":  " There is a problem accessing {0} from the Monitor (172.18.11.34), if the network and host performance is not a problem, and a single node error, try restarting the corresponding Tomcat ". Format (URL)," expression ":  expression," Priority ": 5})     except exception as e:    print (e) Auth  = login (Zabbix_server,user,password) Hostid = gethostid (auth,hostname) applicationid= Getapplicationid (Auth,hostid) CREAte_web_scenario (Auth,url,hostid,applicationid) Create_trigger (Auth,hostname,url) 


Original: Batch add Web monitoring with Zabbix API

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.