X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=zabbix%2Fhosts.py;fp=zabbix%2Fhosts.py;h=c2dbde7900d6b2503ddac1134be6a4675aea8722;hb=bf02dca4b0f09d86990a50a4406ab8ecd79cbd5d;hp=0000000000000000000000000000000000000000;hpb=37c768dbd516a39bd56bc43f9b73b51acdfd9563;p=monitor.git diff --git a/zabbix/hosts.py b/zabbix/hosts.py new file mode 100755 index 0000000..c2dbde7 --- /dev/null +++ b/zabbix/hosts.py @@ -0,0 +1,32 @@ +#!/usr/bin/python + +from monitor.wrapper import plc +import os + +api = plc.api + +HOSTS_FILE="/etc/hosts" + +def is_in_file(filename, pattern): + f = os.popen("grep %s %s" % ( pattern, filename)) + content = f.read() + if len(content) > 0: + return True + else: + return False +def add_to_file(filename, data): + os.system("echo '%s' >> %s" % (data, filename)) + print "echo '%s' >> %s" % (data, filename) + +sites = api.GetSites({'login_base' : 'mlab*'}, ['node_ids']) +for s in sites: + nodes = api.GetNodes(s['node_ids'], ['hostname', 'interface_ids']) + for node in nodes: + try: + i = api.GetInterfaces({ 'interface_id' : node['interface_ids'], 'is_primary' : True}) + print len(i), i + print "%s %s" % (i[0]['ip'], node['hostname']) + #if not is_in_file(HOSTS_FILE, node['hostname']): + # add_to_file(HOSTS_FILE, "%s %s" % (i[0]['ip'], node['hostname'])) + except: + pass