Page 1 of 1

time between two services

Posted: Mon Jun 12, 2017 7:15 am
by ron123456
Hi All,

Is it possible to manage the time of check between two different services ?

for example :

i have two services : service1 and service2

i want that the next_check of service2 will be not less then x minutes after service1 (also the retry checks)

service | next check
---------------------------
service1 | 10:00:00

service2 | 10:00:00 + x


Thanks .

Re: time between two services

Posted: Mon Jun 12, 2017 1:15 pm
by eloyd
My advice (as it almost always is) is event handlers. First, I'm going to assume "x" is 10 minutes, just to make things easier. Second, I'm going to assume you know how to add "event_handler_enabled 0" to all your service configs (do this first).

Set service 2 to be passive and put a 20 minute freshness check on it. 20 is simple twice your "x" or 2 x 10 minutes in my example.

Set service 1 to have event_handler_enabled set to 1 and enable event handlers if you haven't already.

Create an event handler (maybe, /usr/local/nagios/libexec/my_event_handler) that pauses for 10 minutes (remember 10 minute is just my sample "x" from your example) and then executes the actual service check commands required for service 2.

This is pure oversimplification, but I hope you get the idea. I can get more complex if you need me to. Basically, this gives you a lock-step ten minute lag every time service 1 runs before service 2 runs. You may have to hard code some parameters in your event handler script or you may get fancy and parse config files (or use an API!) to figure out what should be sent, but I hope you get the idea.

Remember - this is brute force and event handlers can be your friend. But, as a Nagios world conference talk of mine entitled "Nagios Fails and Bloopers" would have shown, to err is human but to really foul things up you need event handlers.

Another approach would be to become familiar with the Unix "at" command and have service 1 simply execute "at now +10 minutes <execute command for service 2>" and you won't need event handlers.

I'm sure there are other ways.

Re: time between two services

Posted: Mon Jun 12, 2017 1:20 pm
by tgriep
Thanks @eloyd for the help on this. @ron123456 if you have any more questions on this, please post them here.

Re: time between two services

Posted: Tue Jun 13, 2017 1:05 am
by ron123456
Hi eloyd,

Thanks for the answer .

the concept is clear, but what is the event handler that should trigger service2 to run ?
service2 should run always x min after service1 but with no dependency of service1 output state (service2 don't care what happend in service1)

Re: time between two services

Posted: Tue Jun 13, 2017 6:08 am
by eloyd
This is one of those "exercises left for the reader" type things. If you're not familiar with event handlers, they are scripts that run after a service check completes. You have to write it. There are resource on the web (use your search engine to find them) that have ideas on how to implement them.

Basically, an event handler would have no care in the world as to the state of service 1 in this case, it's only using it as a trigger to fire off service 2. Personally, I'd just write a service check wrapper that always fires off service check 1, sleeps for 10 minutes, then fires off service check 2, set #2 to be passive, and have the wrapper submit the results of service check 2 using the various Nagios APIs that are available.

But then, I like writing shell scripts. :-)

Re: time between two services

Posted: Tue Jun 13, 2017 11:29 am
by tgriep
Another option is to use this plugin which will run multiple checks in a row.
https://exchange.nagios.org/directory/P ... le/details
It doesn't look like it had a delay feature but if that is not needed, it could work for you.

Re: time between two services

Posted: Thu Jun 15, 2017 7:42 am
by ron123456
Thank you both, i think you gave me a right direction to continue with

Re: time between two services

Posted: Thu Jun 15, 2017 11:23 am
by tgriep
Your welcome. If you have anymore questions, let us know.