如何向Zabbix询问问题描述?

2024-06-28 20:12:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须在我的基础设施中显示所有当前的问题(比如在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询问主机名,最重要的是询问问题描述,如“缺少可用交换空间”


Tags: infohostgetdate基础设施仪表板nszabbix
1条回答
网友
1楼 · 发布于 2024-06-28 20:12:48

此代码段应该可以实现以下功能:

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 )

当然,如果不需要组和hostinterface api调用,可以省略它们

相关问题 更多 >