Event Handling using monitoring status as condition.

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.
doubleclick
Posts: 7
Joined: Thu Dec 22, 2016 1:11 pm

Event Handling using monitoring status as condition.

Post 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.
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Event Handling using monitoring status as condition.

Post 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?
Former Nagios employee
https://www.mcapra.com/
doubleclick
Posts: 7
Joined: Thu Dec 22, 2016 1:11 pm

Re: Event Handling using monitoring status as condition.

Post 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.)
avandemore
Posts: 1597
Joined: Tue Sep 27, 2016 4:57 pm

Re: Event Handling using monitoring status as condition.

Post 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.
Previous Nagios employee
doubleclick
Posts: 7
Joined: Thu Dec 22, 2016 1:11 pm

Re: Event Handling using monitoring status as condition.

Post 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?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Event Handling using monitoring status as condition.

Post 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.
Former Nagios Employee
doubleclick
Posts: 7
Joined: Thu Dec 22, 2016 1:11 pm

Re: Event Handling using monitoring status as condition.

Post 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.
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Event Handling using monitoring status as condition.

Post 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.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Event Handling using monitoring status as condition.

Post 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$.
Former Nagios Employee
doubleclick
Posts: 7
Joined: Thu Dec 22, 2016 1:11 pm

Re: Event Handling using monitoring status as condition.

Post 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.
Locked