Event handler definition

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.