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.
Event Handlers
Re: Event Handlers
"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
So then the event_handler will only execute on a state change, not each time a notification is sent?
Re: Event Handlers
Precisely.
From: http://nagios.sourceforge.net/docs/3_0/ ... dlers.html
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.
"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.
Re: Event Handlers
Here is the script I use for managing Event Handlers.
/usr/local/nagios/libexec/eventhandler.sh
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).
/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/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
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.
"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.