"output":["hostid","name"],
"filter":{"host":""}
},
#auth id
"auth":"Zabbix Auth ID",
"id": 1,
})
#create request object
request = urllib2.Request(url,data)
for key in header:
request.add_header(key,header[key])
#get host list
try:
result = urllib2.urlopen(request)
except URLError as e:
print "The server could not fulfill the request.",e.reason
else:
reponse = json.loads(result.read())
result.close()
#print "Number of Hosts:",len(reponse['result'])
for host in reponse['result']:
#print "Host ID:",host['hostid'],"Host Name:",host['name']
zbxhosts=host['name']
zabbixhostlst.append(zbxhosts)
zabbixhostlst.sort()
return zabbixhostlst
for host in diff:
if host in nmaphostlst:
nomonitorlst.append(host)
else:
sys.exit()
#print zbxhostlst
string = '\n'.join(nomonitorlst)
f = file('/shell/machine/result/result.txt','w')
f.write(string)
f.flush()
f.close()
runCmd(mail_cmd)
if __name__ == "__main__":
main() 把脚本添加到crontab,每台会收到关于那些主机没有添加监控的信息。
总结: 1)Zabbix API相关信息可以查看官方详细资料,看不懂英文的可以参考下面这篇文档。http://paperplane.ruhoh.com/zabbix/intro-to-zabbix-api/
2)通过该脚本可以知道那些主机没有添加监控,希望对大家有帮助,如果有更好的解决方法欢迎多多交流。