码迷,mamicode.com
首页 > Windows程序 > 详细

zabbix--api学习之路--get_hostgroup获取

时间:2018-10-12 13:53:29      阅读:419      评论:0      收藏:0      [点我收藏+]

标签:imp   ati   class   dump   tab   lib   检索   2.0   output   

api:hostgroup.get
url:https://www.zabbix.com/documentation/3.4/zh/manual/api/reference/hostgroup/get

  • 参数说明:The method allows to retrieve host groups according to the given parameters.该方法允许根据给定的参数检索主机组。

  • The method supports the following parameters.该方法支持以下参数
    参数 类型 描述
    graphids string/array 只返回包含具有给定图表的主机或模板的主机组。
    groupids string/array 只返回具有给定主机组ID的主机组。
  • 获取所有主机群组

import json
import urllib2
url ="http://10.127.0.119/api_jsonrpc.php"
header = {"Content-Type":"application/json" }
data =json.dumps(
{
    "jsonrpc": "2.0",
    "method": "hostgroup.get",
    "params": {
        "output": "extend", #不加条件,输出全部
        # "filter": {
        #     "name": [
        #         "Linux servers",
        #         "Zabbix servers",
        #         "Discovered hosts"
        #     ]
        # }
      },
    "auth": "cb5a0ce5ffbdd1cf3a18e32117801592", #刚才过去到的auth
    "id": 1
}
)
request =urllib2.Request(url,data)
for key in header:
   request.add_header(key,header[key])
   # get host list
   result = urllib2.urlopen(request)
   response = json.loads(result.read())
   result.close()
   print response
   print "Number Of Hosts: ", len(response[‘result‘]) #总数
   #print response
   for group in response[‘result‘]:
       #print group
       print "Group ID:",group[‘groupid‘],"\tGroupName:",group[‘name‘]
  • 按照名字获取主机群组

  • 请求:
{
    "jsonrpc": "2.0",
    "method": "hostgroup.get",
    "params": {
        "output": "extend",
         "filter": {
            "name": [
                 "Linux servers",
                 "Zabbix servers",
                 "Discovered hosts"
             ]
         }
      },
    "auth": "cb5a0ce5ffbdd1cf3a18e32117801592",
    "id": 1
}
  • 响应:
Number Of Hosts:  3
Group ID: 5     GroupName: Discovered hosts
Group ID: 2     GroupName: Linux servers
Group ID: 4     GroupName: Zabbix servers

zabbix--api学习之路--get_hostgroup获取

标签:imp   ati   class   dump   tab   lib   检索   2.0   output   

原文地址:https://www.cnblogs.com/zdoubly/p/9777122.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!