X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=zabbix%2Fzabbixsite.py;h=e3bcfb43632053bfcf072267547af0ecf965b1b4;hb=a06427d1c9506ee93888e8f2f80b6c4bdd134527;hp=76e9ea6ae88797964cff997a27a7f847abdf8612;hpb=c0d3e59ff639296fd16eb2b2bab18bc78b0a7415;p=monitor.git diff --git a/zabbix/zabbixsite.py b/zabbix/zabbixsite.py index 76e9ea6..e3bcfb4 100755 --- a/zabbix/zabbixsite.py +++ b/zabbix/zabbixsite.py @@ -4,12 +4,14 @@ from os import getcwd from os.path import dirname, exists, join import sys import md5 +import glob from monitor import config from monitor.database.dborm import zab_session as session from monitor.database.zabbixapi.model import * from monitor.database.zabbixapi.emailZabbix import * from monitor.database.zabbixapi import defines +from monitor.util.file import * @@ -73,6 +75,7 @@ def setup_global(): print "checking for correct configuration" mediatype = MediaType.get_by(smtp_email=config.from_email) if not mediatype: + mediatype = MediaType.get_by(description="Email") # NOTE: assumes smtp server is local to this machine. print "updating email server configuration" mediatype.smtp_server='localhost' @@ -87,15 +90,20 @@ def setup_global(): print "checking zabbix server host info" zabbixserver = Host.get_by(host="ZABBIX Server") if zabbixserver: - print "UPDATING Primary Zabbix server entry" - zabbixserver.host=config.MONITOR_HOSTNAME - zabbixserver.ip=config.MONITOR_IP - zabbixserver.dns=config.MONITOR_HOSTNAME - zabbixserver.useip=1 + print "Removing default Zabbix server entry" + zabbixserver.delete() + + # NOTE: creating a host and assigning a template cannot work + # due to the crazy item, trigger, action + # 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("/usr/share/monitor/templates/*.xml.in"): + if 'zabbix_server' in file: + buf = loadFile(file) + args = {'hostname' : config.MONITOR_HOSTNAME, 'ip' : config.MONITOR_IP} + dumpFile(file[:-3], buf % args) - ############################ DEFAULT TEMPLATES - # pltemplate - via web, xml import - # TODO: os.system("curl --post default_templates.xml") ##################### SCRIPTS ## TODO: add calls to check/reset the boot states. @@ -142,7 +150,7 @@ def setup_site(loginbase, techemail, piemail, iplist): # HOST GROUP plc_host_group = HostGroup.find_or_create(name="MyPLC Hosts") site_host_group = HostGroup.find_or_create(name=HOSTGROUP_NAME % loginbase) - plctemplate = Host.get_by(host="Template_Linux_PLHost") + plctemplate = Host.get_by(host="Template_Linux_PLC_Host") escalation_action_name = ESCALATION_ACTION_NAME % loginbase discovery_action_name = DISCOVERY_ACTION_NAME % loginbase discovery_rule_name = DISCOVERY_RULE_NAME % loginbase