我必须在我的基础架构中显示所有当前问题(例如在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有关主机名,最重要的是有关问题描述,例如“缺少自由交换空间”?
答案 0 :(得分:0)
此代码段应能达到目的:
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 )
当然,如果不需要,可以省略group和hostinterface api调用