Page 2 of 3

Re: Unable to get $CONTACTEMAIL$ to expand

Posted: Wed Aug 03, 2011 9:59 am
by agriffin
navaho wrote:No Joy. I updated to 3.2.3 by removing the debs, hand building it from source, and dropping my configs in.
Did you update nagios.cfg to point to the new locations of your object files?

Re: Unable to get $CONTACTEMAIL$ to expand

Posted: Wed Aug 03, 2011 11:31 am
by navaho
Good morning!

Yes, I did. I'm pretty darn sure I have everything configured properly. Everything works, it just doesn't send email.

I set debug to -1 and found that it's telling me that the macro is failing. I'll grab a capture of that log in just a bit. Seems it rotated out over the night.

Someone suggested to try with on-demand macro $CONTACTEMAIL:navaho$ to see if it works which I will.

Re: Unable to get $CONTACTEMAIL$ to expand

Posted: Wed Aug 03, 2011 12:18 pm
by navaho
I turned on debugging with the original contact command

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$" "$CONTACTEMAIL$"
And this is what I got in the debug log. I've snipped it simply for brevity, I can paste the entirely of it if there is more that you would like to see.

Code: Select all

[1312391403.159137] [2048.2] [pid=4104]   Not currently in macro.  Running output (213): '/usr/bin/printf "%b" "Notification:\t\n\nOccurred:\t$DATETIME$\nHostname:\thostname (10.5.4.1)\nService:\tmy service\nState:\t\tCRITICAL\nDetails:\n\n $OUTPUT$" | /usr/bin/mail -s ": hostname/my service -- CRITICAL" "'
[1312391403.159152] [2048.2] [pid=4104]   Processing part: 'CONTACTEMAIL'
[1312391403.159168] [2048.2] [pid=4104]   macro_x[22] (CONTACTEMAIL) match.
[1312391403.159182] [2048.2] [pid=4104]   Processed 'CONTACTEMAIL', Clean Options: 0, Free: 1
[1312391403.159196] [2048.0] [pid=4104]  WARNING: An error occurred processing macro 'CONTACTEMAIL'!
I'm going to try running it again with $CONTACTEMAIL:navaho$ and see what that does.

Re: Unable to get $CONTACTEMAIL$ to expand

Posted: Wed Aug 03, 2011 12:36 pm
by navaho
I FOUND IT!

using the macro like this

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$" '$CONTACTEMAIL:navaho$'
Sent email to navaho@nagios server hostname not to the email address listed for navaho in contacts.cfg. That got me to thinking some more and i looked at the debug a little but more. That's where I saw the problem.

I changed $CONTACTEMAIL$ to "$CONTACTEMAIL$" and no go, but then I tried '$CONATACTEMAIL$' and it worked..

I still have to fix up $DATETIME$ as that's coming blank in the email as is $OUTPUT$ but that'll be easy. the hard part was making the email send at all.

Thanks for the sounding board!

Re: Unable to get $CONTACTEMAIL$ to expand

Posted: Wed Aug 03, 2011 12:45 pm
by agriffin
Glad to hear it was resolved, although the solution still doesn't make a whole lot of sense to me.

Re: Unable to get $CONTACTEMAIL$ to expand

Posted: Wed Aug 03, 2011 12:49 pm
by navaho
Same here. I'm looking over the original again, and I don't see any quotes that are escaped. That would do I think, but I don't see one.

Re: Unable to get $CONTACTEMAIL$ to expand

Posted: Wed Aug 03, 2011 4:46 pm
by navaho
What if one of the macros previous to $CONTACTEMAIL$ had unescaped HTML? (which for this service they do) Quotes in there would cause this, wouldn't they?

Re: Unable to get $CONTACTEMAIL$ to expand

Posted: Thu Aug 04, 2011 12:47 pm
by navaho
Just a followup, that was exactly what the issue was. In the mail command was

Details:\n\ n$OUTPUT$"

$OUTPUT$ has html in it. With /usr/bin/printf %b and a field that has html (including "'s) we were getting extra quotes and breaking the mail command.

We were ending up with this

/usr/bin/printf "%b" "Notification:\tPROBLEM: hostname/servicename -- CRITICAL\n\nOccurred:\tWed Aug 3 19:05:51 PDT 2011\nHostname:\tmy hostname (10.5.4.1)\nService:\tService description\nState:\t\tDOWN\nDetails:\n\n<a href="serviceurl.com">service url</a> | /usr/bin/mail -s "PROBLEM: myhostname/my service -- DOWN" [email protected]

It appears that quotes in the serviceurl link were breaking things. Using %s sort fo fixed the problem in that it fixed the quotes in $OUTPUT$ but of course broke the \t and \n that I was using, of course. I had to fix up my formatting, but I'm getting the email now. It's not optimal, but it works.

Re: Unable to get $CONTACTEMAIL$ to expand

Posted: Thu Aug 04, 2011 12:49 pm
by agriffin
Good to know, thanks!

Re: Unable to get $CONTACTEMAIL$ to expand

Posted: Wed Sep 14, 2011 4:29 am
by colintaylor
I had exactly this - and the problem was that I had my event handler(s) for hosts and services set to "notify_host_by_email" or "notify_service_by_email". The $CONTACTEMAIL$ macro is not available in the event handler parameters.

Hope that helps! (took me *weeks* to find that!)