Maintenance Windows for all Hosts / Services

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
sikainfo
Posts: 105
Joined: Thu Mar 29, 2012 3:26 am

Maintenance Windows for all Hosts / Services

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Maintenance Windows for all Hosts / Services

Post 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.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
User avatar
sikainfo
Posts: 105
Joined: Thu Mar 29, 2012 3:26 am

Re: Maintenance Windows for all Hosts / Services

Post 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?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Maintenance Windows for all Hosts / Services

Post 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.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
User avatar
sikainfo
Posts: 105
Joined: Thu Mar 29, 2012 3:26 am

Re: Maintenance Windows for all Hosts / Services

Post by sikainfo »

Thanks a lot for your help

Regards Andy
Locked