logIt Log Around The Clock

Acknowledging Event: Zabbix Python API

Acknowledgement is one of the things that is provided by Zabbix API in its event section. We can make use of the methods get() and acknowledge() to automatically acknowledge an event. Digging through the attributes of those methods, the official doc doesn’t provide complete example to follow. Added with some luck, my search get me to have the following JSON RPC that works in Zabbix 1.8.7 using Gescheit API implementation written in Python.

When the goal is to acknowledge a specific event, the JSON call is however limited to some basic responses. It means that you can’t query a single RPC request for i.e. the following combination: list of acknowledged events with “problem” status and trigger ID 500 (500 is merely an example).

However, combination in a single request do exist i.e. I’ve tried: list of acknowledged events with “problem” status as the following GET request:

{
"params": {"acknowledged": [1], "value": [1]}, "jsonrpc": "2.0",
"method": "event.get",
"auth": "some-hash-authentication",
"id": some-RPC-sequence-integer
}

(Note: value=1 means status is “problem”)

For the basic example above, find the script in my fork of Gescheit API.

Back to our goal of acknowledging events, our API can make the following RPCs:

ack_list=zapi.event.get({"acknowledged":[1]})
problem_list=zapi.event.get({"value":[1]})
event_trigger_list=zapi.event.get({"triggerids":[trigger_id]})

Yes, they are three requests. We can then filter out a single event to be acknowledged by intersecting the three results. The first intersection is between event_trigger_list, problem_list, and ack_list as illustrated below:

problem-list-acknowledgement-intersection.jpg

Intersection of problem list, event list with specific trigger ID, and acknowledged event list

After we opt-out those intersections, we can then get the event with problem status and choose the latest event only to be acknowledged. Check the code on my github.


Leave a Reply