nagios配置邮件报警

Posted 巫谢

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nagios配置邮件报警相关的知识,希望对你有一定的参考价值。

1、配置sendmail

  vi /etc/mail.rc

  加入以下行

  set bsdcompat

  set from=邮件用户名@domain.com smtp=smtp.126.com set smtp-auth-user=邮件用户名 smtp-auth-password=邮箱密码 set smtp-auth=login

2、检查commands.cfg

  

################################################################################
#
# SAMPLE NOTIFICATION COMMANDS
#
# These are some example notification commands.  They may or may not work on
# your system without modification.  As an example, some systems will require 
# you to use "/usr/bin/mailx" instead of "/usr/bin/mail" in the commands below.
#
################################################################################


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

这是正确的命令配置,其中最重要的就是/bin/mail后边的命令配置

3、mqueue

ls /var/spool/mqueue

这个目录存储的是邮件发送队列,

如果这个里边满了不但会影响程序的运行,而且sendmail容易死掉,所以必要的时候要删除。
4、修改联系人地址
vi /usr/local/nagios/etc/objects/contacts.cfg
修改[email protected]为联系人的地址
5、检查所传送的电子邮件是否送出,或滞留在邮件服务器中
/usr/lib/sendmail -bp

若屏幕显示为“Mail queue is empty” 的信息,表示mail 已送出。

6、发送测试邮件

  mail -s "test" [email protected] <content.txt

  content.txt为邮件内容

以上是关于nagios配置邮件报警的主要内容,如果未能解决你的问题,请参考以下文章

Nagios邮件报警系统详细配置

nagios钉钉报警与邮件报警

nagios通过邮件发送报警

nagios安装配置报警监控搭建

nagios 监控

Nagios部署与配置