global_service_event_handler not working
Posted: Wed Dec 18, 2013 5:43 pm
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
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