Different timeperiods for the same service

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
gilbertogm
Posts: 4
Joined: Fri Apr 04, 2014 7:16 am

Different timeperiods for the same service

Post by gilbertogm »

Hello guys,

I'd like to check a service and do different thins depending on the time:

Let's say:

define service{
use generic-service
service_description Service_PING
host_name host1
check_command check_ping!2000.0,80%!5500.0,99%
check_period nonworkhours
max_check_attempts 10
retry_check_interval 3
normal_check_interval 5
event_handler_enabled 1
event_handler retryPing
}

During non-working hours, it executes the event_handler.

define service{
use generic-service
service_description Service_PING
host_name host2
check_command check_ping!2000.0,80%!5500.0,99%
check_period workhours
normal_check_interval 5
}

And on working hours, just check as normal.

Does that work? Is there a better way to do this?

Thanks in advance.
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Different timeperiods for the same service

Post by sreinhardt »

The only way I could think to do this would be to call the event handler each time and have it specifically check the time. You might also be able to pass the timeperiod to it via macro, but it would still need to be parsed and calculated within the script. Presently using timeperiods in this fashion is not really possible, but it does sound kinda cool!

Thinking about it a bit more, you could have a second service for the time when you want the alternative action. However if you plan to report on this service, you would need to be use the first idea of having the event handler manage it all. It really shouldn't be all that difficult to handle the time check within a script, just not really ideal.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
gilbertogm
Posts: 4
Joined: Fri Apr 04, 2014 7:16 am

Re: Different timeperiods for the same service

Post by gilbertogm »

I have worked around and i found a way to do it.

on the command i added the macro $ISVALIDTIME:non-workinghours$

and then on the script i just added the condition

if [ "$6" = '1' ]; then
....
fi
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Different timeperiods for the same service

Post by tmcdonald »

There is some logic that works best in the script itself, and this is definitely one of those cases. Cane we close the thread as solved?
Former Nagios employee
Locked