fi
# Create/update the unprivileged database user and password
- if [ -z "$PLC_MONITOR_DBPASSWORD" || "$PLC_MONITOR_DBPASSWORD" = "None" ] ; then
+ if [[ -z "$PLC_MONITOR_DBPASSWORD" || "$PLC_MONITOR_DBPASSWORD" = "None" ]] ; then
# Zabbix doesn't like plain uuidgen passwords
PLC_MONITOR_DBPASSWORD=$( uuidgen | md5sum - | awk '{print $1}' )
plc-config --category=plc_monitor --variable=dbpassword --value="$PLC_MONITOR_DBPASSWORD" --save=$local_config $local_config
# Evaluated as true or false
[commandline]
cachecalls=True
+embedded=False
echo=False
debug=False
# turn off zabbix server, etc. before writing to the db.
service plc stop monitor
- $MONITORPATH/zabbix/zabbixsync.py --setupglobal &> /var/log/monitor-server
+ $MONITORPATH/zabbix/zabbixsync.py --setupids &> /var/log/monitor-server
+ $MONITORPATH/zabbix/zabbixsync.py --setupglobal 2>&1 >> /var/log/monitor-server
# import any templates
check_zabbix_templates_and_import
fieldname = self._descriptor.auto_primarykey
index = IDs.get_by(table_name=tablename, field_name=fieldname)
if not index:
+ print "NEW IDs index INSIDE INIT"
index = IDs(table_name=tablename, field_name=fieldname, nodeid=0, nextid=10)
index.flush()
index.nextid = index.nextid + 1
ug_row = UsersGroups.get_by(usrgrpid=group.usrgrpid, userid=self.userid)
if ug_row is not None:
ug_row.delete()
- #ug_row.flush()
return
class UsrGrp(ZabbixEntity):
ug_row = UsersGroups.get_by(userid=user.userid, usrgrpid=self.usrgrpid)
if ug_row is not None:
ug_row.delete()
- #ug_row.flush()
return
+def confirm_ids():
+ fields = {
+ 'scripts' : 'scriptid',
+ 'usrgrp' : 'usrgrpid',
+ 'users' : 'userid',
+ 'media' : 'mediaid',
+ 'users_groups' : 'id',
+ 'groups' : 'groupid',
+ 'rights' : 'rightid',
+ 'drules' : 'druleid',
+ 'dchecks' : 'dcheckid',
+ 'actions' : 'actionid',
+ 'conditions' : 'conditionid',
+ 'operations' : 'operationid',
+ 'opconditions' : 'opconditionid',
+ }
+ need_to_flush = False
+
+ for tablename in fields.keys():
+ fieldname = fields[tablename]
+
+ index = IDs.get_by(table_name=tablename, field_name=fieldname)
+ if not index:
+ print "NEW IDs index INSIDE confirm_ids"
+ index = IDs(table_name=tablename, field_name=fieldname, nodeid=0, nextid=10)
+ index.flush()
+ need_to_flush=True
+
+ if need_to_flush:
+ zab_session.flush()
+
+
setup_all()
+confirm_ids()
def get_zabbix_class_from_name(name):
em = get_zabbix_entitymap()
operator=defines.CONDITION_OPERATOR_EQUAL,
value=0 ) # NOT_ACK
return o
-
-#import md5
-#u = User(alias="stephen.soltesz@gmail.com", name="stephen.soltesz@gmail.com", surname="", passwd=md5.md5("test").hexdigest(), url="", autologin=0, autologout=900, lang="en_gb", refresh=30, type=1, theme="default.css")
-#u.flush()
if zabbixserver:
# TODO: verify that this works. it has failed once on fresh
# install... not sure why.
- print "Removing default Zabbix server entry"
- zabbixserver.delete()
+# print "Removing default Zabbix server entry"
+# zabbixserver.delete()
+ zabbixserver.host="unused default server"
# NOTE: creating a host and assigning a template cannot work
# due to the crazy item, trigger, action
# HOST GROUP
plc_host_group = HostGroup.find_or_create(name="MyPLC Hosts")
+ print "myplc groupid: ", plc_host_group.groupid
site_host_group = HostGroup.find_or_create(name=HOSTGROUP_NAME % loginbase)
+ print "site groupid: ", site_host_group.groupid
plctemplate = Host.get_by(host="Template_Linux_PLC_Host")
escalation_action_name = ESCALATION_ACTION_NAME % loginbase
discovery_action_name = DISCOVERY_ACTION_NAME % loginbase
#!/usr/bin/python
import sys
+import os
import site
from monitor.wrapper import plc, plccache
from monitor import database
import zabbixsite
from monitor.database.dborm import zab_session as session
+from monitor.database.zabbixapi.model import confirm_ids, HostGroup
plcdb = plccache.l_sites # database.dbLoad("l_plcsites")
pis = plc.getPIEmails(loginbase)
iplist = get_site_iplist(loginbase)
+ os.system("""echo '%s' | tr ',' '\n' >> /usr/share/monitor/nodelist.txt""" % iplist )
+
print "zabbixsite.setup_site('%s', %s, %s, '%s')" % (loginbase,techs, pis, iplist)
zabbixsite.setup_site(loginbase, techs, pis, iplist)
from monitor import parser as parsermodule
parser = parsermodule.getParser(['cacheset'])
- parser.set_defaults( setupglobal=False, syncsite=True, site=None)
+ parser.set_defaults( setupglobal=False, syncsite=True, site=None, setupids=False)
+ parser.add_option("", "--setupids", action="store_true", dest="setupids",
+ help="Setup global IDs.")
parser.add_option("", "--setupglobal", action="store_true", dest="setupglobal",
help="Setup global settings.")
parser.add_option("", "--nosite", action="store_false", dest="syncsite",
help="Sync only given site name.")
opts = parsermodule.parse_args(parser)
+ os.system("""echo '' > /usr/share/monitor/nodelist.txt""")
+
+ if opts.setupids:
+ # Not sure why, but this doesn't work if we continue. so exit.
+ # This step only needs to be called once, but there is no harm in
+ # calling it multiple times.
+ confirm_ids()
+ session.flush()
+ sys.exit(0)
+
if opts.setupglobal:
zabbixsite.setup_global()
session.flush()
if opts.site:
query.update({'login_base' : opts.site})
+ # ADD SITES
sites = api.GetSites(query, ['login_base'])
- for site in sites[:10]:
+ site_api_list = [ site['login_base'] for site in sites ]
+ for site in sites[:20]:
add_loginbase(site['login_base'])
session.flush()
- # TODO: for any removed site that is in the db, call zabbixsite.delete_site()
+ if not opts.site:
+ # NOTE: for all sites in DB but not API, call zabbixsite.delete_site()
+ hg_list = filter(lambda x: '_hostgroup' in x.name, HostGroup.query.all() )
+ site_db_list = [ hg.name[:-len('_hostgroup')] for hg in hg_list ]
+ in_db_not_plc = set(site_db_list) - set(site_api_list)
+ for login_base in in_db_not_plc:
+ print "Deleting %s" % login_base
+ zabbixsite.delete_site(site['login_base'])
+