Patrik18
Patrik18

Reputation: 329

Sending email notifications from Nagios / Postfix

I would like to ask, is there some possibility to sending emails from nagios via postfix?

1, I have setup nagios to check some services, also I have installed postfix.

2, I have valid email account, i.e.: [email protected]

3, just send email from this account

Thank you!

Patrick

Upvotes: 1

Views: 15730

Answers (2)

Here is a one possible solution for Ubuntu.

Make sure bsd-mailx and postfix are installed:

sudo apt-get install postfix bsd-mailx

Postfix should be configured as a satellite system, which means /etc/postfix/main.cf should contain:

relayhost = your_smtp_relay_address

And then you need to change your Nagios notification commands by adding "from" address:

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

# '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$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        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$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ -- $USER5$
        }

Where $USER5$ is defined in /etc/nagios3/resource.cfg and contains something like:

$USER5$="-f [email protected]"

Upvotes: 1

Bruno9779
Bruno9779

Reputation: 1669

Yes, it is possible. Depending by what version/fork of Nagios you use the configuration will differ.

We use Icinga (nagios fork) and I could link you to the exact page in the documentation. I am not familiar with nagios documentation, but something on these lines should do: http://community.spiceworks.com/topic/144821-nagios-e-mail-alerts-with-postfix.

Upvotes: 0

Related Questions