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 corethe 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 -Oorcmk -Rthe 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