#!/usr/bin/env python2.7# coding=utf-8from zabbix_api import zabbixapiimport urllib2import sys## #get visible_nameinet_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 zabbixserver= "Http://ip/zabbix" Username= "zabbix_username" password= "password" Zapi = zabbixapi (server=server, path= "", log_ level=0) Zapi.login (Username, password) # # #create hosthost_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
This article is from the "Zengestudy" blog, make sure to keep this source http://zengestudy.blog.51cto.com/1702365/1833902
Creating hosts with the Zabbix API