LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Nagios email notification sendmail fails - extra $ is added (https://www.linuxquestions.org/questions/linux-software-2/nagios-email-notification-sendmail-fails-extra-%24-is-added-856293/)

claushoyer 01-14-2011 08:10 AM

Nagios email notification sendmail fails - extra $ is added
 
I have a setup with Centos 5.5, Nagios 3.2.3, sendmail 8.13.8. When a insident is happening Nagios notify-by-mail is triggered and Nagios sends via sendmail. Unfortunately there is a trailing $-sign added to the $CONTACTEMAIL. Sendmail cannot mail to xxx@mail.address$
A hack is to insert mailaddress in misccommands.cfg but I would like to have a more clean way.
Looking forward for a solution :-) - Thanks

MensaWater 01-14-2011 10:52 AM

What exactly is in your host-by-mail command definition? I use host-by-email in misccommands.cfg and don't have a problem with a trailing $ and send tons of email via sendmail from Nagios.

Note that Nagios variables use $VAR$ rather than shell variable format $VAR. The Nagios variable you need is $CONTACTEMAIL$ and NOT simply $CONTACTEMAIL.

My notify-by-email definition is:

Code:

define command{
      command_name    notify-by-email
      command_line    /usr/bin/printf "%b" "Nagios"\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/mail -s "EMA $NOTIFICATIONTYPE$ ALERT! - $HOSTALIAS$ $SERVICEDESC$ is $SERVICESTATE$" $CONTACTEMAIL$
      }


claushoyer 01-18-2011 05:54 AM

Here's a copy of notify-by-mail from misccommands.cfg:

# 'notify-by-email' command definition
define command{
command_name notify-by-email
command_line /bin/echo -e "***** Nagios *****\n\nNotification Type: $NAGIOS_NOTIFICATIONTYPE\n\nService: $NAGIOS_SERVICEDESC\nHost: $NAGIOS_HOSTALIAS\nAddress: $NAGIOS_HOSTADDRESS\nState: $NAGIOS_SERVICESTATE\n\nDate/Time: $DATE$ $TIME$\n\nAdditional Info:\n\n$NAGIOS_HOSTOUTPUT " | /bin/mail -s $NAGIOS_CONTACTEMAIL
}

I also tried a notify-by-mail like this:
# 'notify-by-email' command definition
define command{
command_name notify-by-email
command_line /bin/echo -e "***** Nagios *****\n\nNotification Type: $NAGIOS_NOTIFICATIONTYPE$\n\nService: $NAGIOS_SERVICEDESC$\nHost: $NAGIOS_HOSTALIAS$\nAddress: $NAGIOS_HOSTADDRESS$\nState: $NAGIOS_SERVICESTATE$\n\nDate/Time: $DATE$ $TIME$\n\nAdditional Info:\n\n$NAGIOS_HOSTOUTPUT$ " | /bin/mail -s $NAGIOS_CONTACTEMAIL$
}

And like this:
# 'notify-by-email' command definition
define command{
command_name notify-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NAGIOS_NOTIFICATIONTYPE$\n\nService: $NAGIOS_SERVICEDESC$\nHost: $NAGIOS_HOSTALIAS$\nAddress: $NAGIOS_HOSTADDRESS$\nState: $NAGIOS_SERVICESTATE$\n\nDate/Time: $DATE$ $TIME$\n\nAdditional Info:\n\n$NAGIOS_HOSTOUTPUT$ " | /bin/mail -s $NAGIOS_CONTACTEMAIL$
}

but I get this kind of records in maillog: (having x-ed out real mailaddress). Look at the to=XXXX@xxxxxx.yyy chich gets a tailing $ sign.

Jan 17 13:57:59 nagios-2 sendmail[26558]: p0HCvxJw026558: from=nagios, size=256, class=0, nrcpts=1, msgid=<201101171257.p0HCvxJw026558@xxxxxx.yyy>, relay=nagios@localhost
Jan 17 13:58:00 nagios-2 sendmail[26558]: p0HCvxJw026558: to=XXX@xxxxxx.yyy$, ctladdr=nagios (500/500), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=30256, relay=mail01.xxxxxx.yyy. [192.168.119.20], dsn=2.0.0, stat=Sent (p0HCw0R1009730 Message accepted for delivery)

Mailing from commandline is succesfull. Sendmail delivers correctly. I'm still confused.

Refering to the above, the first notify-by-mail command is the command which works best. Try to look at this mail which is generated by the 2nd notify-by-mail described above.

***** Nagios *****
Notification Type: RECOVERY$
Service: NTP$
Host: asic204$
Address: asic204$
State: OK$
Date/Time: 18-01-2011 13:46:40
Additional Info:
PING OK - Packet loss = 0%, RTA = 2.02 ms$

I get tailing $ on every Nagios macro!!

OdinnBurkni 04-14-2011 06:16 AM

Nagios emailing
 
I have the same setup as MensaWater and my emailing works. Only problem I am facing is that I want to send email to another ISP and they stop it because of the ctladdr. I haven't figured out how to change that to something else than the machine's name.
Like Mensawater pointed out, you have to have $var$. But from what you have shown us you have a different variable name then the standard Nagios does. What is the reason for that?


All times are GMT -5. The time now is 03:22 AM.