Ad Widget

Collapse

Visible Name in Inventory Name field using the API for discovered hosts

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Visible Name in Inventory Name field using the API for discovered hosts

    New to Zabbix -- I think there are a couple of ways to solve this problem and I'm striking out on all of them. I'm using Zabbix v4.2 and have integrated it with VMware vSphere v6.5, which is managing a two node cluster with approximately 150 VMs.

    My objective is to automate the process for creating a map of discovered hosts using the Zabbix API. I have most of it working but would like to use the Icon Mapping/Regular Expression feature to auto-select the appropriate icon based on the discovered hosts' Visible Name. It seems the only way to do this is to have the Visible Name assigned to a field in the hosts' inventory for the Icon Mapping feature.

    Method 1: Use host.update via API
    The host update syntax I'm using to test the functionality is the following:
    zapi.host.update({"hostid": 10952, "inventory_mode": 0, "inventory": {"name": "Router 10"},}]

    I've tested this syntax against regular hosts (non-discovered hosts) and it works fine.

    The error I receive for the syntax above is following:
    zabbix_api.ZabbixAPIException: (u'Error -32500: Application error., Cannot update "inventory_mode" for a discovered host "501a2a20-60c3-7d91-b3c0-f0fad90ef59e". while sending {"params": {"hostid": "10952", "inventory_mode": 0, "inventory": [{"name": "Router 10"}]}, "jsonrpc": "2.0", "method": "host.update", "auth": "b86e2b4da0f641c3f6c78546ead95bc0", "id": 2}', -32500)

    I have tried altering the Default Host Inventory Mode to "Manual" under Administration --> Other. I tried deleting all discovered hosts and re-discovered them and that didn't help.
    I tried to set the Discover VMware VMs --> Host prototype template to both Manual and Automatic, and that didn't help either.

    Method 2: Using Items to populate the Inventory Name Field
    Using the "Template VM VMware Guest" and navigating to Items, I tried creating new items as well as use existing items to populate the Name Field, which did work, but the values were for uptime, Cluster Name, CPU usage, etc. I was unable to find any keys that would display a discovered hosts' Visible Name (aka Virtual Machine Name, #VM.NAME, etc).

    If someone can provide some assistance for how to get a discovered hosts' Visible Name populated to the Inventory Name field without having to manually enter it for each host, It would be much appreciated.


    #2
    I resolved my issue via Method 1.

    Solution: I got it working by modifying the syntax to the following: zapi.host.update({"hostid": hostidvariable, "inventory": {"name": visiblenamevariable},})

    It seems the Inventory API syntax in the Zabbix documentation is wrong, at least for discovered hosts.

    Comment

    Announcement

    Collapse
    No announcement yet.
    Working...
    X