Ad Widget

Collapse

Custom dynamic LLD for RestAPI(HTTP agent)

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cbl
    Junior Member
    • Apr 2025
    • 7

    #1

    Custom dynamic LLD for RestAPI(HTTP agent)


    I'm struggling with finding a tutorial or instructions on creating a Low Level Discovery for a custom device that has a very nice RestAPI.

    There are lots of good videos and instructions around LLD, however they all use the Zabbix Agent or other pre-built data collection items which fail to explain how to do this from scratch.


    Basically my RestAPI call comes back with a list of dictionaries(I think those are the right terms). Which may have one item in the list, or several. The need to to dynamically pull in one item from the dictionary, from each item in the list....even if that is ONE item or MULTIPLE. As some of our equipment has one, and some have multiple of these.


    For things that have only ONE per device, it's super easy to create an item in the template using the HTTP agent. The complexity is where there are possibly multiple. I *think* the answer is LLD and setting up the right Item Prototype.
  • Answer selected by cbl at 21-05-2025, 15:25.
    SanMonitor
    Member
    • Aug 2022
    • 48

    Hi cbl,

    First, you should create a discovery rule. Make id dependent on the 'master' item that gives you the JSON. The key you can choose freely.

    Secondly, you create an item prototype. This should also be dependent on the 'master item'. The key you can choose but you should end it with [{#SNMPINDEX}] so for example: client.name[{#SNMPINDEX}]
    Then, go to the tab preprocessing. Here you have to add a JSONPath that will filter your data. It depends on how exactly your JSON is structured (feel free to share if you can) but it will look something like this:
    $.[?(@.SNMPINDEX=="{#SNMPINDEX}")].name (if for example you have an item in your JSON called name)

    If you have another unique identifier for your items in the JSON, you can add these in the LLD macro tab under your discovery rule. Just give an macro name, ex. {#CLIENT.ID} and give the jsonpath for the item ex. $.["ID"]. Then you can also use this macro in the itemkey (only if it's unique) and the preprocessing for this item.

    I always use this site to test my jsonpath > JSONPath and object-path online evaluator

    Comment


    • cbl
      cbl commented
      Editing a comment
      Thanks!

      I think i might have it working now. Still working on it, but wanted to reply...first that I appreciate the response.

      The one thing I'll add to the above, for anyone coming across this later is as follows:
      In the Discovery Rule {#SNMPINDEX} is created as an LLD MACRO.

      The LLD MACRO is what does the discovery dynamically. For instance your looking at hard drives and have 4 hard drives. It will "loop though" the Item Prototype 4 times creating 4 items under your host. You want the LLD MACRO to be the unique identify, say the drive number. So in this example I'll point to the SNMP OID or JSON PATH for the drive ID which is 0 through 3 (The first drive is drive zero)
  • SanMonitor
    Member
    • Aug 2022
    • 48

    #2
    Hi cbl,

    the data you get from you restapi, what format is the response in?
    Ideally this would be json as you can then perform the lld discovery on this.

    Comment

    • cbl
      Junior Member
      • Apr 2025
      • 7

      #3
      Originally posted by SanMonitor
      Hi cbl,

      the data you get from you restapi, what format is the response in?
      Ideally this would be json as you can then perform the lld discovery on this.
      Thanks for the reply.

      Yes, JSON.
      Yes, I agree, LLD is the right way to build these out dynamically.

      As my original question stated; Thus far I've failed to locate a good example of LLD dynamic discovery on RestAPI endpoints parsing that JSON to dynamically create the appropriate ITEMS.
      All of the examples (written and video) I've found use either SNMP or Agent collection items, which my lack of Zabbix experience is failing to translate to RestAPI/JSON collection.

      Comment

      • SanMonitor
        Member
        • Aug 2022
        • 48

        #4
        Hi cbl,

        First, you should create a discovery rule. Make id dependent on the 'master' item that gives you the JSON. The key you can choose freely.

        Secondly, you create an item prototype. This should also be dependent on the 'master item'. The key you can choose but you should end it with [{#SNMPINDEX}] so for example: client.name[{#SNMPINDEX}]
        Then, go to the tab preprocessing. Here you have to add a JSONPath that will filter your data. It depends on how exactly your JSON is structured (feel free to share if you can) but it will look something like this:
        $.[?(@.SNMPINDEX=="{#SNMPINDEX}")].name (if for example you have an item in your JSON called name)

        If you have another unique identifier for your items in the JSON, you can add these in the LLD macro tab under your discovery rule. Just give an macro name, ex. {#CLIENT.ID} and give the jsonpath for the item ex. $.["ID"]. Then you can also use this macro in the itemkey (only if it's unique) and the preprocessing for this item.

        I always use this site to test my jsonpath > JSONPath and object-path online evaluator

        Comment


        • cbl
          cbl commented
          Editing a comment
          Thanks!

          I think i might have it working now. Still working on it, but wanted to reply...first that I appreciate the response.

          The one thing I'll add to the above, for anyone coming across this later is as follows:
          In the Discovery Rule {#SNMPINDEX} is created as an LLD MACRO.

          The LLD MACRO is what does the discovery dynamically. For instance your looking at hard drives and have 4 hard drives. It will "loop though" the Item Prototype 4 times creating 4 items under your host. You want the LLD MACRO to be the unique identify, say the drive number. So in this example I'll point to the SNMP OID or JSON PATH for the drive ID which is 0 through 3 (The first drive is drive zero)
      Working...