#!/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
本文出自 “zengestudy” 博客,请务必保留此出处http://zengestudy.blog.51cto.com/1702365/1833902
原文地址:http://zengestudy.blog.51cto.com/1702365/1833902