Page 1 of 1
Trigger / Sequence 2 x Services
Posted: Mon Dec 18, 2023 4:39 am
by bpg
Hi
I have 2 services that I'd like to run in sequence.
Is it possible to have the 1st service trigger the 2nd service?
I want this to happen regardless of what status is returned from the 1st service.
Any help greatly appreciated.
Re: Trigger / Sequence 2 x Services
Posted: Mon Dec 18, 2023 10:27 am
by gwesterman
Hi @bpg,
This can be accomplished using
service dependencies. You can make service 2 dependent on service 1 and set whatever return value from service 1 you want to be considered a failure (in your case none). This will make nagios check service 1 before checking service 2 and, once service 1 returns, check service 2. Admittedly, this isn't exactly having service 1 "trigger" service 2 but it should guarantee that they run in sequence. For a true "trigger", you would probably have to set up one or more
event handlers. There is a lot you can do with service dependencies and it can get pretty complicated pretty quickly.
Hope this helps!
Thank you!
Re: Trigger / Sequence 2 x Services
Posted: Mon Dec 18, 2023 11:51 am
by bpg
Thanks for the suggestion @gwesterman - much appreciated.
Am I right in thinking that the dependent service ('service 2') has to be active at all times for this to work?
I was hoping that 'service 2' could be left as inactive and only run when triggered by 'service 1'.
If that is the case then I think that an event handler might be the only solution to this but would appreciate your opinion.
Thanks
Re: Trigger / Sequence 2 x Services
Posted: Tue Dec 19, 2023 12:29 pm
by gwesterman
I believe that you are correct, yes. Every time service 2 is run, nagios checks if it has any dependencies and runs those first, only running service 2 if the return code you set as success returns. So this requires service 2 to be active on its own. Event handlers do seem to be your best bet for what you're looking for.
Thank you!