如何在postfix中为电子邮件地址指定一个特定的名称。

时间:2017-03-24 06:04:07

标签: open-source monitoring nagios postfix

我在我的系统上安装了Nagios核心,如果某些服务进入严重/警告阶段,我会向我发送电子邮件。一切都很好。 我已经配置了post-fix以发送电子邮件并在&#34; sasl_passwd&#34;中配置了一个电子邮件地址。提交类似这样的内容&#34; [smtp.gmail.com]:587 <email-id>:<password>&#34;。 当我收到有关服务阶段的邮件时,它来自<email-id>&#34;来自<email-id>&#34;现在我想改变我想要一封电子邮件来#34; Nagios提醒&#34;或者像邮件主题那样的东西,而不仅仅是account。 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

更改您的命令notify-host-by-emailnotify-service-by-email。这些命令是发送电子邮件通知的内容。它默认将消息字符串传递给/bin/mail。它已包含指示主题的-s标志。因此,为了覆盖发件人,我们会检查man mail并确定该标志为-r [from-addr]。因此,您可以从以下位置更改命令:

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

要:

# '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" | /bin/mail -r "someemail@somewhere.com" -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$\n" | /bin/mail -r "someemail@somewhere.com" -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
    }

someemail@somewhere.com 是您的电子邮件地址。

希望这有帮助。