X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=zabbix%2Fzabbixsite.py;h=419b84bb653f81a008249db4d8652d2a3d6bf306;hb=4875f56c715aa643ff9a1f5a3a801f240b47fe96;hp=241e739fc05b35e2533b1def661c627eff6f7008;hpb=7b3d462aa05fcc1892fd914db163143f36a05945;p=monitor.git diff --git a/zabbix/zabbixsite.py b/zabbix/zabbixsite.py index 241e739..419b84b 100755 --- a/zabbix/zabbixsite.py +++ b/zabbix/zabbixsite.py @@ -62,6 +62,11 @@ def delete_site(loginbase): return +# NOTE: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +## These functions can ONLY be run when the server and gui are offline. +## Any changes to the db while this is running risks introducing a failure +## to commit, and therefore error. +# NOTE: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! def setup_global(): # GLOBAL: # update mediatype for email. @@ -100,7 +105,7 @@ def setup_global(): # copying that the php code does during a host add. # NOTE: Instead, reformat any *xml.in templates and import those # during /etc/plc.d/monitor sync - for file in glob.glob("%s/zabbix/templates/*.xml.in" config.MONITOR_SCRIPT_ROOT): + for file in glob.glob("%s/zabbix/templates/*.xml.in" % config.MONITOR_SCRIPT_ROOT): if 'zabbix_server' in file: buf = loadFile(file) args = {'hostname' : config.MONITOR_HOSTNAME, 'ip' : config.MONITOR_IP} @@ -122,6 +127,23 @@ def setup_global(): }) return +def merge_iplist(iplist): + # TODO: rewrite addresses as x.x.x.y-z rather than x.x.x.y,x.x.x.z if y-z==1 + ips = iplist.split(',') + ips.sort() + prev=None + newlist="" + for ip in ips: + fields = ip.split('.') + first = ".".join(fields[:2]) + last = int(fields[3]) + if prev: + if last - prev == 1: + pass + prev=last + newlist += "%s," + return newlist[:-1] + def setup_site(loginbase, techemail, piemail, iplist): # TODO: send a message when host is discovered.