How to setup a nagios event handler to run only in non working hours

nagiossystem-monitoring

I have a event handler configured and running in nagios which is triggered every time a given service is in a CRITICAL state.

The problem is that we decided that in regular working hours there's no need to run the event handler as we can fix the problem by hand and in a more efficient way.

The question is, is there any way I can setup this event handler to run just in a given periot of time and yet be normally notified of the CRITICAL state? Let's say in non-working hours?

Thanks in advance for your help.

Best Answer

Take a look at the Nagios macro ISVALIDTIME.

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".

Don't know whether this is present in the service context, but you can test it. Define a timeperiod "non-working hours" and take ISVALIDTIME as a parameter to your eventhandler script. When the script is called during working hours, let it do nothing and exit.

When this doesn't work, you could just verify the time of day in the eventhandler script.

Related Topic