Ad Widget

Collapse

JSONpath preprocessing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Noobz
    Senior Member
    • Jun 2020
    • 105

    #1

    JSONpath preprocessing

    Hello,

    I am extracting a JSON data set and trying to run discovery with LLD macros and item prototypes.

    I believe it will work as is, except some of the JSON objects have brackets in the name such as "Voltage(V)" and I simply can't get past this as is due the following error:
    1. Failed: cannot extract value from json by path "$.[?(@.Intf == "{$IF}")].Voltage"(V)"": unsupported construct in jsonpath starting with: ""(V)""


    I have tried quotes around the entire name, only around the brackets, escaping the brackets.

    I'm going to edit the script to simply remove the brackets and contained text as it isn't important; so this is more of a "if this was critical, how do I make this work?" kind of question.

    Any ideas?

    Cheers
  • Noobz
    Senior Member
    • Jun 2020
    • 105

    #2
    Data example:
    Code:
    {
    "Intf": "0/1",
    "Detection": "Unknown",
    "Class": "Unknown",
    "Consumed": "0.00",
    "Voltage": "0.00",
    "Current": "0.00",
    "WattHr": "0.00",
    "Temperature": "N/A"
    },
    {
    "Intf": "0/2",
    "Detection": "Unknown",
    "Class": "Unknown",
    "Consumed": "0.00",
    "Voltage": "46.81",
    "Current": "0.00",
    "WattHr": "0.00",
    "Temperature": "N/A"
    },
    Using online JSONpath evaluator, the path -
    $.[?(@.Intf == "0/2")].Voltage
    For example will return "46.81"

    I have an LLD macro {#IF} = #..Intf

    So the hope was for use the JSON path preprocessing in the item prototype such as
    $.[?(@.Intf == {$IF})].Voltage

    However if I have quotes around the macro I get "no data matches the specified path" which I assume is because it is being parsed but not interpreted correctly.

    Comment

    • ISiroshtan
      Senior Member
      • Nov 2019
      • 324

      #3
      Hey mate.

      If you really using
      Code:
      $.[?(@.Intf == {$IF})].Voltage
      then could you change user macro {$IF} for LLD macro {#IF} and try again?

      Comment

      • Noobz
        Senior Member
        • Jun 2020
        • 105

        #4
        Originally posted by ISiroshtan
        Hey mate.

        If you really using
        Code:
        $.[?(@.Intf == {$IF})].Voltage
        then could you change user macro {$IF} for LLD macro {#IF} and try again?
        Apologies - I ended up confusing myself for a while in between trying everything I could think of.
        It is in fact an LLD macro ({#IF}) - I corrected this within Zabbix after copy pasting it here, it made no difference.

        Comment

        • pardhak25
          Junior Member
          • Mar 2021
          • 6

          #5
          Try LLD macro {#IF} = $.Intf (single dot) in json path this should remove the []​

          Comment

          Working...