Ad Widget

Collapse

zabbix 6.0 change visible name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acevizci
    Junior Member
    • Feb 2023
    • 6

    #1

    zabbix 6.0 change visible name

    Hello,
    We are using zabbix 6.0. Can we use item name instead of Visible Name, is there a method for this? Do this as a macro vs. Is there a way to do it with
    Thanks in advance for your help.​
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    Too few info.... Can you elaborate, what do you want to achieve... ?

    Comment

    • acevizci
      Junior Member
      • Feb 2023
      • 6

      #3
      Hello,
      I want to print an item in the template in the hostname field or the visible name field.​
      thanks.

      Comment

      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #4
        Your host has possibly many items, which one should be used?



        Only way to use any macros in hostname is LLD macros in host prototype name...

        But your use case is still unclear..

        Comment

        • acevizci
          Junior Member
          • Feb 2023
          • 6

          #5
          Hi Cyber,

          At first, thank you for your interest. We were able to achieve our goal with the following python code

          Thank you for your support

          thanks.

          Code:
          #!/usr/bin/python
          
          from pyzabbix import ZabbixAPI
          
          USER = 'username'
          PSWD = 'Password'
          URL = 'http://zabbix server/zabbix/api_jsonrpc.php'
          
          # init the API and Authenticate
          zapi = ZabbixAPI(URL, timeout=5)
          zapi.login(USER, PSWD)
          
          # Get all hosts in the hg_kiosks host group
          group = zapi.hostgroup.get(filter={"name": "Hostgroup Name"}, output=["groupid"])
          group_id = group[0]["groupid"]
          
          # Get all hosts in the hg_kiosks host group
          for hosts in zapi.host.get(
          output=['extend'],
          groupids=[group_id],
          selectInventory=['inventory item name']
          ):
          print(hosts['hostid'], hosts['inventory']['inventory item name']) # For debugging
          
          # Update the host's visible name as taken from the inventory
          if 'inventory' in hosts and hosts['inventory'].get('inventory item name'):
          name = hosts['inventory'].get('inventory item name')
          zapi.host.update(
          hostid=hosts['hostid'],
          name=name
          )
          else:
          if 'inventory' in hosts:
          print(f"Skipping host {hosts['hostid']} because MAC address is missing or empty")
          else:
          name = hosts.get('name') or hosts['host']
          zapi.host.update(
          hostid=hosts['hostid'],
          name=name
          )
          Last edited by acevizci; 10-05-2023, 00:08.

          Comment

          Working...