global_service_event_handler not working

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
ksd13
Posts: 6
Joined: Wed Dec 18, 2013 5:28 pm

global_service_event_handler not working

Post 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
wfournier
Posts: 7
Joined: Fri Oct 04, 2013 2:44 am

Re: global_service_event_handler not working

Post 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?
ksd13
Posts: 6
Joined: Wed Dec 18, 2013 5:28 pm

Re: global_service_event_handler not working

Post 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
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: global_service_event_handler not working

Post 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/
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
ksd13
Posts: 6
Joined: Wed Dec 18, 2013 5:28 pm

Re: global_service_event_handler not working

Post 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
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: global_service_event_handler not working

Post 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
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
ksd13
Posts: 6
Joined: Wed Dec 18, 2013 5:28 pm

Re: global_service_event_handler not working

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

Re: global_service_event_handler not working

Post 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
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.
ksd13
Posts: 6
Joined: Wed Dec 18, 2013 5:28 pm

Re: global_service_event_handler not working

Post by ksd13 »

# grep event_handler_timeout /etc/nagios/nagios.cfg
event_handler_timeout=30
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: global_service_event_handler not working

Post 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
Locked