从Nagios / Postfix发送电子邮件通知

时间:2022-10-23 18:55:29

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

我想问一下,是否有可能通过postfix从nagios发送电子邮件?

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

1,我已经设置了nagios来检查一些服务,我也安装了postfix。

2, I have valid email account, i.e.: patrick@mydomain.com

2,我有有效的电子邮件帐户,即:patrick@mydomain.com

3, just send email from this account

3,只需从此帐户发送电子邮件

Thank you!

Patrick

2 个解决方案

#1


0  

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

对的,这是可能的。根据您使用的Nagios版本/分支,配置会有所不同。

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.

我们使用Icinga(nagios fork),我可以将您链接到文档中的确切页面。我不熟悉nagios文档,但这些内容应该是:http://community.spiceworks.com/topic/144821-nagios-e-mail-alerts-with-postfix。

#2


0  

Here is a one possible solution for Ubuntu.

这是Ubuntu的一种可能的解决方案。

Make sure bsd-mailx and postfix are installed:

确保安装了bsd-mailx和postfix:

sudo apt-get install postfix bsd-mailx

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

Postfix应配置为卫星系统,这意味着/etc/postfix/main.cf应包含:

relayhost = your_smtp_relay_address

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

然后,您需要通过添加“from”地址来更改Nagios通知命令:

# '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 $在/etc/nagios3/resource.cfg中定义并包含如下内容:

$USER5$="-f nagios.notifications@company.lan"

#1


0  

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

对的,这是可能的。根据您使用的Nagios版本/分支,配置会有所不同。

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.

我们使用Icinga(nagios fork),我可以将您链接到文档中的确切页面。我不熟悉nagios文档,但这些内容应该是:http://community.spiceworks.com/topic/144821-nagios-e-mail-alerts-with-postfix。

#2


0  

Here is a one possible solution for Ubuntu.

这是Ubuntu的一种可能的解决方案。

Make sure bsd-mailx and postfix are installed:

确保安装了bsd-mailx和postfix:

sudo apt-get install postfix bsd-mailx

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

Postfix应配置为卫星系统,这意味着/etc/postfix/main.cf应包含:

relayhost = your_smtp_relay_address

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

然后,您需要通过添加“from”地址来更改Nagios通知命令:

# '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 $在/etc/nagios3/resource.cfg中定义并包含如下内容:

$USER5$="-f nagios.notifications@company.lan"