Page 1 of 1

global_service_event_handler not working

Posted: Wed Dec 18, 2013 5:43 pm
by ksd13
I have been trying to send SNMPtrap using global_service_event_handler and global_host_event_handler but it does not work. Nagios user can execute commands created for this purpose but nothing happens when service/host events are generated. Nagios does recognize global event handlers defined in nagios.cfg on restart.
Thanks in advance for your comments.

# grep global /etc/nagios/nagios.cfg
global_host_event_handler=send-host-trap
global_service_event_handler=send-service-trap

# cat /etc/nagios/commands.cfg
#'send-service-trap' command definition
define command{
command_name send-service-trap
command_line /usr/local/bin/send-service-trap snmp_host_IP public "$HOSTNAME$" "$SERVICEDESC$" $SERVICESTATEID$ "$SERVICEOUTPUT$"

# cat /usr/local/bin/send-service-trap
# Arguments:
# $1 = Management Station
# $2 = Community String
# $3 = host_name
# $4 = service_description (Description of the service)
# $5 = return_code (An integer that determines the state
# of the service check, 0=OK, 1=WARNING, 2=CRITICAL,
# 3=UNKNOWN).
# $6 = plugin_output (A text string that should be used
# as the plugin output for the service check)
#
#
echo "Service trap sent" | /bin/mailx -s "Service trap sent" [email protected]
sudo /usr/bin/snmptrap -v 2c -c $2 $1 '' NAGIOS-NOTIFY-MIB::nSvcEvent nSvcHostname s "$3" nSvcDesc s "$4" nSvcStateID i $5 nSvcOutput s "$6"

# ls -al /usr/bin/snmptrap
-rwxr-xr-x 1 root root 14648 Aug 24 2011 /usr/bin/snmptrap

Re: global_service_event_handler not working

Posted: Thu Dec 19, 2013 6:39 am
by wfournier
Set log_event_handlers=1 in the nagios.cfg to make sure that the handler is even executed.
You did set enable_event_handlers=1 on nagios.cfg, did you?

Re: global_service_event_handler not working

Posted: Thu Dec 19, 2013 10:24 am
by ksd13
I have both parameters enabled but I do not see it executed.

# egrep 'log_event|enable_event_handlers' /etc/nagios/nagios.cfg
log_event_handlers=1
enable_event_handlers=1

Re: global_service_event_handler not working

Posted: Thu Dec 19, 2013 3:35 pm
by sreinhardt
Could you run this for us please and return the output? This is taking into account a source based install generally on Cent\RHEL so the path may need to change for your system.

Code: Select all

grep -Ri 'event_handler' /usr/local/nagios/etc/

Re: global_service_event_handler not working

Posted: Fri Dec 20, 2013 9:15 am
by ksd13
# grep -Ri 'event_handler' /etc/nagios
/etc/nagios/.#services-infosec.cfg.1.35:event_handler_enabled 1
/etc/nagios/.#services-infosec.cfg.1.35:event_handler_enabled 1
/etc/nagios/services-infosec.cfg:event_handler_enabled 1
/etc/nagios/services-infosec.cfg:event_handler_enabled 1
/etc/nagios/hosts-infosec.cfg: event_handler_enabled 1
/etc/nagios/services.cfg:event_handler_enabled 1
/etc/nagios/services.cfg:event_handler_enabled 1
/etc/nagios/localhost.cfg: event_handler_enabled 1 ; Host event handler is enabled
/etc/nagios/localhost.cfg: event_handler_enabled 1 ; Service event handler is enabled
/etc/nagios/nagios.cfg:log_event_handlers=1
/etc/nagios/nagios.cfg:#global_host_event_handler=somecommand
/etc/nagios/nagios.cfg:#global_service_event_handler=somecommand
/etc/nagios/nagios.cfg:global_host_event_handler=send-host-trap
/etc/nagios/nagios.cfg:global_service_event_handler=send-service-trap
/etc/nagios/nagios.cfg:event_handler_timeout=30
/etc/nagios/nagios.cfg:enable_event_handlers=1

Re: global_service_event_handler not working

Posted: Fri Dec 20, 2013 3:09 pm
by sreinhardt
OK, all of that looks great, you had me for a second with the commented out global event handler lines. :) Could you run:

Code: Select all

grep -i 'handler' /usr/local/nagios/var/nagios.log

Re: global_service_event_handler not working

Posted: Sat Dec 21, 2013 8:03 pm
by ksd13
Sorry for not removing the commented lines. There are no event handlers reported in the logs.
# grep -i handler /san0/nagios-logs/nagios.log
#

Re: global_service_event_handler not working

Posted: Mon Dec 23, 2013 1:02 pm
by abrist
You config looks ok. What is event_handler_timeout set to?

Code: Select all

grep event_handler_timeout /usr/local/nagios/etc/nagios.cfg

Re: global_service_event_handler not working

Posted: Mon Dec 23, 2013 4:32 pm
by ksd13
# grep event_handler_timeout /etc/nagios/nagios.cfg
event_handler_timeout=30

Re: global_service_event_handler not working

Posted: Thu Dec 26, 2013 11:23 am
by slansing
Based on what you are triggering, you may want to push that number a bit further out. You would need to make the change, then restart nagios for it to take effect:

http://nagios.manubulon.com/traduction/ ... er_timeout