Mail notification problem

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.
Also
Posts: 10
Joined: Thu Jun 02, 2016 12:59 pm

Re: Mail notification problem

Post by Also »

Yes, you are right!
Nagios doesn't have permission to write in the sendEmail log and notification was disabled!

I change the log permission and now in the log is full of:

Code: Select all

Jun 23 17:10:18 raspberrypi sendEmail[23709]: ERROR => Can't use improperly formatted email address: $
Jun 23 17:15:35 raspberrypi sendEmail[23956]: ERROR => Can't use improperly formatted email address: $
Jun 23 17:20:19 raspberrypi sendEmail[24150]: ERROR => Can't use improperly formatted email address: $
Jun 23 17:25:36 raspberrypi sendEmail[24429]: ERROR => Can't use improperly formatted email address: $
Furthermore if I try:
runuser -l nagios -c "sendEmail -f mymail -t anothermail -u test -m text -s smtp -xu mymail -xp 123456789 -v -o tls=no"
I get no result, the mail doesn't arrive, and in the log there is nothing new..
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Mail notification problem

Post by rkennedy »

Based on that log file, there is probably a syntax error in what you're passing to sendEmail. Take a look at your command definitions and verify them. It might be worth having it echo all of the data, so that you can see what exactly is getting passed and how it's handling it.

Code: Select all

define command {
        command_name notify-host-by-email
        command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -s $USER7$ -xu $USER9$ -xp $USER10$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n"
}

# 'notify-service-by-email' command definition
define command {
        command_name notify-service-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/local/bin/sendEmail -s $USER7$ -xu $USER9$ -xp $USER10$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$"
}
Furthermore if I try:
runuser -l nagios -c "sendEmail -f mymail -t anothermail -u test -m text -s smtp -xu mymail -xp 123456789 -v -o tls=no"
I get no result, the mail doesn't arrive, and in the log there is nothing new..
This is odd, but it works when running as the root user? You may need the -l parameter to specify the log file similar to above to see what's going on. -l /var/log/sendEmail
Former Nagios Employee
Also
Posts: 10
Joined: Thu Jun 02, 2016 12:59 pm

Re: Mail notification problem

Post by Also »

I'm so sorry for the late of the answer but I have had some problems!
I solved the problem removing the parameter $USER$ and putting direct the mail and smtp in command.cfg.

This is not wonderful but works!

Many thanks for your help, this topic con be closed!
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Mail notification problem

Post by rkennedy »

Awesome! Thanks for letting us know the solution.

You might be able to use single quotes around the '$USER#$' variable to have them parse properly.

Locking this up, feel free to create a new thread if you have any questions in the future!
Former Nagios Employee
Locked