Ad Widget

Collapse

LLD JSONPath Bug or User Syntax Error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xetrovwf
    Junior Member
    • Aug 2022
    • 4

    #1

    LLD JSONPath Bug or User Syntax Error?

    I'm working on a template that retrieves information via API. The API requires you to authenticate with user/password, and it sends back an API key that is to be appended to the headers of all subsequent requests. I have created an item to send the user/pass, and return the response headers as JSON. I am them trying to use a Discovery LLD, to parse this reply and save the API key as a macro, to be used in all further requests. When testing the JSONPath used to parse the response (in preprocessing), I am getting the key I require, but when using this same path in LLD, I get an error.

    JSON returned from item query:

    Code:
    {"header":{"HTTP/1.1 201 Created":"","Content-Length":"6492","Content-Type":"application/xml; charset=utf-8","Location":"https://x.x.x.x5:9398/api/sessionMngr/8af2d345-978f-44f2-93da-91bed0e98c6e","Server":"Microsoft-HTTPAPI/2.0","X-RestSvcSessionId":"OGFmMmQzNDUtOTc4Zi00OWXyLTkzXGEtOTFiZWQwZTk4YzZl","Set-Cookie":"X-RestSvcSessionId=OGFmMmQzNDUtOTc4Zi00OWYyLTkzZGEtOTFiZWQwZTk4YzZl; path=/api","Date":"Mon, 22 Aug 2022 15:35:28 GMT"}}
    Below is a similar response as above, just formatted to make it easier to digest:

    Code:
    {"header":
         {
         "HTTP/1.1 201 Created":"",
         "Content-Length":"6492",
         "Content-Type":"application/xml; charset=utf-8",
         "Location":"https://x.x.x.x:9398/api/sessionMngr/3e43de8c-229e-4b6d-8c62-164e4136a990",
         "Server":"Microsoft-HTTPAPI/2.0",
         "X-RestSvcSessionId":"M2UzM2RlOXMtMjI5ZS00YjZkLThXNjI tMTY0ZTQxMzZhOTkw",
         "Set-Cookie":"X-RestSvcSessionId=M2UzM2RlXGMtMjI5ZS00YjZkLThjNjItM TY0ZTQxMzZhOTkw; path=/api",
         "Date":"Fri, 19 Aug 2022 18:14:27 GMT"
         }
    }
    JSONPath: $['header']['X-RestSvcSessionId']
    Error: "Cannot find the "data" array in the received JSON object."

    I've tried many iterations over the past 4 days, and cannot get this to work for the life of me. Can anyone assist?
    Last edited by xetrovwf; 22-08-2022, 23:20.
  • ISiroshtan
    Senior Member
    • Nov 2019
    • 324

    #2
    Pretty sure your issue with LLD is fact that is expects to recieve an JSON array to itirate through. So it can be either like:
    {"data": [ RESULTS_JSON_HERE ]}
    or like:
    [ RESULTS_JSON_HERE ]

    You can try to add preprocessing to your item to transform JSON to be inline with what is expected.
    For example input data for LLD could be:

    Code:
    [
        {"header":
             {
             "HTTP/1.1 201 Created":"",
             "Content-Length":"6492",
             "Content-Type":"application/xml; charset=utf-8",
             "Location":"https://x.x.x.x:9398/api/sessionMngr/3e43de8c-229e-4b6d-8c62-164e4136a990",
             "Server":"Microsoft-HTTPAPI/2.0",
             "X-RestSvcSessionId":"M2UzM2RlOXMtMjI5ZS00YjZkLThXNjI tMTY0ZTQxMzZhOTkw",
             "Set-Cookie":"X-RestSvcSessionId=M2UzM2RlXGMtMjI5ZS00YjZkLThjNjItM TY0ZTQxMzZhOTkw; path=/api",
             "Date":"Fri, 19 Aug 2022 18:14:27 GMT"
             }
        }
    ]
    And JSON path for LLD macro keep as you have it: $['header']['X-RestSvcSessionId']

    I think should work this way

    Comment

    • xetrovwf
      Junior Member
      • Aug 2022
      • 4

      #3
      I think this may have worked.

      That said, what is the best way to test for the value of the macro it should be setting? I attempted to pass this value in the header of another item request, and it fails authorization. I created another script item, passed the macro to it as a parameter, and had it return the same value so I could check it against the log. It returned {#API.TOKEN} instead of the string. I want to say that the macro isnt working, but Im also not sure if the macro can be passed as a script parameter in the first place.

      Comment

      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #4
        You can use LLD macros in key parameters in prototype... https://www.zabbix.com/documentation...ros/lld_macros

        Comment

        • xetrovwf
          Junior Member
          • Aug 2022
          • 4

          #5
          Ah, prototypes! Thank you!
          Last edited by xetrovwf; 24-08-2022, 17:48.

          Comment

          Working...