Ad Widget

Collapse

getting hostnames out of Zabbix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pmurtey
    Member
    • Mar 2020
    • 91

    #1

    getting hostnames out of Zabbix

    Has anyone been able to successfully retrieve all the host names of all the host severs that are in zabbix using the API? If so, can you please share? We have tried using the host.get method shown in the documentation, but all it returns is a bunch of host ID numbers. TIA
  • Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1781

    #2
    In Python: https://majornetwork.net/2022/10/bas...-and-pyzabbix/

    Let us know how your API call looked like, someone surely will be able to tell how to improve that.

    Markku

    Comment

    • LukeAB93UK
      Member
      Zabbix Certified Specialist
      • Jun 2023
      • 72

      #3
      Originally posted by pmurtey
      Has anyone been able to successfully retrieve all the host names of all the host severs that are in zabbix using the API? If so, can you please share? We have tried using the host.get method shown in the documentation, but all it returns is a bunch of host ID numbers. TIA
      Hello,

      Here is a code snippet from a Python script of mine that exports a list of hosts based on a host group that may be useful to use

      Code:
          # Get devices from the specified host group
          host_payload = {
              'jsonrpc': '2.0',
              'method': 'host.get',
              'params': {
                  'output': ['hostid', 'name'],
                  'groupids': [host_group_id],
              },
              'auth': api_token,
              'id': 2,
          }
          host_response = requests.post(zabbix_url, data=json.dumps(host_payload), headers=headers, verify=False)
          host_result = host_response.json()
          if 'result' in host_result:
              # Get the list of devices
              devices = [host['name'] for host in host_result['result']]

      Comment

      Working...