如何向Zabbix询问问题描述?

How to ask Zabbix about problem description?

我必须在我的基础架构中显示所有当前问题(例如在 Zabbix 仪表板中)。 我希望它看起来像这样:

Date     Host          Problem info    
19.03    hostsap1      Lack of free swap space
18.03    hostsmb2      Zabbix_agentd is not running!

我用problem.get

problemlist = zapi.do_request('problem.get',
                                  {
                                     "output": "extend", 
                                      "selectAcknowledges": "extend", 
                                      "recent": "true", 
                                      "sortfield": ["eventid"],
                                      "sortorder": "DESC" 
                                  })

我有答案:

{
   'eventid': '25644', 
   'source': '0', 
   'object': '0', 
   'objectid': '147717', 
   'clock': '2447665140', 
   'ns': '193586738', 
   'r_eventid': '0', 
   'r_clock': '0', 
   'r_ns': '0', 
   'correlationid': '0', 
   'userid': '0', 
   'acknowledges': []
}, 
[...]

如何向 zabbix 询问主机名以及最重要的问题描述,如 "Lack of free swap space"?

这段代码应该可以解决问题:

zapi = ZabbixAPI(url=zabbixServer, user=zabbixUser, password=zabbixPass)

problems = zapi.problem.get()

for problem in problems:
    trigger = zapi.trigger.get (triggerids=problem['objectid'], selectHosts='extend')
    interface = zapi.hostinterface.get(hostids=trigger[0]['hosts'][0]['hostid'])
    group = zapi.hostgroup.get(hostids=trigger[0]['hosts'][0]['hostid'])

    enabled = "Enabled"
    if (trigger[0]['hosts'][0]['status'] == "1"):
        enabled = "Disabled"

    print "Group:{}; Host:{}; IP:{}; Problem:{}; {}".format(group[1]['name'],
                                                           trigger[0]['hosts'][0]['host'],
                                                           interface[0]['ip'],
                                                           trigger[0]['description'],
                                                           enabled )

当然,如果不需要,可以省略组和主机接口api调用