CheckMK-Raw - Set Up Event Handler

Hello everyone, I am opening this topic in order to understand how to set up correctly Event Handler in CheckMK Raw (currently I am running version 2.3.0p21 CRE).

I am quite new with CheckMK. Currently i have set up my site, created a folder, and using the API support created some hosts (with the auto-discovered services) without any issues.
The next thing that i would like to do is to use the Nagios Event Handler functionality to execute some custom Bash scripts in case a specific service goes into CRITICAL state.

I tried the following steps without success:

Modify directly (following the Nagios documentation) the file opt/omd/sites//etc/nagios/conf.d/check_mk_objects.cfg by adding to a specific service the fields:

event_handler_enabled 1
event_handler powercycle

And by adding in the same file the command:

define command{
        command_name   power-cycle
        command_line   /opt/omd/sites/<site>/etc/nagios/eventhandlers/powercycle.sh
        }

Then I save the file (btw powercycle is my custom script) and try to restart the Nagios core in order to apply the modification but:

  • If i execute the command omd restart core the service Nagios is stopped and then started. But if i try to perform a test on my host I do not notice the execution of the script (or the trigger of the event handler)

  • If I execute the command cmk -O or cmk -R the Nagios service is restarted correctly, but the changes performed in the opt/omd/sites//etc/nagios/conf.d/check_mk_objects.cfg file are lost

Following the suggestion reported in Event handler definition and Check_MK: Selbstheilung mit Event Handler | Geekbundle.org I try to modify the file /opt/omd/sites//etc/check_mk/main.mk (which is empty) by adding the following lines:

extra_service_conf["event_handler_enabled"] = [
  ( "1", ["switch-01"], ["Interface 42"] ),
]
 
extra_service_conf["event_handler"] = [
  ( "power-cycle", ["switch-01"], ["Interface 42"]),
]
 
extra_nagios_conf += r"""
 
define command{
        command_name   power-cycle
        command_line   /opt/omd/sites/<site>/etc/nagios/eventhandlers/powercycle.sh
        }
 

However, if i try to execute the command cmk -O I obtain the following error message:

OMD[<site>]:/opt/omd/sites/<sites>/etc/nagios/conf.d$ cmk -O
Generating configuration for core (type nagios)...
An error occurred: Error creating configuration: tuple indices must be integers or slices, not str

What am I missing?
Thank you in advance for your assistance

Hi,

I’m looking also for something similar. Did you manage with this to work?

Unfortunately no Matjaž, now I switched to a different approach using the Integrate Nagios Plugins functionality (but I am still facing some issues, for which I will open another discussion).

Hi,

After some time and testing I’ve found a working solution with Nagios Event Handler. I’ve add my full description here in this separated topic I’ve opened some days ago. If you will find it as useful, please mark it as a solution.

Regards,
Matjaž

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.