注:本文由本人最早发布在 http://roland.blog.51cto.com/(Roland技术窝~~),现逐步将原 http://roland.blog.51cto.com/(Roland技术窝~~) 所有文章迁移至此博客,请勿修改“创作类型”!致谢!
Nagios是一款功能强大,扩展性高的优秀监控系统。
Nagios在报警信息发送的定义中有联系人及联系人组的相关概念,下面要介绍的是如何实现不同时间发送报警给不同联系人的方法。
在下面的相关配置中需要了解联系人定义(contact),时间周期定义(timeperiod),及如何使其相关联的方法。
I -- 首先看一个标准的联系人定义格式:
- define contact{
- contact_name tester
- alias tester for Roland
- host_notifications_enabled 1
- service_notifications_enabled 1
- 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-by-email
- host_notification_commands host-notify-by-email
- email Roland@localhost.localdomain
- can_submit_commands 1
- }
II -- 接下来看两个时间周期定义格式:在上面的例子里,主机、服务报警周期都定义为24x7,即随时发送报警,这也是nagios的默认设置。
- define timeperiod{
- timeperiod_name work-hours
- alias Work Hours send mail
- monday 09:00-18:00
- tuesday 09:00-18:00
- wednesday 09:00-18:00 //周一到周五每天9点到18点
- thursday 09:00-18:00
- friday 09:00-18:00
- }
- define timeperiod{
- timeperiod_name misc-single-days
- alias Misc Single Days send mail
- 2008-08-08 00:00-24:00 //2008年8月8日全天
- monday 1 00:00-24:00 //每月的第三个星期一
- day 2 00:00-24:00 //每月的第二天
- february 10 00:00-24:00 //每年二月的第10天
- february -1 00:00-24:00 //每年二月的最后一天
- friday -2 00:00-24:00 //每月的倒数第二个星期五
- thursday -1 november 00:00-24:00 //每年十一月的最后一个星期四
- }
上面的例子总定义了两种风格的时间周期。
第一个例子,定义周一到周五每天的9点到18点为发送email的时间;
第二个例子,定义了一些特殊的时间段,在这些指定的时间段里都要发送email。
III -- 上面已经有了标准的联系人定义和一些时间周期定义,那么下面的就是将联系和时间周期定义关联的方法
- define contact{
- contact_name tester01
- alias tester01 for Work Hours send
- mailhost_notifications_enabled 1
- service_notifications_enabled 1
- service_notification_period work-hours //关联时间周期定义
- host_notification_period work-hours //关联时间周期定义
- service_notification_options w,u,c,r
- host_notification_options d,u,r
- service_notification_commands notify-by-email
- host_notification_commands host-notify-by-email
- email Roland@localhost.localdomain
- can_submit_commands 1
- }
- define contact{
- contact_name tester02
- alias tester01 for misc-single-days send mail
- host_notifications_enabled 1
- service_notifications_enabled 1
- service_notification_period misc-single-days //关联时间周期定义
- host_notification_period misc-single-days //关联时间周期定义
- service_notification_options w,u,c,r
- host_notification_options d,u,r
- service_notification_commands notify-by-email
- host_notification_commands host-notify-by-email
- email Roland@localhost.localdomain
- can_submit_commands 1
- }
通过上面的联系人定义方法就既可非常方便的将不同时间周期定义应用到不同的联系人中。以上所述只是nagios联系人定义和时间周期定义的简单应用,更深层的配置方法和应用案例欢迎大家与我探讨。
-- -- 上述文字描述、配置、方法、案例等如有不妥之处请读者诸君予以纠正 -- --
转载于:https://blog.51cto.com/rolandqu/942416