如何设置一个nagios事件处理程序只在非工作时间运行?

我有一个事件处理程序configuration和运行在每次给定的服务处于CRITICAL状态触发的nagios。

问题是,我们决定在正常工作时间内不需要运行事件处理程序,因为我们可以通过手动和更高效的方式解决问题。

问题是,有没有什么办法可以设置这个事件处理程序只运行在一个给定的时间周期,但通常情况下通知CRITICAL状态? 我们说在非工作时间?

在此先感谢您的帮助。

看看Nagios的macrosISVALIDTIME 。

This is a special on-demand macro that returns a 1 or 0 depending on whether or not a particular time is valid within a specified timeperiod. There are two ways of using this macro: $ISVALIDTIME:24x7$ will be set to "1" if the current time is valid within the "24x7" timeperiod. If not, it will be set to "0". $ISVALIDTIME:24x7:timestamp$ will be set to "1" if the time specified by the "timestamp" argument (which must be in time_t format) is valid within the "24x7" timeperiod. If not, it will be set to "0". 

不知道这是否存在于服务上下文中,但是你可以testing它。 定义一个timeperiod“非工作时间”,并把ISVALIDTIME作为你的eventhandler脚本的一个参数。 当在工作时间内调用脚本时,不要执行任何操作并退出。

当这不起作用时,您可以在事件处理程序脚本中validation一天的时间。

在我提出实际的答案之前,需要注意的一点是,当我build立我们的呼叫路由系统,而不是手工处理“工作时间”时,我完全忘记了公共假期,让紧急的客户呼叫响起在星期一的下一个银行假日的一半空的办公室。

我相信你会比这更小心:-)

抛开这个警告,它看起来像是想在Nagiosconfiguration中定义一些timeperiod对象,例如:

 define timeperiod{ timeperiod_name workhours alias "Normal" Working Hours monday 08:00-17:00 tuesday 08:00-17:00 wednesday 08:00-17:00 thursday 08:00-17:00 friday 08:00-17:00 } 

然后在服务configuration中用check_period调用它们:

 define service{ use some-service name service-name ... check_period 24x7 ... } 

如果你真的想这样做,我有一个想法(这是我想到的第一件事):

  1. 把服务定义放在一个单独的文件中,使其更容易
  2. 写一个脚本来检查当前的时间
  3. 在工作时间的开始时间,您将在configuration文件中注释event_handler行,并在注释结束时注释掉。 (你可以用sed来做)

试试这个,让我知道如果它的作品。