Page 1 of 1

Maintenance Windows for all Hosts / Services

Posted: Tue Aug 21, 2012 8:22 am
by sikainfo
Hi there,
is there any way to schedule a Maintenance Windows for all Hosts and Services under NagiosXI ?

With Nagios Core we have used following script for that, will it work also for NagiosXI ?

Code: Select all

for HOST in `awk '/host_name/ {print $2}' /srv/http/nagios.ch.sika.com/www/etc/objects/xyz.com/hosts.cfg`
do
    echo $HOST
    /usr/local/app/nagios/3.3.1/bin/nagios_down.php -h $HOST -s all -a nagiosadmin -c "Maintenance Window" -f -b "25 Aug 2012 06:00" -e "26 Aug 2012 18:30"
    /usr/local/app/nagios/3.3.1/bin/nagios_down.php -h $HOST -a nagiosadmin -c "Maintenance Window" -f -b "25 Aug 2012 06:00" -e "26 Aug 2012 18:30"
done

Thanks for any help

Andy

Re: Maintenance Windows for all Hosts / Services

Posted: Tue Aug 21, 2012 9:27 am
by scottwilkerson
Assuming nagios_down.php sends the correct command to schedule downtime this should work fine with one exception.

Instead of all of the hosts being in one hosts.cfg file they will be in several *.cfg files located in /usr/local/nagios/etc/hosts/ directory.

If you adjust your script to look for host_name in all of those files it should work fine.

Re: Maintenance Windows for all Hosts / Services

Posted: Wed Aug 22, 2012 8:52 am
by sikainfo
I changed the script to handle that and it works fine.

Code: Select all

#!/bin/bash
#
# Script to define a downtime in NagiosXI for all monitored items (hosts and services)
#
# Requirements:
#
# This script is using a PHP programm "nagios_down.php" this programm should be placed under /usr/local/nagios/bin
# Additional the PHP is using a named pipe (nagios.cmd) which resides under /usr/local/nagios/var/rw
#
# Variable definitions
#
NAGIOS_BASE=/usr/local/nagios
NAGIOS_BIN=$NAGIOS_BASE/bin
NAGIOS_CONF=$NAGIOS_BASE/etc
NAGIOS_HOSTS=$NAGIOS_CONF/hosts
SCRIPTS=/root/scripts/servicewindow
COUNT=0

grep host_name $NAGIOS_HOSTS/*.cfg > $SCRIPTS/hostlist.tmp

for HOST in `awk '/host_name/ {print $3}' $SCRIPTS/hostlist.tmp`
do
        echo -n "Defining downtime for all services ......"
        $NAGIOS_BIN/nagios_down.php -h $HOST -s all -a nagiosadmin -c "Maintenance Window" -f -b "08/25/12 06:00" -e "08/26/12 18:00" > /dev/nul
l 2>&1
        echo " on host: $HOST"
        $NAGIOS_BIN/nagios_down.php -h $HOST -a nagiosadmin -c "Maintenance Window" -f -b "08/25/12 06:00" -e "08/26/12 18:00" > /dev/null 2>&1
        let COUNT++
done
echo "Defined downtime for all services on $COUNT hosts"

Now if someone entered by accident the wrong date and time, is there a way to remove such worng downtime definitions?

Re: Maintenance Windows for all Hosts / Services

Posted: Wed Aug 22, 2012 9:57 am
by scottwilkerson
Using the command info found here
http://old.nagios.org/developerinfo/ext ... and_id=125
and here
http://old.nagios.org/developerinfo/ext ... and_id=126

You can remove downtimes, but you need to know there ID.

Re: Maintenance Windows for all Hosts / Services

Posted: Thu Aug 23, 2012 4:15 am
by sikainfo
Thanks a lot for your help

Regards Andy