码迷,mamicode.com
首页 > 移动开发 > 详细

nagios配置邮件报警

时间:2016-05-18 17:26:19      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

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
修改nagios@localhost为联系人的地址
5、检查所传送的电子邮件是否送出,或滞留在邮件服务器中
/usr/lib/sendmail -bp

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

6、发送测试邮件

  mail -s "test" luoyelin1989@126.com <content.txt

  content.txt为邮件内容

nagios配置邮件报警

标签:

原文地址:http://www.cnblogs.com/wuxie1989/p/5505766.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!