Unable to get $CONTACTEMAIL$ to expand

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.
navaho
Posts: 12
Joined: Mon Aug 01, 2011 4:43 pm

Unable to get $CONTACTEMAIL$ to expand

Post by navaho »

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)

Code: Select all

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

Code: Select all

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

Code: Select all

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
        }       
This should expand out to sending notifications to myemail@mydomain.com, but it does not.

Code: Select all

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 with my actual email, it sends perfectly

Code: Select all

/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?
agriffin
Posts: 876
Joined: Mon May 09, 2011 9:36 am

Re: Unable to get $CONTACTEMAIL$ to expand

Post by agriffin »

Are there any special characters in your email address?
navaho
Posts: 12
Joined: Mon Aug 01, 2011 4:43 pm

Re: Unable to get $CONTACTEMAIL$ to expand

Post by navaho »

Thank you for replying.

No, no special characters at all.The format is Myfirstname@mydomain.com. 6 letters, not hyphens or dots in the name, no numbers, no special characters.
agriffin
Posts: 876
Joined: Mon May 09, 2011 9:36 am

Re: Unable to get $CONTACTEMAIL$ to expand

Post by agriffin »

Hmm... Are you sure there are no typos, and the correct contact is associated with the host? Does it happen with other contacts?
navaho
Posts: 12
Joined: Mon Aug 01, 2011 4:43 pm

Re: Unable to get $CONTACTEMAIL$ to expand

Post by navaho »

No typos that I am able to see.

I fixed commands.cfg back to $CONTACTEMAIL$ from my hardcoded email address, I added another contact, shut a service down and watched the mail log. Same result, it sent mail to $ @ the nagios server's host name.
agriffin
Posts: 876
Joined: Mon May 09, 2011 9:36 am

Re: Unable to get $CONTACTEMAIL$ to expand

Post by agriffin »

Can you try mailing yourself something from the command line?

Code: Select all

echo test | mail myemail@mydomain.com
navaho
Posts: 12
Joined: Mon Aug 01, 2011 4:43 pm

Re: Unable to get $CONTACTEMAIL$ to expand

Post by navaho »

Yes, and mail is working properly on this server.

I'm sorry, but the focus here is not whether mail sends or not, it does. The focus is that the command works perfectly with my email hardcoded on the end of the command instead of $CONTACTEMAIL$ macro.

This works, run manually or by nagios

/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

With my email address hard coded nagios sends me a notification of services going up or down properly and as it should.


/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$

This does not. With the $CONTACTEMAIL$ macro it sends to $ @ nagios server hostname. Why does $CONTACTEMAIL$ not translate?

I'm aware that I'm coning across as a jerk, and I don't mean to, but I feel as though we're headed in the wrong direction by checking to see that mail even works after posting mail log extracts and posting that it works fine if the email address is hard coded.
agriffin
Posts: 876
Joined: Mon May 09, 2011 9:36 am

Re: Unable to get $CONTACTEMAIL$ to expand

Post by agriffin »

You don't come across as a jerk, it's just that I'm pretty baffled too and just want to make sure that you didn't miss something simple. Your configs look totally correct to me.

There were a few bug fixes in 3.2.2 related to macros and email notifications. You may want to try upgrading to see if that fixes the problem. Unfortunately there's no clean & straightforward way to do that in Debian. You could compile from source, but then you'll have to move your config files around a bit. You could also install updated packages from Debian's testing repo. You can download them manually from Debian's archive and install each package and their dependencies one at a time, or you could enable the testing repo and deal with the mess that is apt_preferences to get your package manager to handle dependencies and updates automatically.
navaho
Posts: 12
Joined: Mon Aug 01, 2011 4:43 pm

Re: Unable to get $CONTACTEMAIL$ to expand

Post by navaho »

Oh, good idea. Let me try that.
navaho
Posts: 12
Joined: Mon Aug 01, 2011 4:43 pm

Re: Unable to get $CONTACTEMAIL$ to expand

Post by navaho »

No Joy. I updated to 3.2.3 by removing the debs, hand building it from source, and dropping my configs in.

I also removed the n in the commands config service_notification_options w,u,c,r,s,n

Still sending email to $@.
Locked