Page 1 of 1

Only notify-service-by-email not working

Posted: Fri Dec 27, 2013 4:01 pm
by ServerMonkey
I've run into an interesting problem using Nagios 3.5.1. The notify-host-by-email command works just fine, but notify-service-by-email doesn't even run the specified command line. No error is thrown or logged, it just silently goes nowhere. This is all I see in the logs:

Code: Select all

[1388177492] EXTERNAL COMMAND: SEND_CUSTOM_SVC_NOTIFICATION;artsci;http;3;michael;Testing notification
[1388177492] SERVICE NOTIFICATION: ops;artsci;http;CUSTOM (OK);notify-service-by-email;HTTP OK: HTTP/1.0 200 OK - 31151 bytes in 0.030 second response time;michael;Testing notification
The command definitions for both are very similar:

Code: Select all

define command{
        command_name    notify-host-by-email
        command_line /usr/sbin/nagmail --atype host --caddr $CONTACTEMAIL$ --ntype $NOTIFICATIONTYPE$ --hname $HOSTNAME$ --hstate $HOSTSTATE$ --haddr $HOSTADDRESS$ --hout $HOSTOUTPUT$ --ldtime $LONGDATETIME$
        }

define command{
        command_name    notify-service-by-email
        command_line /usr/sbin/nagmail --atype service --caddr $CONTACTEMAIL$ --ntype $NOTIFICATIONTYPE$ --sdesc $SERVICEDESC$ --halias $HOSTALIAS$ --sstate $SERVICESTATE$ --haddr $HOSTADDRESS$  --ldtime $LONGDATETIME$ --sout $SERVICEOUTPUT$
        }
The /usr/sbin/nagmail is a perl wrapper that I built to give me more control over debugging, SMTP settings, etc. But it isn't even being run when notify-service-by-email is called. I've confirmed that by having the script write a file each time it runs (whether it works or not), and that file is only written when Nagios calls notify-host-by-email.

Any ideas? I'm running under CentOS 6.5, using Nagios 3.5.1 from the EPEL yum repository.

Re: Only notify-service-by-email not working

Posted: Mon Dec 30, 2013 10:17 am
by abrist
You may need to wrap the macros that could potentially have spaces with quotes. Without the quotes, the command may silently die when a space in a macro is interpreted as an argument separator.

Code: Select all

define command{
        command_name    notify-host-by-email
        command_line /usr/sbin/nagmail --atype host --caddr $CONTACTEMAIL$ --ntype $NOTIFICATIONTYPE$ --hname "$HOSTNAME$" --hstate $HOSTSTATE$ --haddr $HOSTADDRESS$ --hout "$HOSTOUTPUT$" --ldtime "$LONGDATETIME$"
        }

define command{
        command_name    notify-service-by-email
        command_line /usr/sbin/nagmail --atype service --caddr $CONTACTEMAIL$ --ntype $NOTIFICATIONTYPE$ --sdesc "$SERVICEDESC$" --halias "$HOSTALIAS$" --sstate $SERVICESTATE$ --haddr $HOSTADDRESS$  --ldtime "$LONGDATETIME$" --sout "$SERVICEOUTPUT$"
        }