2.3 nagios 配置邮件告警

2017-06-12

nagios 配置邮件告警

目前 nagios 只能在浏览器上查看各个机器各个服务的状态,当某个机器宕掉或者某个服务宕掉时,我们是不知道的,因为我们不可能时时盯着服务看。这时,就需要用到告警系统了,让它自动化,当发现问题时及时通知我们。下面配置使用发邮件的方式来实现告警。

在服务端操作!

首先定义邮件接受者。

[root@localhost ~]# vim /etc/nagios/objects/contacts.cfg
define contact{
        contact_name                    test1
        use                             generic-contact
        alias                           email1
        email                           test1@163.com
}
define contact{
        contact_name                    test2
        use                             generic-contact
        alias                           email2
        email                           test2@163.com
}
define contactgroup{
        contactgroup_name               common
        alias                           common
        members                         test1,test2
}

说明:contact.cfg 里面既可以定义 user 也可以定义 group,先定义两个 user test1 和 test2,然后把这两个 user 加入到 common 组里面。发邮件时就发给 common 组就可以了,这时 test1@163.com 和 test2@163.com 都会收到邮件。

然后在需要告警的服务里加上 contactgroup

[root@localhost ~]# vim /etc/nagios/conf.d/192.168.56.128.cfg

针对 check_load 服务增加告警配置

define service{
   use            generic-service
   host_name      192.168.56.128
   service_description  check_load
   check_command    check_nrpe!check_load
   max_check_attempts   5
   normal_check_interval   1
   contact_groups   common
   notifications_enabled  1
   notification_period   24x7
   notification_options  w,u,c,r
}

说明:notifications_enabled 1 表示是否开启提醒功能。1 为开启,0 为禁用。一般,这个选项会在主配置文件(nagios.cfg)中定义,效果相同。notification_period 24x7 表示发送提醒的时间段。如果不在定义的时间段内,无论什么问题都不会发送提醒。notification_options:w,u,c,r 表示 service 的状态。w 为 warning,u 为 unknown,c 为 critical,r 为 recovery。类似的还有一个 host 对应的状态:d,u,r,f,n。 d 状态表示 DOWN,u 为 UNREACHABLE,r 状态恢复为 OK,f 为 flapping,n 为不发送提醒。需要加入到 host 的定义配置里生效。

编辑完配置文件后,重启 nagios 服务

[root@localhost ~]# service nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.

标题:2.3 nagios 配置邮件告警
作者:散宜生
地址:https://17kblog.com/articles/2017/06/12/1497263292876.html