Page 1 of 2

Event Handling using monitoring status as condition.

Posted: Thu Dec 22, 2016 1:39 pm
by doubleclick
Good Morning,

Is it possible to configure event handlers for hosts according to their monitoring status of disabled or enabled? I.e. If I disabled or activated monitoring for a host, could an event handler be triggered accordingly?

From what I've been reading it looks as if event handlers are very useful when using host states as conditions, but was wondering if the suppression status of a host could also be used as a condition?

If event handlers are not the way to go, would there be an alternative?

Thank you.

Re: Event Handling using monitoring status as condition.

Posted: Thu Dec 22, 2016 2:19 pm
by mcapra
It would depend on the specific use case I suppose. Strictly speaking, if a Host/Service is not being monitored it's corresponding event handler should never execute:
https://assets.nagios.com/downloads/nag ... dlers.html
Event handlers are executed when a service or host:
  • Is in a SOFT problem state
  • Initially goes into a HARD problem state
  • Initially recovers from a SOFT or HARD problem state
Could you describe the use case a little more in-depth?

Re: Event Handling using monitoring status as condition.

Posted: Thu Dec 22, 2016 2:47 pm
by doubleclick
Thank you for your reply.

Indeed event handlers might not be the best option.

I've got monitoring services on a remote host. These services can only be suppressed/unsuppressed by running certain scripts. I'd like to use the nagios GUI to trigger these scripts, effectively disabling/enabling monitoring when I click the respective Nagios GUI buttons. (For this particular use case I cannot use nrpe.)

Re: Event Handling using monitoring status as condition.

Posted: Thu Dec 22, 2016 4:23 pm
by avandemore
Have you looked at the External Commands feature?

https://assets.nagios.com/downloads/nag ... mands.html

Although I confess I'm puzzled by your use case since that functionality is already in the GUI.

Re: Event Handling using monitoring status as condition.

Posted: Thu Dec 22, 2016 7:34 pm
by doubleclick
Apologies if I'm not explaining myself right,

When we use the nagios GUI to disable (or enable) monitoring, it is my understanding that in the background a certain instruction is triggered to write onto the command file, such as:
/bin/printf "[%lu] DISABLE_HOST_CHECK;host1\n" $now > $commandfile

(taken from here: https://old.nagios.org/developerinfo/ex ... mand_id=54 )

What I'd like to do (for a specific service of a remote host) is: when the Nagios GUI is used to disable/enable monitoring an instruction would be triggered to run one of my scripts instead.

The reason behind this is that I've got a remote host that contains services which are monitored by custom local scripts. I can locally and remotely prevent these scripts from running, thus disabling monitoring. Using the Nagios GUI to achieve this would be a lot nicer though. Admittedly, I guess this is not what nagios should be used for, however since I've got a few hosts in nagios it would be nicer to keep using Nagios and keep monitoring suppression/unsuppression in one place.

From what I read, external commands appear to be the opposite of what I'm trying to do - or perhaps I did not understand them correctly?

Re: Event Handling using monitoring status as condition.

Posted: Tue Dec 27, 2016 12:26 pm
by rkennedy
I believe event handlers will work for this, however, you need to build a script to interpret the logic as @mcapra mentioned. Then, you can fine line execute whatever happens when x variables line up, such as execute the scripts on the local machine through check_by_ssh or check_nrpe.

Re: Event Handling using monitoring status as condition.

Posted: Mon Jan 09, 2017 3:44 pm
by doubleclick
Thank you for your help @rkennedy. Is there any nagios documentation you'd recommend on the topic of implementing a system that interprets the logic mentioned by @mcapra ? Looks as if I'll need to be working with a few background system files in order to be able to execute actions when host suppression status conditions are met, but not entirely sure where to start.

Re: Event Handling using monitoring status as condition.

Posted: Mon Jan 09, 2017 4:28 pm
by dwhitfield
What version of Core are you using? Was it compiled from source or installed from distro repos? On what OS/version is nagios running? cat /etc/*-release may be of use.

All of that will help us give you the right documentation and potentially the right file paths.

Re: Event Handling using monitoring status as condition.

Posted: Mon Jan 09, 2017 4:31 pm
by rkennedy
The macros which will evaluate into the variables your after can be found here - https://assets.nagios.com/downloads/nag ... olist.html

I believe the specific ones you'll want to build your conditioning off of are $HOSTSTATE$ and $SERVICESTATE$.

Re: Event Handling using monitoring status as condition.

Posted: Wed Jan 11, 2017 4:27 pm
by doubleclick
Thank you @dwhitfield and @rkennedy.

Would there be macros similar to $HOSTSTATE$ and $SERVICESTATE$ that would evaluate against a host or service suppression status? This would really solve the problem.

The OS I'm using is RHEL Server release 5.3 and the Nagios version is 4.0.7.