Page 1 of 1
Would event-handler get disabled with scheduled downtime
Posted: Thu Aug 18, 2016 1:02 pm
by dlukinski
Hello XI Support
We had configured Windows Service event handling (start back if stopped)
as per
https://assets.nagios.com/downloads/nag ... 1454484852
Please advice if scheduled downtime (host or service) would prevent event handler from triggering service startup (as it hopefully should)
- we need the way to disable event handling during server/services maintenance (done by users, not via service deactivations)
Thank you
Re: Would event-handler get disabled with scheduled downtime
Posted: Thu Aug 18, 2016 2:14 pm
by bwallace
I just answered this question another thread recently.
Short answer is no, event handlers remain active during scheduled downtime. But, you can write logic into your event handler scripts so they will not run if downtime is detected. This is accomplished by using the $HOSTDOWNTIME$ and/or $SERVICEDOWNTIME$ macros in your event handler definitions. If these macros are non-zero, then the service/host is considered to be in scheduled downtime. This will allow you to have your event handlers decide how to proceed.
Two other options (not ideal, do these for the duration of the scheduled downtime)
- Disable all event handlers globally in nagios.cfg = enable_event_handlers
- Disable event handler at the host or service level, check for 'event_handler = enabled' in the definition.
Understanding Macros and How They Work
https://assets.nagios.com/downloads/nag ... acros.html
Re: Would event-handler get disabled with scheduled downtime
Posted: Thu Aug 18, 2016 2:35 pm
by dlukinski
bwallace wrote:I just answered this question another thread recently.
Short answer is no, event handlers remain active during scheduled downtime. But, you can write logic into your event handler scripts so they will not run if downtime is detected. This is accomplished by using the $HOSTDOWNTIME$ and/or $SERVICEDOWNTIME$ macros in your event handler definitions. If these macros are non-zero, then the service/host is considered to be in scheduled downtime. This will allow you to have your event handlers decide how to proceed.
Two other options (not ideal, do these for the duration of the scheduled downtime)
- Disable all event handlers globally in nagios.cfg = enable_event_handlers
- Disable event handler at the host or service level, check for 'event_handler = enabled' in the definition.
Understanding Macros and How They Work
https://assets.nagios.com/downloads/nag ... acros.html
Well, event handler is one of yours from assets:
File: servicer~tart.sh Line 1 Col 0 227 bytes 100%
#!/bin/sh
# Event Handler for Restarting Linux/BSD/Windows Services
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
/usr/local/nagios/libexec/check_nrpe -H "$2" -p 5666 -c runcmd -a "$3"
;;
esac
exit 0
Could you please help us to get it working with scheduled downtimes?
Re: Would event-handler get disabled with scheduled downtime
Posted: Fri Aug 19, 2016 10:14 am
by bwallace
Here you go....
The command in XI should be changed to this:
check_nrpe -H $HOSTADDRESS$ $ARG2$ -p -c runcmd -a $ARG3$ $ARG4$
And the script should now look like:
Code: Select all
#!/bin/sh
# Event Handler for Restarting Linux/BSD/Windows Services
if [$4 -gt 0]
then exit
fi
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
/usr/local/nagios/libexec/check_nrpe -H "$2" -p 5666 -c runcmd -a "$3"
;;
esac
exit 0
Only thing that's new in the script are those 1st 3 UNcommented lines:
Re: Would event-handler get disabled with scheduled downtime
Posted: Wed Aug 31, 2016 2:10 pm
by dlukinski
bwallace wrote:Here you go....
The command in XI should be changed to this:
check_nrpe -H $HOSTADDRESS$ $ARG2$ -p -c runcmd -a $ARG3$ $ARG4$
And the script should now look like:
Code: Select all
#!/bin/sh
# Event Handler for Restarting Linux/BSD/Windows Services
if [$4 -gt 0]
then exit
fi
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
/usr/local/nagios/libexec/check_nrpe -H "$2" -p 5666 -c runcmd -a "$3"
;;
esac
exit 0
Only thing that's new in the script are those 1st 3 UNcommented lines:
Hi
This did not work (updated handling script, scheduled downtime, but handler still restarts the services)
Should we make a ticket out of this one?
Re: Would event-handler get disabled with scheduled downtime
Posted: Wed Aug 31, 2016 2:35 pm
by ssax
Did you use $SERVICEDOWNTIME$ or $HOSTDOWNTIME$? If you used $SERVICEDOWNTIME$ was the service in downtime or just the host?
Please post your command definition as well so that we may review it.
Thank you
Re: Would event-handler get disabled with scheduled downtime
Posted: Thu Sep 01, 2016 9:15 am
by dlukinski
ssax wrote:Did you use $SERVICEDOWNTIME$ or $HOSTDOWNTIME$? If you used $SERVICEDOWNTIME$ was the service in downtime or just the host?
Please post your command definition as well so that we may review it.
Thank you
I think I missed this one. How to use it?
$USER1$/check_nt -H $HOSTADDRESS$ -s "$ARG1$" -p 12489 -v $ARG2$ $ARG3$ $ARG4$
Re: Would event-handler get disabled with scheduled downtime
Posted: Thu Sep 01, 2016 1:52 pm
by tgriep
The changes for this have to be added to the event handler script called service_restart. Try editing like the example below and see if that works for you.
Code: Select all
define command {
command_name service_restart
command_line $USER1$/servicerestart.sh $SERVICESTATE$ $HOSTADDRESS$ $_SERVICESERVICE$ $SERVICEDOWNTIME$
Re: Would event-handler get disabled with scheduled downtime
Posted: Fri Sep 02, 2016 1:58 pm
by dlukinski
tgriep wrote:The changes for this have to be added to the event handler script called service_restart. Try editing like the example below and see if that works for you.
Code: Select all
define command {
command_name service_restart
command_line $USER1$/servicerestart.sh $SERVICESTATE$ $HOSTADDRESS$ $_SERVICESERVICE$ $SERVICEDOWNTIME$
This is still not working / creating ticket instead
Re: Would event-handler get disabled with scheduled downtime
Posted: Tue Sep 06, 2016 9:22 am
by tmcdonald
Ticket received, we'll pick up there. Going to close this thread in the meantime.