5

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                           [email protected]
    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 [email protected], if I shut down the SE: service on myservicehost. It doesn't.

Aug  1 13:56:12 myhostname postfix/cleanup[25382]: 2DC5F28054: message-id=<[email protected]>
Aug  1 13:56:12 myhostname postfix/qmgr[22452]: 2DC5F28054: from=<[email protected]>, size=470, nrcpt=1 (queue active)
Aug  1 13:56:12 myhostname postfix/local[25384]: 2DC5F28054: to=<[email protected]>, 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=<[email protected]>

Note the [email protected], 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$" [email protected] 

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.

3
  • UPDATE: I've updated nagios from 3.2.1 to 3.2.3. No change. I also have tried $CONTACTPAGER$ and $CONTACTALIAS$ just to see if I could make a change in the behaviour. No, still sends to $@ yet if I put my email address in there in place of $CONTACTALIAS$ it sends to me just fine.
    – navaho
    Aug 3, 2011 at 1:55
  • Could you please put the solution in a post below and mark it as the right answer? This way it won't get kicked to the front page now and then. Aug 3, 2011 at 19:47
  • 1
    I cannot accept my own answer for 23 more hours, I did post it though, with an update as to what looks to be the root of the issue. I'll accept it tomorrow.
    – navaho
    Aug 3, 2011 at 21:42

6 Answers 6

2
  • Turn on debug level to have a closer look at nagios.log
  • Try with on-demand macro $CONTACTEMAIL:navaho$ to see if it works
3
  • Better, but still not right. Now instead of $ nagios sent the email to navaho@ the nagios server hostname, rather than navaho's email address as listed in contacts.cfg.
    – navaho
    Aug 3, 2011 at 17:25
  • the log lines:[1312392300.090484] [2048.2] [pid=4704] Processing part: 'CONTACTEMAIL:navaho' [1312392300.090510] [2048.2] [pid=4704] macro_x[22] (CONTACTEMAIL) match. [1312392300.090537] [2048.2] [pid=4704] Processed 'CONTACTEMAIL:navaho', Clean Options: 0, Free: 1 [1312392300.090561] [2048.0] [pid=4704] WARNING: An error occurred processing macro 'CONTACTEMAIL:navaho'!'
    – navaho
    Aug 3, 2011 at 17:26
  • I found it. While your suggestion didn't work, it led me to the right place. I'll edit the original post with what I did to make it work.
    – navaho
    Aug 3, 2011 at 17:37
1

The problem is the 'n' in the service_notification_options:

http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html

service_notification_options: If you specify n (none) as an option, the contact will not receive any type of service notifications.

6
  • I'm pretty sure that would make it not even send, not send to $@.. nonetheless I did remove the n and it is still sending email to $@
    – navaho
    Aug 2, 2011 at 23:52
  • Try going to the 'view config' section on nagios, and looking at services. Make sure everything on that line looks correct, then click on the contacts listed and make sure all the info there looks correct. There might be some unintended inheritance going on.
    – opsguy
    Aug 3, 2011 at 0:35
  • I don't see anything incorrect there.
    – navaho
    Aug 3, 2011 at 1:53
  • When you view the contacts in the config, does the email properly show up under the navaho user?
    – opsguy
    Aug 3, 2011 at 2:19
  • Yes, it does appear as it should. The email is properly formed, and when viewed via the nagios config area clickable. Just to be certain, I went to the point of clicking it, which opens an email in my mail client that sends to the right person.
    – navaho
    Aug 3, 2011 at 3:13
1

There is an error in your contacts.cfg.
Remove the nfrom the list service_notification_options the n stands for none...

Like this:

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
    host_notification_commands      notify_by_email
    service_notification_commands   notify_by_email
    email                           [email protected]
    register                        1
    } 
1
  • Good catch. I did remove the n, and the same thing resulted, however. still sending email to $@
    – navaho
    Aug 2, 2011 at 23:49
1

After a suggestion by quanta posted below I turned on debugging and then used an on demand macro to see what nagios was actually 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. Oddly, Double quotes did not work.

As I work with it more it appears that $OUTPUT$ has unescaped html which is causing the issues.

0

Try putting $CONTACTEMAIL$ in quotes in the command_line in commands.cfg

1
  • No change. Wish it were that easy. I'd already tried and did it again, just in case. Same thing, sending to [email protected]
    – navaho
    Aug 2, 2011 at 21:28
0

Are there any non-printable characters contained in the $CONTACTEMAIL$ string, thus not making it match anything?

3
  • none at all. 6 letters then @ mydomain. no dots, dashes, speaces, or even numbers.
    – navaho
    Aug 2, 2011 at 21:43
  • What about in "$CONTACTEMAIL$" itself as it sits on the line before dereferencing?
    – mdpc
    Aug 2, 2011 at 21:57
  • I'm afraid that I don't know what you're asking.
    – navaho
    Aug 2, 2011 at 22:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .