time between two services

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
ron123456
Posts: 4
Joined: Wed Feb 04, 2015 7:06 am

time between two services

Post 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 .
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: time between two services

Post 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.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: time between two services

Post by tgriep »

Thanks @eloyd for the help on this. @ron123456 if you have any more questions on this, please post them here.
Be sure to check out our Knowledgebase for helpful articles and solutions!
ron123456
Posts: 4
Joined: Wed Feb 04, 2015 7:06 am

Re: time between two services

Post 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)
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: time between two services

Post 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. :-)
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: time between two services

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
ron123456
Posts: 4
Joined: Wed Feb 04, 2015 7:06 am

Re: time between two services

Post by ron123456 »

Thank you both, i think you gave me a right direction to continue with
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: time between two services

Post by tgriep »

Your welcome. If you have anymore questions, let us know.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked