注:本文由本人最早发布在 http://roland.blog.51cto.com/(Roland技术窝~~),现逐步将原 http://roland.blog.51cto.com/(Roland技术窝~~) 所有文章迁移至此博客,请勿修改“创作类型”!致谢!

Nagios是一款功能强大,扩展性高的优秀监控系统。

Nagios在报警信息发送的定义中有联系人及联系人组的相关概念,下面要介绍的是如何实现不同时间发送报警给不同联系人的方法。

在下面的相关配置中需要了解联系人定义(contact),时间周期定义(timeperiod),及如何使其相关联的方法。

I -- 首先看一个标准的联系人定义格式:

 
  
  1. define contact{ 
  2.         contact_name         tester 
  3.         alias                 tester for Roland 
  4.         host_notifications_enabled        1 
  5.         service_notifications_enabled     1 
  6.         service_notification_period    24x7 //这是定义服务报警周期 
  7. host_notification_period   24x7 //这是定义主机报警周期 
  8. service_notification_options    w,u,c,r 
  9. host_notification_options     d,u,r 
  10. service_notification_commands   notify-by-email 
  11. host_notification_commands        host-notify-by-email 
  12. email                      Roland@localhost.localdomain 
  13. can_submit_commands              1 

II -- 接下来看两个时间周期定义格式:在上面的例子里,主机、服务报警周期都定义为24x7,即随时发送报警,这也是nagios的默认设置。

 
  
  1. define timeperiod{ 
  2. timeperiod_name work-hours 
  3. alias Work Hours send mail 
  4. monday             09:00-18:00 
  5. tuesday             09:00-18:00 
  6. wednesday         09:00-18:00 //周一到周五每天9点到18点 
  7. thursday        09:00-18:00 
  8. friday    09:00-18:00 
  9.   
  10. define timeperiod{ 
  11. timeperiod_name misc-single-days 
  12. alias               Misc Single Days send mail 
  13. 2008-08-08             00:00-24:00 //2008年8月8日全天 
  14. monday 1         00:00-24:00 //每月的第三个星期一 
  15. day 2              00:00-24:00 //每月的第二天 
  16. february 10      00:00-24:00 //每年二月的第10天 
  17. february -1            00:00-24:00 //每年二月的最后一天 
  18. friday -2           00:00-24:00 //每月的倒数第二个星期五 
  19. thursday -1 november  00:00-24:00 //每年十一月的最后一个星期四 

上面的例子总定义了两种风格的时间周期。

第一个例子,定义周一到周五每天的9点到18点为发送email的时间;

第二个例子,定义了一些特殊的时间段,在这些指定的时间段里都要发送email

III -- 上面已经有了标准的联系人定义和一些时间周期定义,那么下面的就是将联系和时间周期定义关联的方法

 
  
  1. define contact{ 
  2. contact_name tester01 
  3. alias                              tester01 for Work Hours send 
  4. mailhost_notifications_enabled       1 
  5. service_notifications_enabled        1 
  6. service_notification_period      work-hours //关联时间周期定义 
  7. host_notification_period            work-hours //关联时间周期定义 
  8. service_notification_options        w,u,c,r 
  9. host_notification_options           d,u,r 
  10. service_notification_commands       notify-by-email 
  11. host_notification_commands          host-notify-by-email 
  12. email                             Roland@localhost.localdomain 
  13. can_submit_commands                1 
  14.   
  15. define contact{ 
  16. contact_name           tester02 
  17. alias                             tester01 for misc-single-days send mail 
  18. host_notifications_enabled           1 
  19. service_notifications_enabled      1 
  20. service_notification_period       misc-single-days //关联时间周期定义 
  21. host_notification_period          misc-single-days //关联时间周期定义 
  22. service_notification_options       w,u,c,r 
  23. host_notification_options         d,u,r 
  24. service_notification_commands        notify-by-email 
  25. host_notification_commands           host-notify-by-email 
  26. email                              Roland@localhost.localdomain 
  27. can_submit_commands                  1 

通过上面的联系人定义方法就既可非常方便的将不同时间周期定义应用到不同的联系人中。以上所述只是nagios联系人定义和时间周期定义的简单应用,更深层的配置方法和应用案例欢迎大家与我探讨。

-- -- 上述文字描述、配置、方法、案例等如有不妥之处请读者诸君予以纠正 -- --