Ad Widget

Collapse

Problem with LLD macros and JSON without indexes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Oscar Garcia
    Junior Member
    • Oct 2015
    • 6

    #1

    Problem with LLD macros and JSON without indexes

    Hello all. We have Zabbix 5.0 LTS.

    We obtain the following JSON data through a REST service:
    Code:
    {
      "content": [
        {
          "type": "TYPE",
          "availableHostnames": [
            "host1",
            "host2",
            "host3",
            "host4"
          ]
        }
      ]
    ​}
    We are using the following Preprocesing JSONPath:
    Code:
    $.content[?(@.type == "TYPE")].availableHostnames.first()
    And tried the following LLD Macros:
    Code:
    $.first() (0 items generated)
    $.[*] (0 items generated)
    $.. (error parsing JSONPath)
    $. (error parsing JSONPath)
    But neither works to assign the content of each element obtained in the JSON to a LLD macro.

    (*) We have also tried using the rule without "first()" and "$.first()", but it discovers a single element whose macro value is ["host1","host2","host3","host4"].

    How can I get the data for each element contained in the "availableHostnames" attribute so that each one creates a discovered item?

    Tested combinations:
    • Preprocessing step (JSONPath): $.content[?(@.type == "TYPE")].availableHostnames.first()
      • LLD Macro {#TEST} (result):
        • $. (Cannot process LLD macro "{#TEST}": jsonpath was unexpectedly terminated.).
        • $.. (Cannot process LLD macro "{#TEST}": jsonpath was unexpectedly terminated.).
        • $.first() (0 items created)
        • Code:
          $.[*]
          (0 items created)
    • Preprocessing step (JSONPath): $.content[?(@.type == "TYPE")].availableHostnames
      • LLD Macro {#TEST} (result):
        • Code:
          $.[*]
          (1 item created):
          • Ping ["host1","host2","host3","host4"] (icmpping["["host1","host2","host3","host4"]"])
        • $.first() (1 item created):
          • Ping host1 (icmpping[host1])

    I attach test host: zbx_export_TEST LLD.xml

    Thank you very much for your help.​
    Last edited by Oscar Garcia; 17-01-2023, 16:18.
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    $.content[?(@.type == "TYPE")].availableHostnames
    gives you result
    [
    [
    "host1",
    "host2",
    "host3",
    "host4"
    ]
    ]​
    kind of double array (not my real topic, I always confuse those arrays, element and objects.. ) so you probably should refer to inner one in LLD path as $.[0]. At least if I test here https://www.javainuse.com/jsonpath it works... if you use[*] it will return everything unchanged...

    and you cannot really use first(), as it limits to first object, but you need all of them...

    Comment

    • Oscar Garcia
      Junior Member
      • Oct 2015
      • 6

      #3
      Originally posted by cyber
      $.content[?(@.type == "TYPE")].availableHostnames
      gives you result

      kind of double array (not my real topic, I always confuse those arrays, element and objects.. ) so you probably should refer to inner one in LLD path as $.[0]. At least if I test here https://www.javainuse.com/jsonpath it works... if you use[*] it will return everything unchanged...

      and you cannot really use first(), as it limits to first object, but you need all of them...
      If i use $.[0] then only the first element appears as discovered item. Using $.[1] the second one, and so on.

      I need to discover 4 items, an element with each element of the array (ping host1, ping host2, ping host3, ping host4).

      Thank you for answer.

      Comment

      • Oscar Garcia
        Junior Member
        • Oct 2015
        • 6

        #4
        Any ideas? Thanks.

        Comment

        Working...