限制Nagios报警次数技巧(Escalations)

运维 系统运维
用Escalations限制Nagios报警次数:Nagios是一款强大的监控工具,特别是他的报警功能,但是如果服务器出现故障未及时解决,那么Nagio就不断得发送消息。该通过怎么样的方式限制Nagios报警次数呢?本文讲述的是限制Nagios报警次数技巧(Escalations)。

巧用escalations限制Nagios报警次数

  Nagios是非常强大的一款监控工具,尤其是它的告警功能,现在网上实现的形式多种多样如结合移动139邮箱、Fetion、MSN等,但是如果服务器出现故障而未能及时的解决,Nagios就会不断的发送告警信息,实在令人头疼。现在用如下方法可以解决Nagios的告警次数问题。

  系统环境:CentOS 5.2

  Nagios版本:3.0.6

  Nagios安装路径:/usr/local/nagios

  配置文件内容定义:#基本的配置就不再进行注释了。

  hosts.cfg  
 
  define host{  
 
  host_name WWW-Server  
 
  alias WWW-Server  
 
  address 193.1.16.100  
 
  check_command check-host-alive  
 
  max_check_attempts 5  
 
  check_period 24x7  
 
  notification_interval 10  
 
  notification_period 24x7  
 
  notification_options d,u,r  
 
  notifications_enabled 1  
 
  contact_groups chengnan  
 
  }  
 
  Services.cfg  
 
  define service{  
 
  host_name WWW-Server  
 
  service_description Check_HTTP  
 
  check_command check_http  
 
  max_check_attempts 10  
 
  normal_check_interval 3  
 
  retry_check_interval 2  
 
  check_period 24x7  
 
  notification_interval 5  
 
  notification_period 24x7  
 
  notification_options w,u,c,r  
 
  contact_groups admin  
 
  }  
 
  define service{  
 
  host_name WWW-Server  
 
  service_description Check_Jetty  
 
  check_command check_tcp!8080  
 
  max_check_attempts 10  
 
  normal_check_interval 3  
 
  retry_check_interval 2  
 
  check_period 24x7  
 
  notification_interval 5  
 
  notification_period 24x7  
 
  notification_options w,u,c,r  
 
  contact_groups admin  
 
  }  
 
  Contacts.cfg  
 
  define contact{  
 
  contact_name chengnan  
 
  alias chengnan  
 
  service_notification_period 24x7  
 
  host_notification_period 24x7  
 
  service_notification_options w,u,c,r  
 
  host_notification_options d,u,r  
 
  service_notification_commands notify-service-by-email  
 
  host_notification_commands notify-host-by-email  
 
  email chengnan@139.com //手机邮箱  
 
  }  
 
  define contactgroup{  
 
  contactgroup_name chengnan  
 
  alias Nagios Administrators  
 
  members chengnan  
 
  }  
 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.

  除此之外再定义一个联系人

  define contact{  
 
  contact_name chengnan_cor  
 
  alias chengnan_cor  
 
  service_notification_period 24x7  
 
  host_notification_period 24x7  
 
  service_notification_options w,u,c,r  
 
  host_notification_options d,u,r  
 
  service_notification_commands notify-service-by-email  
 
  host_notification_commands notify-host-by-email  
 
  email chengnan@company.com //公司邮箱  
 
  }  
 
  define contactgroup{  
 
  contactgroup_name sysadmin  
 
  alias sysadmin  
 
  members chengnan_cor  
 
  }  
 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.

  然后创建一个配置文件:

  vi escalations.cfg  
 
  • 1.
  • 2.

  escalations有自动调整;不断增加; 逐步上升等意思,本身配置文件的功能是当服务在某一告警次数前没有恢复,告警频率周期将会缩短,同时将告警信息发送至指定联系人。

  其内容为:

  define hostescalation{  
 
  host_name WWW-Server //被监控主机名称,与Hosts.cfg中一致  
 
  first_notification 4 // 第n条信息起,改变频率间隔  
 
  last_notification 0 // 第n条信息起,恢复频率间隔  
 
  notification_interval 30 // 通知间隔(分)  
 
  contact_groups sysadmin  
 
  }  
 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

  说明:从第4条告警信息起至服务器恢复前,告警信息发送至sysadmin组下的联系人,告警间隔为30分钟1条信息。

  define serviceescalation{  
 
  host_name WWW-Server //被监控主机名称,与Hosts.cfg中一致  
 
  service_description Check_HTTP,Check_Jetty //被监控服务名称,与Services.cfg中一致  
 
  first_notification 4  
 
  last_notification 0  
 
  notification_interval 30  
 
  contact_groups sysadmin  
 
  }  
 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.

  保存

  修改nagios.cfg

  vi nagios.cfg  
 
  • 1.
  • 2.

  添加:

  cfg_file=/usr/local/nagios/etc/objects/escalations.cfg  
 
  • 1.
  • 2.

  检查nagios配置文件是否正确

 

  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg  
 
  • 1.
  • 2.

  重新启动nagios服务:

  service nagios restart  
 
  • 1.
  • 2.

  测试

  服务器启动后停掉被监控测试机的相应服务,确认告警信息是否按照设置发送至不同信箱

  总结

  escalations这个功能官方给的定义是notification的扩充,使notification变得更加灵活,方便。文中我使用的方法算是耍了个小聪明,将第四条告警信息后的所有信息全部发送至我公司邮箱直至服务器恢复(recovery的信息还是会发送至手机的),从而实现限制告警信息发送至手机的条数。这样,用Escalations限制Nagios报警次数的功能就成功实现了。

【编辑推荐】
责任编辑:zhaolei 来源: javaeye
相关推荐

2011-03-24 08:56:23

escalationsNagios报警

2011-03-25 14:56:43

Nagiosescalations

2011-03-23 13:32:14

Nagios飞信

2011-03-25 13:10:08

2011-03-24 08:56:21

Nagios邮件

2011-04-01 10:53:43

2013-06-08 16:55:22

Nagios

2011-03-22 16:31:27

Nagios

2011-03-23 09:07:49

Nagios飞信

2011-03-22 14:58:08

Nagios

2011-03-24 10:08:42

Nagios飞信Linux

2011-03-23 12:55:51

NagiosMSN飞信

2011-03-24 13:00:31

Nagios飞信

2011-03-23 09:07:50

Nagios短信

2011-03-25 15:56:58

2010-11-09 10:03:26

2018-12-04 09:02:14

正则表达式回溯WEB安全

2011-04-06 14:24:18

2011-08-22 12:24:56

nagios

2011-08-02 14:39:59

windowsXP系统限制孩子上网
点赞
收藏

51CTO技术栈公众号