如何获取启用zabbix的主机,通过使用API

How get zabbix enabled host,Through the use of API

这是我的代码,它可以获得所有host.I只需要启用主机。

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 doc: https://www.zabbix.com/documentation/3.0/manual/api/reference/host/get

我在网上找了很久。但是没有用。请帮助或尝试提供一些想法如何实现这一目标。

提前致谢。

在您的 host 过滤器中,添加过滤 status of 0,可能像这样:

"filter":{
        "with_monitored_items": True,
        "status": "0"},