Event Handler in Scheduled Downtime

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
computerone
Posts: 21
Joined: Thu Jan 03, 2013 9:04 pm

Event Handler in Scheduled Downtime

Post by computerone »

Hi,

Can anyone please share a script to restart windows service using event handler. Event handler only runs when host or service is not in scheduled downtime and output the results into a log file.

Thanks,
Khawar Syed
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Event Handler in Scheduled Downtime

Post by dwhitfield »

You can use https://assets.nagios.com/downloads/nag ... ios-XI.pdf. Page 3 takes you through creating an event handler.
computerone
Posts: 21
Joined: Thu Jan 03, 2013 9:04 pm

Re: Event Handler in Scheduled Downtime

Post by computerone »

Thanks dwhitfield for the link.

I have been to that link and already created event handler. Issue is that event handler starts the service even when host or service is in scheduled downtime.
I want a script to check if host or service is in downtime and if that's true event handler doesn't start service.

hope that make sense.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Event Handler in Scheduled Downtime

Post by lmiltchev »

You could somehow incorporate the $HOSTDOWNTIME$ and $SERVICEDOWNTIME$ macros in your script (which are standard nagios macros) by adding a simple if/else statement. If the value of the macro>0, start the service, else - don't start it (exit).
Be sure to check out our Knowledgebase for helpful articles and solutions!
computerone
Posts: 21
Joined: Thu Jan 03, 2013 9:04 pm

Re: Event Handler in Scheduled Downtime

Post by computerone »

for anyone who needs this is the script to check if host or service is in downtime or not.

#!/bin/sh
#$1 defines service state, $2 defines hostname, $3 defines servicename to restart on windows server ,$4 defines servicestate, $5 defines hostdowntime, $6 defines servicedowntime

logfile=/usr/local/nagios/libexec/eventhandler.log
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
if [[ "$4" == "HARD" ]] && [[ "$5" == "0" ]] && [[ "$6" == "0" ]]
then
/usr/local/nagios/libexec/check_nrpe -H "$2" -p 5666 -c restart_service -a "$3" >> $logfile
echo ServiceState $4 >> $logfile
echo HostDownTime $5 >> $logfile
echo ServiceDownTime $6 >> $logfile
fi
;;
esac
exit 0
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Event Handler in Scheduled Downtime

Post by dwhitfield »

Thanks for sharing! Are we ready to lock this one up?
Locked