zabbix--api學習之路--get_hostgroup獲取
阿新 • • 發佈:2018-10-12
獲取 document lib 返回 quest cat ber param -s
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獲取