Nagios send trap event handler question

Winkles, William (Bill) billwinkles at lucent.com
Wed Nov 3 22:01:31 CET 2004


Can anyone explain to me how I would setup an event handler to send a trap
when a service hits a hard state?

Currently I have added this to my services.cfg file under the service
definition I want to trap on:

event_handler                   send-trap


I am not sure where to set up send-trap now.  I have added this to my
checkcommands.cfg file as:

# 'send-trap' command definition
define command{
	command_name	send-trap
 	command_line	/usr/local/bin/snmptrap  -v 1 -c public
192.234.243.145 1.3.6.1.4.1.3224 $HOSTADDRESS$ 6
 17 ''
 	}

And also tried this:


# 'send-trap' command definition
define command{
	command_name	send-trap
 	command_line	$USER1$/send-trap $HOSTADDRESS$
 	}

Where send-trap is a modified version of the example event handler script
from the nagios docs:


#!/bin/sh
#
# Event handler script for sending a trap
#
# 
#


# What state is the service in?
case "$1" in
OK)
	# The service just came back up, so don't do anything...
	;;
WARNING)
	# We don't really care about warning states, since the service is
probably still running...
	;;
UNKNOWN)
	# We don't know what might be causing an unknown error, so don't do
anything...
	;;
CRITICAL)
	# Aha!  The service appears to have a problem - perhaps we should
send a trap...

	# Is this a "soft" or a "hard" state?
	case "$2" in
		
	# We're in a "soft" state, meaning that Nagios is in the middle of
retrying the
	# check before it turns into a "hard" state and contacts get
notified...
	SOFT)
			
		# What check attempt are we on?  We don't want to restart
the web server on the first
		# check, because it may just be a fluke!
		case "$3" in
				
		# Wait until the check has been tried 3 times before sending
the trap.
		# If the check fails on the 4th time (after we restart the
web server), the state
		# type will turn to "hard" and contacts will be notified of
the problem.
		# Hopefully this will restart the web server successfully,
so the 4th check will
		# result in a "soft" recovery.  If that happens no one gets
notified because we
		# fixed the problem!
		3)
			echo -n "Sending a Trap (3rd soft critical
state)..."
			# Call the script to send a trap
                        /usr/local/bin/snmptrap -v 1 -c public
192.234.243.145 1.3.6.1.4.1.3224 $HOSTADDRESS$ 6 17 ''
			;;
			esac
		;;
				
	
		echo -n "Sending Trap..."
		# Call the script to send a trap
		/usr/local/bin/snmptrap -v 1 -c public 192.234.243.145
1.3.6.1.4.1.3224 $HOSTADDRESS$ 6 17 ''
		;;
		;;
	esac
	;;
esac
exit 0


The only thing I get from the nagios.log file is:

[1099515319] SERVICE EVENT HANDLER: Demo;E1_Interface_State;WARNING;
HARD;1;send-trap

No trap is sent.

Any ideas what am I missing here?

Thanks.

Bill




-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click




More information about the Users mailing list