【问题标题】:get host list from zabbix api with python使用python从zabbix api获取主机列表
【发布时间】:2014-10-23 13:55:06
【问题描述】:

请帮助我,提供一些想法或一些代码)) 我列出了所有主机,并列出了 zabbix 服务器中存在的所有密钥。 那么,当我选择需要的密钥时,如何显示哪个服务器有这个密钥? 在我的示例中,我如何列出拥有关键 vmware 的主机?谢谢 我的例子:

data = {
                    "jsonrpc": "2.0",
                    "method": "host.get",
                    "params": {
                            "output": "extend"
                    },
                    "auth": authId,
                    "id": 2
            }
            request = requests.post(path, data=json.dumps(data), headers={'content-type':'application/json-rpc'})
            result = []
            request_res = request.json()['result']
            for item in request_res:
                    result.append(item['hostid'])
            data = {
                    "jsonrpc": "2.0",
                    "method": "item.get",
                    "params": {
                            "output": "extend",
                            "hostids": hosts_list,
                            "sortfield": "name"
                    },
                    "auth": authId,
                    "id": 1
                    }
            request = requests.post(path, data=json.dumps(data), headers={'content-type':'application/json-rpc'})
            request_res = request.json()['result']
            keys_list = []
            for items in request_res:
                    keys_list.append(items['key_'])
            keys_list = dict.fromkeys(keys_list).keys()
            data = {
                    "jsonrpc": "2.0",
                    "method": "host.get",
                    "params": {
                            "filter":{
                                    "key_" : "vmware"
                            },
                            "output": "extend",
                    },
                    "auth": authId,
                    "id": 2
            }
            request = requests.post(path, data=json.dumps(data), headers={'content-type':'application/json-rpc'})
            request_res = request.json()['result']
            print request_res

【问题讨论】:

    标签: python json zabbix


    【解决方案1】:

    1.) 选择带有密钥 vmware 的项目 ID

                    "method": "item.get",
                    "params": {
                            "output": ["itemid"],
                            "search":{
                                    "key_" : "vmware"
                            }                            
                    }
    

    2.) 然后选择具有这些项目 ID 的主机

                    "method": "host.get",
                    "params": {
                            "output": "extend",
                            "itemids": [<itemsids from previous step>]                            
                    },
    

    【讨论】:

      猜你喜欢
      • 2015-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多