2

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?

Richlv
  • 3,954
  • 1
  • 17
  • 21
KJ9
  • 169
  • 2
  • 11

2 Answers2

3

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)

Simone Zabberoni
  • 2,024
  • 1
  • 10
  • 15
0

Using curl.

To get problem event ids:

curl -H "Content-Type: application/json-rpc" -X POST my_zabbix_url -d '{"jsonrpc": "2.0","method": "problem.get","params": {},"auth": "my_token","id": 0}'

To get hosts based on event id:

curl -H "Content-Type: application/json-rpc" -X POST my_zabbix_url -d '{"jsonrpc": "2.0","method": "event.get","params": {"selectHosts": ["host","name"],"output": "extend","select_acknowledges": "extend","objectids": "my_event_object_id","sortfield": ["clock", "eventid"],"sortorder": "DESC"},"auth": "my_token","id": 0}'
Ken Roy
  • 915
  • 1
  • 10
  • 15