add cron script to regenerate config files daily.
add dependencies and setup to monitor-nagios rpm
improve monitor-nagios.init script (I still think it may need to only be run once).
Requires: mysql-devel
Requires: mysql-libs
Requires: mailx
+Requires: sendmail
+Requires: php
+Requires: httpd
+Requires: cronie
Requires: nagios
Requires: nagios-common
Requires: nagios-devel
install -D -m 644 monitor.functions $RPM_BUILD_ROOT/%{_sysconfdir}/plc.d/monitor.functions
install -D -m 755 monitor-server.init $RPM_BUILD_ROOT/%{_sysconfdir}/plc.d/monitor
install -D -m 755 zabbix/monitor-zabbix.init $RPM_BUILD_ROOT/%{_sysconfdir}/plc.d/zabbix
+
install -D -m 755 nagios/monitor-nagios.init $RPM_BUILD_ROOT/%{_sysconfdir}/plc.d/monitor-nagios
+install -D -m 644 nagios/monitor-server.cron $RPM_BUILD_ROOT/%{_sysconfdir}/cron.d/monitor-nagios.cron
# cron job for automated polling
install -D -m 644 monitor-server.cron $RPM_BUILD_ROOT/%{_sysconfdir}/cron.d/monitor-server.cron
# install monitor python package
rsync -a --exclude .svn ./monitor/ $RPM_BUILD_ROOT/%{python_sitearch}/monitor/
+install -D -m 644 monitor/wrapper/plc.py $RPM_BUILD_ROOT/usr/share/%{name}/nagios/
+install -D -m 644 monitor/generic.py $RPM_BUILD_ROOT/usr/share/%{name}/nagios/
+
# install third-party module to site-packages
install -D -m 755 threadpool.py $RPM_BUILD_ROOT/%{python_sitearch}/threadpool.py
%defattr(-,root,root)
%{_sysconfdir}/plc.d/monitor-nagios
/usr/share/%{name}/nagios
+%{_sysconfdir}/cron.d/monitor-nagios.cron
%files server
%defattr(-,root,root)
import logging
import time
import traceback
-from monitor import database
# note: this needs to be consistent with the value in PLEWWW/planetlab/includes/plc_functions.php
PENDING_CONSORTIUM_ID = 0
return self.api.__repr__()
-class CachedPLC(PLC):
-
- def _param_to_str(self, name, *params):
- fields = len(params)
- retstr = ""
- retstr += "%s-" % name
- for x in params:
- retstr += "%s-" % x
- return retstr[:-1]
-
- def __getattr__(self, name):
- method = getattr(self.api, name)
- if method is None:
- raise AssertionError("method does not exist")
-
- def run_or_returncached(*params):
- cachename = self._param_to_str(name, *params)
- #print "cachename is %s" % cachename
- if hasattr(config, 'refresh'):
- refresh = config.refresh
- else:
- refresh = False
-
- if 'Get' in name:
- if not database.cachedRecently(cachename):
- load_old_cache = False
- try:
- values = method(self.auth, *params)
- except:
- print "Call %s FAILED: Using old cached data" % cachename
- load_old_cache = True
-
- if load_old_cache:
- values = database.dbLoad(cachename)
- else:
- database.dbDump(cachename, values)
-
- return values
- else:
- values = database.dbLoad(cachename)
- return values
- else:
- return method(self.auth, *params)
-
- return run_or_returncached
-
api = PLC(auth.auth, auth.server)
-cacheapi = CachedPLC(auth.auth, auth.server)
def getAPI(url):
from monitor.wrapper import plc
from monitor.generic import *
from monitor.database.info.model import *
+from monitor import database
import profile
plcdb_lb2hn = None
plcdb_id2lb = None
+class CachedPLC(PLC):
+
+ def _param_to_str(self, name, *params):
+ fields = len(params)
+ retstr = ""
+ retstr += "%s-" % name
+ for x in params:
+ retstr += "%s-" % x
+ return retstr[:-1]
+
+ def __getattr__(self, name):
+ method = getattr(self.api, name)
+ if method is None:
+ raise AssertionError("method does not exist")
+
+ def run_or_returncached(*params):
+ cachename = self._param_to_str(name, *params)
+ #print "cachename is %s" % cachename
+ if hasattr(config, 'refresh'):
+ refresh = config.refresh
+ else:
+ refresh = False
+
+ if 'Get' in name:
+ if not database.cachedRecently(cachename):
+ load_old_cache = False
+ try:
+ values = method(self.auth, *params)
+ except:
+ print "Call %s FAILED: Using old cached data" % cachename
+ load_old_cache = True
+
+ if load_old_cache:
+ values = database.dbLoad(cachename)
+ else:
+ database.dbDump(cachename, values)
+
+ return values
+ else:
+ values = database.dbLoad(cachename)
+ return values
+ else:
+ return method(self.auth, *params)
+
+ return run_or_returncached
+
+cacheapi = CachedPLC(plc.auth.auth, plc.auth.server)
+
def init():
import traceback
#print "IMPORTING PLCCACHE: ",
--- /dev/null
+# run daily to regenerate the nagios configuration files
+0 0 * * * root /usr/share/monitor/nagios/plc_hosts_to_nagios.py > /etc/nagios/objects/plc.cfg
+5 0 * * * root /usr/share/monitor/nagios/plc_users_to_nagios.py > /etc/nagios/objects/plcusers.cfg
+10 0 * * * root /sbin/service nagios restart
# $Id$
#
-. /etc/plc.d/functions
-. /etc/plc.d/monitor.functions
-. /etc/planetlab/plc_config
+for f in /etc/plc.d/functions /etc/plc.d/monitor.functions /etc/planetlab/plc_config ; do
+ if [ -f /etc/plc.d/functions ] ; then
+ source $f
+ fi
+done
# NOTE: expect that mysqld is already started.
start () {
- if ! $( mysqladmin ping 2> /dev/null ) ; then
+ if ! ( mysqladmin ping &> /dev/null ) ; then
echo "mysqld is not running; cannot continue; exit..."
exit
fi
# if it's a fresh install, there is no root passwd.
- if $( mysqladmin -u root create nagios ) ; then
+ if ( mysqladmin -u root create nagios &> /dev/null ) ; then
cat <<EOF > /tmp/nagios.priv
GRANT ALL PRIVILEGES ON nagios.* TO ndouser@localhost IDENTIFIED BY 'ndopassword';
EOF
perl ./installdb -u ndouser -p ndopassword -d nagios
fi
- if ! $( grep -q /usr/lib/nagios/brokers/ndomod.so /etc/nagios/nagios.cfg ) ; then
+ if ! ( grep -q /usr/lib/nagios/brokers/ndomod.so /etc/nagios/nagios.cfg ) ; then
echo "broker_module=/usr/lib/nagios/brokers/ndomod.so config_file=/etc/nagios/ndomod.cfg" >> /etc/nagios/nagios.cfg
- echo "foo"
fi
- /sbin/chkconfig ndo2db on
- #/sbin/service ndo2db start
+ if ( chkconfig --list ndo2db | grep -q 3:off ) ; then
+ /sbin/chkconfig ndo2db on
+ /sbin/service ndo2db start
+ fi
#/sbin/service nagios restart
## set passwd for /etc/nagios/passwd
- htpasswd -b -c /etc/nagios/passwd nagiosadmin nagiospassword
+ if ! ( grep nagiosadmin /etc/nagios/passwd &> /dev/null ) ; then
+ htpasswd -b -c /etc/nagios/passwd nagiosadmin nagiospassword
+ fi
# disable /etc/httpd/conf.d/nagios.conf restriction to only 127.0.0.1
- if $( grep -q -E "^ deny from all" /etc/httpd/conf.d/nagios.conf ) ; then
- sed -i -e 's/ deny from all/ allow from all/g' /etc/httpd/conf.d/nagios.conf
- sed -i -e 's/ order deny,allow/ order allow,deny/g' /etc/httpd/conf.d/nagios.conf
+ if ( grep -q -E "^ deny from all" /etc/httpd/conf.d/nagios.conf ) ; then
+ sed -i -e 's/ deny from all/ #allow from all/g' /etc/httpd/conf.d/nagios.conf
+ sed -i -e 's/ order deny,allow/ #order allow,deny/g' /etc/httpd/conf.d/nagios.conf
sed -i -e 's/ allow from 127.0.0.1/ /g' /etc/httpd/conf.d/nagios.conf
fi
- touch /etc/nagios/objects/plc.cfg
- touch /etc/nagios/objects/plcusers.cfg
- echo "cfg_file=/etc/nagios/objects/plc.cfg" >> /etc/nagios/nagios.cfg
- echo "cfg_file=/etc/nagios/objects/plcusers.cfg" >> /etc/nagios/nagios.cfg
+ if [ ! -f /etc/nagios/objects/plc.cfg ] ; then
+ /usr/share/monitor/nagios/plc_hosts_to_nagios.py > /etc/nagios/objects/plc.cfg
+ fi
+
+ if [ ! -f /etc/nagios/objects/plcusers.cfg ] ; then
+ /usr/share/monitor/nagios/plc_users_to_nagios.py > /etc/nagios/objects/plcusers.cfg
+ fi
+
- /sbin/chkconfig sendmail on
- /sbin/service sendmail start
+ if ! ( grep -q "cfg_file=/etc/nagios/objects/plc.cfg" /etc/nagios/nagios.cfg) ; then
+ echo "cfg_file=/etc/nagios/objects/plc.cfg" >> /etc/nagios/nagios.cfg
+ echo "cfg_file=/etc/nagios/objects/plcusers.cfg" >> /etc/nagios/nagios.cfg
+ fi
+
+ if ( chkconfig --list sendmail | grep -q 3:off ) ; then
+ /sbin/chkconfig sendmail on
+ /sbin/service sendmail start
+ fi
# change /etc/nagios/objects/contacts.cfg to some real email addr
# change /etc/nagios/nagios.cfg admin_email to some real email addr
#!/usr/bin/python
+
+import plc
from nagiosobjects import *
+from generic import *
command_auto = Command(command_name="check_mode",
command_line="""/usr/share/monitor/nagios/plugins/checkmode.py -H $HOSTNAME$ --sn $SERVICENOTIFICATIONNUMBER$ """)
for obj in globalhost + globalservices:
print obj.toString()
-from monitor.wrapper import plc
-from monitor.generic import *
l_sites = plc.api.GetSites({'login_base' : ['asu', 'gmu', 'gt']})
#l_sites = plc.api.GetSites([10243, 22, 10247, 138, 139, 10050, 10257, 18, 20,
service_description="cPCU",
display_name="cPCU",
servicegroups="NET,PCU",
- notifications_enabled="0",
+ notifications_enabled="1",
check_command="check_pcu")
# NOTE: try to repair the host, if it is online and 'mode' indicates a problem
t1 = 0
t2 = time.time()
- if True:
+ if False:
print "FAKE-OK: PCU test successful"
sys.exit(0)
elif False: