time between two services

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

time between two services

Postby ron123456 » Mon Jun 12, 2017 7:15 am

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

Re: time between two services

Postby eloyd » Mon Jun 12, 2017 1:15 pm

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
eloyd
Cool Title Here
 
Posts: 1857
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY

Re: time between two services

Postby tgriep » Mon Jun 12, 2017 1:20 pm

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!
User avatar
tgriep
Madmin
 
Posts: 6086
Joined: Thu Oct 30, 2014 9:02 am

Re: time between two services

Postby ron123456 » Tue Jun 13, 2017 1:05 am

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

Re: time between two services

Postby eloyd » Tue Jun 13, 2017 6:08 am

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
eloyd
Cool Title Here
 
Posts: 1857
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY

Re: time between two services

Postby tgriep » Tue Jun 13, 2017 11:29 am

Another option is to use this plugin which will run multiple checks in a row.
https://exchange.nagios.org/directory/Plugins/Others/check_multiple/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!
User avatar
tgriep
Madmin
 
Posts: 6086
Joined: Thu Oct 30, 2014 9:02 am

Re: time between two services

Postby ron123456 » Thu Jun 15, 2017 7:42 am

Thank you both, i think you gave me a right direction to continue with
ron123456
 
Posts: 4
Joined: Wed Feb 04, 2015 7:06 am

Re: time between two services

Postby tgriep » Thu Jun 15, 2017 11:23 am

Your welcome. If you have anymore questions, let us know.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tgriep
Madmin
 
Posts: 6086
Joined: Thu Oct 30, 2014 9:02 am


Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 31 guests