将批量主机 SNMP 添加到 Zabbix (py-zabbix)

发布于 2025-01-10 23:44:55 字数 1363 浏览 0 评论 0原文

因此,我正在尝试将 Cisco 网络交换机批量添加到 Zabbix,这是迄今为止我所想到的。遇到这个问题时,尽管我尝试了多种不同的途径来尝试让 API 正常工作,但我还是收到了“传递给函数的参数无效”错误。

这是有问题的代码。在我的环境中,我们不依赖 DNS,因此在阅读了一点内容后,我不认为 DNS 字段是必需的,但除此之外,我只是感到困惑。

from pyzabbix import ZabbixAPI,ZabbixAPIException
# Create ZabbixAPI class instance
with ZabbixAPI(url=zabbix_url, user=zabbix_user, password=passwd) as zapi:
    try:
        # Get all monitored hosts
        zapi.host.create(
            host=switch_name,
            interfaces={"type": 2,"main": 1,"useip": 1,"ip": switch_ip,"dns": "","port": "161"},
            details={"version":2,"bulk":1,"community":zabbix_snmp_community},
            groups={"groupid": site_group_id,},
            template={"templateid":cisco_template_id},
            inventory_mode=-1
        )
    except ZabbixAPIException as e:
        print("Error",e)

这是我收到的错误:

Error {'code': -32602, 'message': 'Invalid params.', 'data': 'Incorrect arguments passed to function.', 'json': "{'jsonrpc': '2.0', 'method': 'host.create', 'params': {'host': '0000', 'interfaces': {'type': 2, 'main': 1, 'useip': 1, 'ip': '0000', 'dns': '', 'port': '161'}, 'details': {'version': 2, 'bulk': 1, 'community': '0000'}, 'groups': {'groupid': '0000'}, 'template': {'templateid': '0000'}, 'inventory_mode': -1}, 'id': '1', 'auth': '********'}"}

非常感谢任何帮助!

So I'm attempting to add Cisco network switches in bulk to Zabbix, this has been so far what I've come up with. Trouble with this, despite me trying numerous different avenues to try to get the API to work, I'm getting an invalid argument's passed to function error.

Here is the code in question. In my environment, we don't rely on DNS, so after reading a little bit, I don't think that the DNS field is required, but beyond that, I'm just flat confused.

from pyzabbix import ZabbixAPI,ZabbixAPIException
# Create ZabbixAPI class instance
with ZabbixAPI(url=zabbix_url, user=zabbix_user, password=passwd) as zapi:
    try:
        # Get all monitored hosts
        zapi.host.create(
            host=switch_name,
            interfaces={"type": 2,"main": 1,"useip": 1,"ip": switch_ip,"dns": "","port": "161"},
            details={"version":2,"bulk":1,"community":zabbix_snmp_community},
            groups={"groupid": site_group_id,},
            template={"templateid":cisco_template_id},
            inventory_mode=-1
        )
    except ZabbixAPIException as e:
        print("Error",e)

Here is the error I'm getting in return:

Error {'code': -32602, 'message': 'Invalid params.', 'data': 'Incorrect arguments passed to function.', 'json': "{'jsonrpc': '2.0', 'method': 'host.create', 'params': {'host': '0000', 'interfaces': {'type': 2, 'main': 1, 'useip': 1, 'ip': '0000', 'dns': '', 'port': '161'}, 'details': {'version': 2, 'bulk': 1, 'community': '0000'}, 'groups': {'groupid': '0000'}, 'template': {'templateid': '0000'}, 'inventory_mode': -1}, 'id': '1', 'auth': '********'}"}

Any help is more than appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

°如果伤别离去 2025-01-17 23:44:55

你的问题:“细节”应该是“接口”的属性。

请参阅示例“创建具有 SNMP 接口的主机”: https://www.zabbix.com/documentation/current/it/manual/api/reference/host/create

注意:我更喜欢禁用(设置为 0)批量 SNMP。

Your problem: "details" should be a property of "interfaces".

See the example "Creating a host with SNMP interface": https://www.zabbix.com/documentation/current/it/manual/api/reference/host/create

Note: i prefer to disable (set to 0) bulk SNMP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文