Ad Widget

Collapse

API: Find all Items discovered by discovery rule in a template.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pato
    Junior Member
    • Jul 2019
    • 11

    #1

    API: Find all Items discovered by discovery rule in a template.

    I am struggling with this one

    I have Item Prototypes inside a Discovery Rule inside a Template.
    Another template is linked, and that template has linked hosts.

    All these hosts get discovered items, and all works great.

    Now I want to list all these discovered items with the API.
    How I can list them?

    With this I get close
    {
    "jsonrpc": "2.0",
    "method": "item.get",
    "params": {
    "search": {
    "key_": "MY KEY"
    }
    },
    "auth": "token",
    "id": 1
    }

    But of course, it lists other things that where not discovered by this template, and there is no way to filter that list.
    Unfortunatelly I cannot see any type of "Discovered By" where I could put the ID of my Discovery Rules.

    Any ideas?


  • Pato
    Junior Member
    • Jul 2019
    • 11

    #2
    I found a way and learned a few things along the way

    1. Search on Integers is not implemented nor documented as such...?!?! A workaround it to use a filter object
    2. searchWildcardsEnabled is broken/inconsistent it works only under certain conditions

    Code:
    {
       "jsonrpc": "2.0",
       "method": "item.get",
       "params": {
          "output": ["itemid", "selectItemDiscovery"],
          "filter": {
                "status": 1
          },
          "search": {
                "key_": "free.space"
          },
          "searchWildcardsEnabled": false,
          "selectItemDiscovery": ["key_"]
       },
       "auth": "secret",
       "id": 1
    }
    This is good enough but not perfect.
    With selectItemDiscovery, I can pipe it into an external script. Ideally it should be done entirely by the JSON request.
    But I could not find a way to filter/search or do a sub filter/search, and I am not the first one:
    https://www.zabbix.com/forum/zabbix-...-on-query-data

    Anybody a clue?
    Last edited by Pato; 30-07-2019, 20:04.

    Comment

    Working...