Page 1 of 1
Event Handler in Scheduled Downtime
Posted: Thu Jan 11, 2018 12:20 am
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
Re: Event Handler in Scheduled Downtime
Posted: Thu Jan 11, 2018 3:34 pm
by dwhitfield
You can use
https://assets.nagios.com/downloads/nag ... ios-XI.pdf. Page 3 takes you through creating an event handler.
Re: Event Handler in Scheduled Downtime
Posted: Thu Jan 11, 2018 5:46 pm
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.
Re: Event Handler in Scheduled Downtime
Posted: Fri Jan 12, 2018 12:42 pm
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).
Re: Event Handler in Scheduled Downtime
Posted: Fri Feb 09, 2018 12:01 am
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
Re: Event Handler in Scheduled Downtime
Posted: Fri Feb 09, 2018 9:03 am
by dwhitfield
Thanks for sharing! Are we ready to lock this one up?