本文共 1058 字,大约阅读时间需要 3 分钟。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #!/usr/bin/env python2.7 # coding=utf-8 from zabbix_api import ZabbixAPI import urllib2 import sys ###get visible_name inet_ip=sys.argv[1] url = 'http://10.47.102.185/api/ecs/?ip={0}' . format (inet_ip) response = urllib2.urlopen(url) result = response. read () info = eval (result[1:-1]) visible_name = info[ 'name' ] ###login zabbix server= "http://ip/zabbix" username= "zabbix_username" password= "password" zapi = ZabbixAPI(server=server, path= "" , log_level=0) zapi.login(username, password) ###create host host_name = sys.argv[2] if zapi.host.exists({ "host" :host_name}): print 'host already exists' else : create_host=zapi.host.create({ "host" :host_name, "groups" :[{ "groupid" : "8" }], "interfaces" :[{ "type" : "1" , "main" : "1" , "useip" : "1" , "ip" :inet_ip, "port" : "10050" , "dns" : "" }], "templates" :[{ "templateid" : "10001" }], "inventory_mode" :-1, "name" :visible_name}) print create_host |