Getting email notifications to work!

Hello all

I’m in the process of setting up Nagios 3 on CentOS and so far all has gone really well. However, I’ve now run into a problem where I just can’t get my head around email notifications.

Basically, I’m at a loss as to what the best way to set this up is. I notice that sendmail is installed by default but I can’t get to grips with using this at all.
I’ve also seen posts where people have used mailx, which I have also tried, but just can’t get anything to work (and I don’t know if mailx and sendmail are actually the same thing or not).

We just have one Nagios server that we need to send email alerts internally to the tech team, and we have an exchange server, so it’s not a complex setup. I’ve had a good look for documentation but there’s precious little in the way of idiots guides on this (that I can see).

Any help or info or some basic steps to get this working would be really appreciated.

Cheers

Neil

Hi,
Did you enable email options and give your email id to which emails are to be send in your nagios configuration file and in contacts.cfg file

I think you did not do that. Check that once

Regards,
512

Since you are sending your alerts to a exchange server internally you may have to setup sendmail for Smart Relay.

Edit the /etc/sendmail.cf

Search for # “smart” relay host (may be null)
DS

After the DS enter in your exchange server name.

DSexhangeserver.domain.com

Then restart sendmail

service sendmail restart

You will have to configure your exchange server to accepted relaying from your nagios box as well. I don’t run Exchange so I have no idea on how that is done.

Regards,

Hello, I am in much the same boat as neild. We have an exchange server and another server running Ubuntu 8.10 server edition with Nagios 3. I don’t want to use the exchange server to send out the notifications as monitoring the exchange server is largely the reason why we are using Nagios in the first place.

I’ve followed the Ubuntu quick start and nagios is working just fine, just not the email notification part.

I’ve installed mailx per quick start guides and changed /usr/local/nagios/etc/objects/commands.cfg ‘/bin/mail’ references to ‘/usr/bin/mail’.

What else do I need to do?

my commands.cfg reads:

‘notify-host-by-email’ command definitiondefine command{ command_name notify-host-by-email command_line /usr/bin/printf “%b” "***** Nagios *****\n\nNotification

Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTA
DDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | usr/bin/mail -s "*

  • $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
    }

‘notify-service-by-email’ command definitiondefine 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/bin/mail -s “** $NOTIFICATIONTYPE$ Service Aler
t: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
}

Nathan, you need to configure postfix and make sure you can send mail via terminal before troubleshooting/configuring the commands.cfg. For Ubuntu, your commands looks fine, make sure you have templates.cfg, contacts.cfg and command.cfg correctly configured. I also like to edit the nagios.cfg and change the $adminemail$ to my own and replace $contactemail$ with it.

[blockquote]I’ve installed mailx per quick start guides and changed /usr/local/nagios/etc/objects/commands.cfg ‘/bin/mail’ references to ‘/usr/bin/mail’.[/blockquote] No you didn’t… look…

[blockquote]my commands.cfg reads:

‘notify-host-by-email’ command definitiondefine command{ command_name notify-host-by-email command_line /usr/bin/printf “%b” "***** Nagios *****\n\nNotification

Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTA
DDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | **usr/bin/mail *-s "

  • $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
    }

‘notify-service-by-email’ command definitiondefine 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/bin/mail -s " $NOTIFICATIONTYPE$ Service Aler
t: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}[/blockquote]

usr/bin/mail is not the same as /usr/bin/mail

Thanks Strides. I made the specified changes and restarted Nagios. Anyother ideas? Commands.cfg now reads:

‘notify-host-by-email’ command definitiondefine 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/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$        }

‘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/bin/mail -s "
$NOTIFICATIONTYPE$ Service Ale
rt: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
}

As mentioned before no other changes have been made to the server other then those specified in the quickstart guide. I feel like I am missing a step somewhere.

Hello

Sorry first of all for posting this then not replying to the comments that people have put. I actually managed to get this working in the end, so will update the thread with what I found.

Basically, what worked for me in the end was changing the /usr/bin/mail -s option to just mail -s and this worked. I did have it working with sendmail at the end first off, but this wasn’t entering any text in the subject or body of the alerts, so wasn’t a great solution (I’m not sure if that was me getting it wrong or just sendmail not being able to).

Hope this helps others get this sorted.

Cheers

Neil