1)判断ip是否存在于zabbix中
思路:
1)使用user.login模拟登陆,获取authID
2)使用hostinterface.get获取主机hostid(要是使用主机名的话,可以使用host.get来获取hostid)
3)main函数实现:
if __name__ == "__main__":
file = raw_input("请输入文件名:")
fp = open(file)
hostname_list = fp.readlines()
fp.close()
hostids = []
j = 0
if os.path.exists('error_ip.txt'):
os.remove('error_ip.txt')
if os.path.exists('correct_ip.txt'):
os.remove('correct_ip.txt')
for i in hostname_list:
hostname = i.strip().split(' ')[0]
hostids.append(host_get(hostname))
if hostids[j] == None:
print hostids[j]
fp1 = open('error_ip.txt','a')
fp1.write(i)
fp1.close()
else:
print hostids[j]
fp2 = open('correct_ip.txt','a')
fp2.write(i)
fp2.close()
j = j + 1