'Add Bulk Hosts SNMP to Zabbix (py-zabbix)

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!



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Iron Bishop