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