[英]How get zabbix enabled host,Through the use of API
這是我的代碼,它可以獲取所有主機。我只需要啟用主機即可。
import requests
import csv
import json
url = 'https://xxxx.zabbix.com/api_jsonrpc.php'
post_data = {
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"filter":{
"with_monitored_items": True},
"output":
["host"],
"selectInterfaces":
["ip"]},
"id": 1,
"auth": "xxxxxxxxxxxxxxxxxx"}
post_header = {'Content-Type': 'application/json-rpc'}
ret = requests.post(url,
data=json.dumps(post_data),
headers=post_header,
verify=False)
data = ret.json()['result']
# print(data)
parsed_result = [{'host': i['host'], 'eth0': i['interfaces'][0]['ip'],
'type': 'vm', 'status': 'online'} for i in data]
print(parsed_result)
with open("data.csv", "w") as file:
csv_file = csv.writer(file)
header = ['hostname', 'eth0', 'type', 'status']
data_rows = [(i['host'], i['eth0'], i['type'], i['status']) for i in parsed_result] # NOQA
csv_file.writerow(header)
csv_file.writerows(data_rows)
我該怎么辦?這是zabbix文檔: https : //www.zabbix.com/documentation/3.0/manual/api/reference/host/get
我正在網上搜索很長時間。 但是沒用。 請幫助或嘗試給出一些想法來實現這一目標。
提前致謝。
在主機過濾器中,添加status
為0的過濾器,可能是這樣的:
"filter":{
"with_monitored_items": True,
"status": "0"},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.