#!/bin/bash # # chkconfig: - 65 35 # # Provides: monitor-nagios # Required-Start: mysqld sendmail # Defalt-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Description: Setup requirements for monitor to work with nagios # # Stephen Soltesz # Copyright (C) 2010 The Trustees of Princeton University # # $Id$ # 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 &> /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 &> /dev/null ) ; then cat < /tmp/nagios.priv GRANT ALL PRIVILEGES ON nagios.* TO ndouser@localhost IDENTIFIED BY 'ndopassword'; EOF cat /tmp/nagios.priv | mysql -u root cd /usr/share/doc/ndoutils-mysql-*/db perl ./installdb -u ndouser -p ndopassword -d nagios fi 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 fi 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 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 "^service_check_timeout=60" /etc/nagios/nagios.cfg ) ; then # NOTE: PCU checks can take several minutes due to timeouts and internal delays sed -i -e 's/service_check_timeout=.*/service_check_timeout=150/g' /etc/nagios/nagios.cfg # NOTE: All 'action' commands are in the notification category. # Complex actions such as 'repair.py' may take several minutes. sed -i -e 's/notification_timeout=.*/notification_timeout=240/g' /etc/nagios/nagios.cfg 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 sed -i -e 's/ allow from 127.0.0.1/ /g' /etc/httpd/conf.d/nagios.conf fi 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 if ! ( grep -q "cfg_file=/etc/nagios/objects/plcnodes.cfg" /etc/nagios/nagios.cfg ) ; then echo "cfg_file=/etc/nagios/objects/plcnodes.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 } # See how we were called. case "$1" in start) start ;; stop) echo "not implemented" ;; status) echo "not implemented" ;; restart) echo "not implemented" ;; *) echo $"Usage: $0 {start|stop|status|condrestart|restart}" exit 1 esac exit $?