Nagios failing to expand $CONTACTEMAIL$ macro in notificaion command

nagios

I'm having a problem where my nofication command isn't expanding the $CONTACTEMAIL$ macro

(Version 3.2.1 installed on debian squeeze using the debian packages)

me@hostname:/etc/nagiosql# dpkg -l | grep nagios
ii  nagios-images                                          0.7                                   Collection of images and icons for the nagios system
ii  nagios-nrpe-plugin                                     2.12-4                       Nagios Remote Plugin Executor Plugin
ii  nagios-plugins                                         1.4.15-3squeeze1             Plugins for the nagios network monitoring and management system
ii  nagios-plugins-basic                                   1.4.15-3squeeze1             Plugins for the nagios network monitoring and management system
ii  nagios-plugins-standard                                1.4.15-3squeeze1             Plugins for the nagios network monitoring and management system
ii  nagios3                                                3.2.1-2                      A host/service/network monitoring and management system
ii  nagios3-cgi                                            3.2.1-2                      cgi files for nagios3
ii  nagios3-common                                         3.2.1-2                      support files for nagios3
ii  nagios3-core                                           3.2.1-2                      A host/service/network monitoring and management system core files

I have this in my commands.cfg

define command {
    command_name                    notify_by_email
    command_line                    /usr/bin/printf "%b" "Notification:\t$NOTIFICATIONTYPE$\n\nOccurred:\t$DATETIME$\nHostname:\t$HOSTALIAS$ ($HOSTADDRESS$)\nService:\t$SERVICEDESC$\nState:\t\t$SERVICESTATE$\nDetails:\n\ n$OUTPUT$" | /usr/bin/mail -s "$NOTIFICATIONTYPE$: $HOSTALIAS$/$SERVICEDESC$ -- $SERVICESTATE$" $CONTACTEMAIL$ 
    register                        1
}       

and in contacts.cfg

define contact {
    contact_name                    navaho
    contactgroups                   pagers
    host_notifications_enabled      1
    service_notifications_enabled   1
    host_notification_period        24x7
    service_notification_period     24x7
    host_notification_options       d,u,r,f,s
    service_notification_options    w,u,c,r,s,n
    host_notification_commands      notify_by_email
    service_notification_commands   notify_by_email
    email                           myemail@mydomain.com
    register                        1
    }       

In my service config file I have

define service {
    host_name                       servicehost.mydomain.com
    hostgroup_name                  null
    service_description             SE:
    display_name                    SE:
    check_command                   check_se
    max_check_attempts              5
    check_interval                  5
    retry_interval                  5
    active_checks_enabled           1
    check_period                    24x7
    event_handler                   notify_by_email
    notification_interval           5
    notification_period             24x7
    notification_options            w,u,r,c,s
    notifications_enabled           1
    contacts                        navaho
    contact_groups                  pagers
    register                        1
}       

With these configs I would expect nagios to be sending notifications to the email address myemail@mydomain.com, if I shut down the SE: service on myservicehost. It doesn't.

Aug  1 13:56:12 myhostname postfix/cleanup[25382]: 2DC5F28054: message-id=<20110801205612.2DC5F28054@myhostname.mydomain.net>
Aug  1 13:56:12 myhostname postfix/qmgr[22452]: 2DC5F28054: from=<nagios@myhostname.mydomain.net>, size=470, nrcpt=1 (queue active)
Aug  1 13:56:12 myhostname postfix/local[25384]: 2DC5F28054: to=<$@myhostname.mydomain.net>, orig_to=<$>, relay=local, delay=0.07, delays=0.05/0.01/0/0.01, dsn=5.1.1, status=bounced (unknown user: "$")
Aug  1 13:56:12 myhostname postfix/cleanup[25382]: 3B96B28055: message-id=<20110801205612.3B96B28055@myhostname.mydomain.net>

Note the $@myhostname.mydomain.net, orig_to=

When I modify the command in commands.cfg to hardcode it to my actual email, it sends perfectly

/usr/bin/printf "%b" "Notification:\t$NOTIFICATIONTYPE$\n\nOccurred:\t$DATETIME$\nHostname:\t$HOSTALIAS$ ($HOSTADDRESS$)\nService:\t$SERVICEDESC$\nState:\t\t$SERVICESTATE$\nDetails:\n\ n$OUTPUT$" | /usr/bin/mail -s "$NOTIFICATIONTYPE$: $HOSTALIAS$/$SERVICEDESC$ -- $SERVICESTATE$" myemail@mydomain.com 

What could I be missing that is making nagios not expand out $CONTACTEMAIL$ macro?

EDIT: After a suggestion by quanta posted below I turned on debugging and used an on demand macro to see what nagios was doing. While I can't yet explain why, nagios seemingly wasn't expanding the macro because it was bare. I changed $CONTACTEMAIL$ to '$CONTACTEMAIL' and it started to work.

Best Answer

  • Turn on debug level to have a closer look at nagios.log
  • Try with on-demand macro $CONTACTEMAIL:navaho$ to see if it works
Related Topic