Page 1 of 1

Event handlers

Posted: Wed May 03, 2017 7:47 am
by jkinning
I have a request from one of our business units that when a certain service goes critical they would like to have Nagios restart tomcat first and then if that still fails send out a notification. I was reading this pdf on how to set this all up but not sure if this will correct the critical notifications from being dispatched.

Code: Select all

 https://assets.nagios.com/downloads/nagiosxi/docs/Restarting-Windows-Services-With-NRPE-in-Nagios-XI.pdf?_ga=2.63505319.964425772.1493815062-68545757.1490190270 
So, when the service goes critical initially do notifications get sent out or will the event handler restart the service. If it tries to restart once, not sure how to determine how many times to try but plan to test this out later today, and service is still not OK will Nagios send out the notifications? Of does it also send out the notifications the first time as well when the event handler runs?

Re: Event handlers

Posted: Wed May 03, 2017 11:38 am
by tgriep
When Are Event Handlers Executed In Nagios XI?
Event handlers are called whenever a state change occurs. This includes HARD and SOFT state types, as
well as OK, WARNING, CRITICAL, and UNKNOWN states. The logic for what actions to take, if any, when a
state change occurs is performed by the script or executable that is called by Nagios XI at the moment of the
state change. The script can parse these states through macros passed to it by the event handler.
For example, an event handler can be created that restarts a service if and only if that service has entered a
HARD CRITICAL state. This is possible passing the script the $SERVICESTATE$ (OK, WARNING,
UNKNOWN, CRITICAL) macro and the $SERVICESTATETYPE$ (HARD, SOFT) macro. It is the responsibility
of the person writing the script to make sure the script logic handles the passed macros appropriately
Take a look at this document for more details.
https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Now, if your service check runs, detects a critical state and run the event handler and that handler repairs the failure, then there will be no email notification sent.
If the handler cannot fix the issue and the check gets to the Max Check Attempts while it is still in a non OK state, that is when the email notification is sent.

Does that help out in your questions?