Event handler definition

Good morning everyone.

I have no experience in shell scripting and event handlers and currently I am searching for some guidance.

In one of our servers, we are required to do an event handler for 20 of the machines.
Is it possible to define them as follow?

define command {
command_name event-handler-name-goes-here

       command_line script1 /opt/scripts/eventhandlerscript.sh hostname1, hostname2, and so on... (EXAMPLE)


Hi joaoe33,
can you explain which problem you want to solve with the event handler?

It is quite complex.

In the server we have several machines, but the event handler is to work when a certain group of machines goes into critical state in a given service.

I have never worked with event handlers and scripts but I have managed to do a barebone script. My question is how to handle the macros.

I was thinking of calling a Python script to the check if the hostname belongs to the list of hosts required, and to do some other operations, such as creating a JSON file.

Hi joaoe33,
thanks for the explanation.
When using the (paid) Entreprise Edition, you can use the Alert Handler for this purpose. But with the Raw Edition you can use the Event Handlers with standard configuration under ~/etc/nagios/conf.d/. See also the (short) doc here:

See also the other files there. The hostname shall be denoted as $HOSTNAME$ e.g…

Currently we are using the Raw version, hence why we are trying to configure the Event Handlers.

So basicly i can do a define such as:

define command {
command_name event-handler-name-goes-here

       command_line script1 /folder/script.sh $HOSTNAME$


And when executing the code have a line like this

python script.py $HOSTNAME$

The event handler needs to be defined rather like this:

define command {
        command_name myeventhandler01
        command_line /myfolder01/myscript01.sh $HOSTNAME$

The file /myfolder01/myscript01.sh may be a python file. Ensure that the script is executable when run with a proper argument.


Thank you for your help.

I do have a few more questions.

To allow check_mk to run the event handler, what file in conf.d folder should be altered? PNP4Nagios.cfg?

And also is it required to do an extra_service_conf in the main.mk file to declare the event handler?