将批量主机 SNMP 添加到 Zabbix (py-zabbix)
因此,我正在尝试将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题:“细节”应该是“接口”的属性。
请参阅示例“创建具有 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.