From 19ba97634589f5cce3719dbe0f96d94e3e148e1d Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Wed, 19 Nov 2008 01:24:00 +0000 Subject: [PATCH] general improvements --- Monitor.spec | 7 +++++-- monitor-server.init | 5 +++++ monitor/wrapper/plccache.py | 4 ++++ zabbix/zabbixsite.py | 1 + zabbix/zabbixsync.py | 14 +++++++------- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Monitor.spec b/Monitor.spec index 335ab16..c48facf 100644 --- a/Monitor.spec +++ b/Monitor.spec @@ -122,8 +122,8 @@ install -D -m 755 threadpool.py $RPM_BUILD_ROOT/%{python_sitearch}/threadpool.py touch $RPM_BUILD_ROOT/var/www/cgi-bin/monitor/monitorconfig.php chmod 777 $RPM_BUILD_ROOT/var/www/cgi-bin/monitor/monitorconfig.php -install -D -m 755 monitor-default.conf $RPM_BUILD_ROOT/etc/monitor.conf -cp $RPM_BUILD_ROOT/usr/share/%{name}/monitorconfig-default.py $RPM_BUILD_ROOT/usr/share/%{name}/monitorconfig.py +#install -D -m 755 monitor-default.conf $RPM_BUILD_ROOT/etc/monitor.conf +#cp $RPM_BUILD_ROOT/usr/share/%{name}/monitorconfig-default.py $RPM_BUILD_ROOT/usr/share/%{name}/monitorconfig.py %clean rm -rf $RPM_BUILD_ROOT @@ -156,6 +156,9 @@ rm -rf $RPM_BUILD_ROOT # TODO: update the content of automate_pl03.sh # TODO: Use the installed version of bootcd to create custom boot images. ( or, use the api now). +# NOTE: generate the python defines from zabbix include files. +php /usr/share/%{name}/zabbix/getdefines.php > %{python_sitearch}/monitor/database/zabbixapi/defines.py + #chkconfig --add monitor-server #chkconfig monitor-server on diff --git a/monitor-server.init b/monitor-server.init index df00751..21671bf 100644 --- a/monitor-server.init +++ b/monitor-server.init @@ -261,7 +261,12 @@ case "$1" in MESSAGE=$"Syncing PLC db with Zabbix DB" dialog "$MESSAGE" + # turn off zabbix server, etc. before writing to the db. + service plc stop monitor + $MONITORPATH/zabbix/zabbixsync.py --setupglobal &> /var/log/monitor-server + + service plc start monitor result "$MESSAGE" ;; diff --git a/monitor/wrapper/plccache.py b/monitor/wrapper/plccache.py index f872d7a..978e6bb 100755 --- a/monitor/wrapper/plccache.py +++ b/monitor/wrapper/plccache.py @@ -21,6 +21,10 @@ def dsn_from_dsln(d_sites, id2lb, l_nodes): lb2hn = {} dsn = {} hn2lb = {} + for id in id2lb: + if id2lb[id] not in lb2hn: + lb2hn[id2lb[id]] = [] + for node in l_nodes: # this won't reach sites without nodes, which I guess isn't a problem. if node['site_id'] in id2lb.keys(): diff --git a/zabbix/zabbixsite.py b/zabbix/zabbixsite.py index 76e9ea6..678c756 100755 --- a/zabbix/zabbixsite.py +++ b/zabbix/zabbixsite.py @@ -73,6 +73,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' diff --git a/zabbix/zabbixsync.py b/zabbix/zabbixsync.py index fd2126e..6ab825f 100755 --- a/zabbix/zabbixsync.py +++ b/zabbix/zabbixsync.py @@ -2,17 +2,16 @@ import sys import site -from monitor.wrapper import plc +from monitor.wrapper import plc, plccache from monitor import database import zabbixsite -from monitor.database.dborm import session +from monitor.database.dborm import zab_session as session -print "test" -plcdb = database.dbLoad("l_plcsites") -netid2ip = database.dbLoad("plcdb_netid2ip") -lb2hn = database.dbLoad("plcdb_lb2hn") +plcdb = plccache.l_sites # database.dbLoad("l_plcsites") +netid2ip = plccache.plcdb_netid2ip # database.dbLoad("plcdb_netid2ip") +lb2hn = plccache.plcdb_lb2hn # database.dbLoad("plcdb_lb2hn") def get_site_iplist(loginbase): node_list = lb2hn[loginbase] @@ -43,7 +42,7 @@ if __name__=="__main__": parser.set_defaults( setupglobal=False, syncsite=True, site=None) parser.add_option("", "--setupglobal", action="store_true", dest="setupglobal", help="Setup global settings.") - parser.add_option("", "--nosite", action="store_true", dest="syncsite", + parser.add_option("", "--nosite", action="store_false", dest="syncsite", help="Do not sync sites.") parser.add_option("", "--site", dest="site", help="Sync only given site name.") @@ -53,6 +52,7 @@ if __name__=="__main__": zabbixsite.setup_global() if opts.syncsite: + api = plc.getAuthAPI() query = {'peer_id' : None} if opts.site: query.update({'login_base' : opts.site}) -- 2.43.0