How to create a python event handler for failure events

Hi

i defined event command for service/host aas per below syntax

event_command = “send_to_businesstool”

Now instead of below

object EventCommand “send_to_businesstool” {
command = [
“/usr/bin/curl”,
“-s”,
“-X PUT”
]

arguments = {
“-H” = {
value ="$businesstool_url$"
skip_key = true
}
“-d” = “$businesstool_message$”
}

vars.businesstool_url = “http://localhost:8080/businesstool
vars.businesstool_message = “$host.name$ $service.name$ $service.state$ $service.state_type$ $service.check_attempt$”
}

How can i define event _command = python script , where python takes the input for host/service and reason of failure and do some business logic"

How can i implement this??

Thanks
Mayank (AMdocs)

Hi,

you are already using runtime macro strings which are evaluated from custom variables and object attributes. Everything already works and calls curl. If you prefer to move this into a dedicated python script, leave the EventCommand arguments “as is”, and only change the command pointing e.g. to PluginDir + "/eventhandler_bpt.py".

The python script itself should implement argparser to receive the URL and message. In terms of API calls, the requests library is a good fit.

Cheers,
Michael