Search code examples
zabbix

How can I retrieve problem and host name using Zabbix API?


I want to retrieve data from Zabbix API using ZabbixAPI.

So I made API JSON like below.

zabbixapi.problem.get(time_from=time_from,
                        time_till=time_till,
                        selectHosts = ["host","name"],
                        sortorder = "DESC",
                        output = "extend",
                        monitored = 1)

Result has no host information. Result is below.

[{'eventid': '401154', 'source': '0', 'object': '0', 'objectid': '18265', 'clock': '1569375897', 'ns': '887610916', 'r_eventid': '0', 'r_clock': '0', 'r_ns': '0', 'correlationid': '0', 'userid': '0', 'name': 'Optical power is low on port 7', 'acknowledged': '0', 'severity': '3', 'suppressed': '0'}, {'eventid': '401456', 'source': '0', 'object': '0', 'objectid': '30714', 'clock': '1569401534', 'ns': '909385820', 'r_eventid': '0', 'r_clock': '0', 'r_ns': '0', 'correlationid': '0', 'userid': '0', 'name': 'Optical power is low on port 33', 'acknowledged': '0', 'severity': '3', 'suppressed': '0'}]

I think "selectHosts" does not work. How can I get problem with host information?


Solution

  • According to the documentation, problem.get does not have a selectHosts parameter.

    Every item of the returned object has a eventid value, you can use it in a event.get call, which supports selectHosts.

    Or you can do a single event.get call with selectHosts plus a filter for value = 1, that corresponds to the "Problem" state (see the documentation for the event object)