标签: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
参数 | 类型 | 描述 |
---|---|---|
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