Would event-handler get disabled with scheduled downtime

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
dlukinski
Posts: 1130
Joined: Tue Oct 06, 2015 9:42 am

Would event-handler get disabled with scheduled downtime

Post 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
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: Would event-handler get disabled with scheduled downtime

Post 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
Be sure to check out the Knowledgebase for helpful articles and solutions!
dlukinski
Posts: 1130
Joined: Tue Oct 06, 2015 9:42 am

Re: Would event-handler get disabled with scheduled downtime

Post 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?
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: Would event-handler get disabled with scheduled downtime

Post 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:

Code: Select all

if [$4 -gt 0]
then exit
fi
Be sure to check out the Knowledgebase for helpful articles and solutions!
dlukinski
Posts: 1130
Joined: Tue Oct 06, 2015 9:42 am

Re: Would event-handler get disabled with scheduled downtime

Post 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:

Code: Select all

if [$4 -gt 0]
then exit
fi
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?
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Would event-handler get disabled with scheduled downtime

Post 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
dlukinski
Posts: 1130
Joined: Tue Oct 06, 2015 9:42 am

Re: Would event-handler get disabled with scheduled downtime

Post 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$
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: Would event-handler get disabled with scheduled downtime

Post 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$
Be sure to check out our Knowledgebase for helpful articles and solutions!
dlukinski
Posts: 1130
Joined: Tue Oct 06, 2015 9:42 am

Re: Would event-handler get disabled with scheduled downtime

Post 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
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Would event-handler get disabled with scheduled downtime

Post by tmcdonald »

Ticket received, we'll pick up there. Going to close this thread in the meantime.
Former Nagios employee
Locked