我在CentOS 6.3 Final上configuration了Nagios 3.4.4。 我还configuration了Postfix与SMTP电子邮件服务器。 我已经从控制台validation,我可以发送电子邮件通知,并收到指定的地址。
Nagios被configuration为通过电子邮件发送通知主机和通过电子邮件通知服务。 我可以从Nagios日志中看到从Nagios发送的服务通知警报和客户通知。 但是/ vag / log / maillog没有看到任何东西。 也没有错误。
我甚至从控制台的下面的命令中解雇了'command_line',他们能够发送邮件到上面提到的地址。
Commands.cfg
# '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" | sudo /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" | sudo /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$ }
Contact.cfg
define contact{ contact_name manish service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r,f host_notification_options d,u,r,f service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email email [email protected] } define contactgroup { contactgroup_name email alias Email Group members manish }
Nagios组
cat /etc/group |grep nagios nagios:x:502:nagios,apache nagcmd:x:503:nagios,apache
您需要在主机/服务定义中configuration联系人或联系人组。 我通常创build一个模板主机和服务,然后重写使用inheritance。
http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html#host http://nagios.sourceforge.net/docs/3_0/objectdefinitions.html#service http://nagios.sourceforge.net/docs/ 3_0 / objectinheritance.html
在contacts.cfg文件中,
定义联系人{
contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values alias Nagios Admin ; Full name of user email [email protected] }
在nagios.cfg中
ADMIN_EMAIL = nagios的@本地
(要么)
您可以检查url: http : //www.thegeekstuff.com/2009/06/4-steps-to-define-nagios-contacts-with-email-and-pager-notification/
所有的configuration都是正确的,在Nagios或Postfix端没有发现错误。 事实certificate,Nagios无法触发“邮件”命令实际发送电子邮件通知。 我改变命令的行为来运行一个.php草拟一个HTML电子邮件模板,然后使用'mail'命令发送邮件.php。 这种方法适用于上述情况。 如果有人遇到类似的问题,请使用http://exchange.nagios.org/directory/Addons/Notifications/Send-HTML-Alert-Email-v2/details指南。