EMail notification problem

I have set up nagios nagios-1.3-14.fc4 in my FC4 server, the only problem now is the email notification can’t be send out.
The original notify-by-email in misccommands.cfg is like below:

‘notify-by-email’ command definition

define command{
command_name notify-by-email
command_line /usr/bin/printf “%b” “***** Nagios ***\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVIC
EDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $DATETIME$\n\nAdditional Info:\n
n$OUTPUT$" | -s "
$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
}
I changed it to :

‘notify-by-email’ command definition

define command{
command_name notify-by-email
command_line /bin/mail “%b” “***** Nagios ***\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVIC
EDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $DATETIME$\n\nAdditional Info:\n
n$OUTPUT$" | -s "
$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
}
Basically I replaced /usr/bin/printf with /bin/mail. I am sure that /bin/mail is in the system.
in the /var/log/messages log I see the following error:

Warning: Attempting to execute the command “/bin/mail “%b” “***** Nagios *****\n\nNotification Type: RECOVERY\nHost: Server-1\nState: UP\nAddress: 10.100.1.79\nInfo: PING OK - Packet loss = 0%, RTA = 0.76 ms\n\nDate/Time: Thu Jan 26 17:48:21 EST 2006\n” | -s “Host UP alert for Server-OTM!” [email protected]” resulted in a return code of 127. Make sure the script or binary you are trying to execute actually exists…

Any kind help is highly appreciated!!

which mail
will tell you where the mail command is located.
Also, try your command by hand first and see if it works.
If you are going to modify something like that, you need to make sure it actually works. I ran your command and that is what you get.
“bash: -s: command not found”

What was wrong with the format of the original?

I’m pretty sure that that first command is not the “original” command installed by default, as it doesn’t actually pipe the result of the printf command to the mail command (that, I believe, is how the default notification command works out in Nagios). Maybe you forgot to put that in your post?

The issue with your modified command is that you’re trying to pipe the result of the mail command to -s, which is the subject option for mail. It’s not a command at all, and I believe that is why you’re getting the 127 return code.

Yes, I saw that, but the point of my reply was “test your command first” by hand to see that it actually works, before you implement it in nagios. If he had, he would have immediatly seen that -s is not a valid command.
Edited Thu Jan 26 2006, 11:35PM ]

Yup…that’s me not reading all of your post. Sorry about that. Seems to be a problem with me. :roll:

The notification commands as delivered in the FC4 nagios rpm are hosed; there’s nothing preceding the “-s” switch. marsnagios, make it look like this. (Note the placement of the “/bin/mail” command.)

‘notify-by-email’ command definition

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$" | /bin/mail -s " $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
}

Gee, now you spoiled the effort we made to attempt to get him to look at the command more closely. But hey, I’m sure he is thankful. :slight_smile: Surely he would notice that he was piping to a command called "-s"
i.e. | -s ** $NOTIFICATIONTYPE$ alert