Event Handlers

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
yaanatech
Posts: 74
Joined: Thu Mar 29, 2012 1:23 pm

Event Handlers

Post 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.
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Event Handlers

Post 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.
yaanatech
Posts: 74
Joined: Thu Mar 29, 2012 1:23 pm

Re: Event Handlers

Post by yaanatech »

So then the event_handler will only execute on a state change, not each time a notification is sent?
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Event Handlers

Post 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
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
User avatar
CGraham
Posts: 115
Joined: Tue Aug 16, 2011 2:43 pm

Re: Event Handlers

Post 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).
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Event Handlers

Post by abrist »

Does the script work, are you having any other issues?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked