Search code examples
pythonapizabbix

How to get host id with host's name? Zabbix


Have hosts' names and whant to get their ids using names. Have list with hosts' names. Try

for host in list_regexed_hosts_names:
   ids = z.do_request(method="host.get", params={
            "output": ["hostid"],
            "filter": {
                "host": host
            }
        })

But id does not works


Solution

  • Your request method seems incorrect as per Python zabbix api and host is expecting an array. So instead of looping each host you can directly give it as array. You can look at the zabbix documentation for more details

    Assuming list_regexed_hosts_names is an array or a list containing hostnames.

    ids = z.do_request('host.get',
                       { 
                       'output' : ['hostid'],
                       'filter' :  { 'host': list_regexed_hosts_names}
                       }
          )