Page 1 of 1

Event Handlers

Posted: Tue Feb 05, 2013 2:56 pm
by yaanatech
I have a couple questions in regards to event handlers;

1. If I specify an event handler inside a service check, does that override use of the normal event that sends the e-mail notification to the contacts?
2. Is it possible to just have an event handler run once? ie. a service alerts - the event handler is run 1 time, not to run again until after the service clears and re-alarms later.

I want to write an event that fires an e-mail to Remedy, that will be ingested and a ticket created, but I don't each notifications, which are every 5 minutes, to create a separate Remedy ticket.

Re: Event Handlers

Posted: Tue Feb 05, 2013 3:23 pm
by mguthrie
"Events" in Nagios are actually state changes for hosts and services, so you can write an event handler, or even a global event handler in addition to your regular notification handlers in Nagios. We used the same concept with Nagios IM, where we wrote a global event handler to process state changes and pass appropriate ones to the ticketing system.

Re: Event Handlers

Posted: Wed Feb 06, 2013 4:59 pm
by yaanatech
So then the event_handler will only execute on a state change, not each time a notification is sent?

Re: Event Handlers

Posted: Wed Feb 06, 2013 5:02 pm
by abrist
Precisely.

From: http://nagios.sourceforge.net/docs/3_0/ ... dlers.html
Event handlers are executed when a service or host:

Is in a SOFT problem state
Initially goes into a HARD problem state
Initially recovers from a SOFT or HARD problem state

Re: Event Handlers

Posted: Mon Feb 11, 2013 5:03 pm
by CGraham
Here is the script I use for managing Event Handlers.

/usr/local/nagios/libexec/eventhandler.sh

Code: Select all

#!/bin/sh

# The actual service state (problem, ok, etc)
SSACTUAL=$1

# The actual service type (soft, hard, etc)
STYPEACTUAL=$2

# The desired service when to do something
STYPEDESIRED=$3

# The number of actual attempts so far
SATTEMPTACTUAL=$4

# The desired attempt when you want to do something
SATTEMPTDESIRED=$5

# Information you can use for logging, and creating action
HOST=$6
COMMAND=$7
HOSTNAME=$8
HOSTDOWNTIME=$9

# If you are not in downtime, but in a critical state and the type and attempt match
if [ "$HOSTDOWNTIME" = "0" ] && [ "$SSACTUAL" = "CRITICAL" ] && [ "$STYPEACTUAL" = "$STYPEACTUAL" ] && [ "$SATTEMPTACTUAL" = "$SATTEMPTDESIRED" ]; then

...do something...

        exit 0;
fi

# If you are not in downtime, but in a warning state and the type and attempt match
if [ "$HOSTDOWNTIME" = "0" ] && [ "$SSACTUAL" = "WARNING" ] && [ "$STYPEACTUAL" = "$STYPEACTUAL" ] && [ "$SATTEMPTACTUAL" = "$SATTEMPTDESIRED" ]; then

...do something...

        exit 0;
fi
In NagiosXI, my event handler command would look like this:

/usr/local/nagios/libexec/eventhandler.sh $SERVICESTATE$ $SERVICESTATETYPE$ SOFT $SERVICEATTEMPT$ 2 $HOSTADDRESS$ somecommand $HOSTNAME$ $HOSTDOWNTIME$

So when my check fails the second check in critical or warning states, I can have the nagiosxi server do something (like create a Remedy ticket).

Re: Event Handlers

Posted: Mon Feb 11, 2013 5:16 pm
by abrist
Does the script work, are you having any other issues?