534242 发表于 2016-7-5 09:11:57

nagios 配置邮件告警

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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

1
# vim /etc/nagios/conf.d/192.168.56.128.cfg




      针对check_load服务增加告警配置

1
2
3
4
5
6
7
8
9
10
11
12
define service{
   use            generic-service
   host_name      192.168.56.128
   service_descriptioncheck_load
   check_command    check_nrpe!check_load
   max_check_attempts   5
   normal_check_interval   1
   contact_groups   common
   notifications_enabled1
   notification_period   24x7
   notification_optionsw,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服务

1
2
3
4
# service nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.





页: [1]
查看完整版本: nagios 配置邮件告警