Ad Widget

Collapse

Process Json Response

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nik-k
    Junior Member
    • Oct 2023
    • 4

    #1

    Process Json Response

    Hello everyone,

    I'm trying to process the following JSON return with Zabbix:
    Example response:
    Code:
     [
       {
          "id":"mow.DE-BY-AB-W169-20231019-001",
          "payload":{
             "version":5,
             "type":"ALERT",
             "id":"mow.DE-BY-AB-W169-20231019-001",
             "hash":"2e7a0bfa5bf2a480521b79f272e1d134336fedbe5367fac145378d15fb4f3cef",
             "data":{
                "headline":"Trinkwasser-Verunreinigung - Mönchberg",
                "provider":"MOWAS",
                "severity":"Severe",
                "urgency":"Immediate",
                "msgType":"Update",
                "transKeys":{
                   "event":"BBK-EVC-045"
                },
                "area":{
                   "type":"ZGEM",
                   "data":"8786,100001"
                },
                "valid":true
             }
          },
          "i18nTitle":{
             "de":"Trinkwasser-Verunreinigung - Mönchberg"
          },
          "sent":"2023-10-19T18:20:53+02:00"
       },
       {
          "id":"mow.DE-BY-R-SE084-20231020-84-000",
          "payload":{
             "version":5,
             "type":"ALERT",
             "id":"mow.DE-BY-R-SE084-20231020-84-000",
             "hash":"818682e7c089b229d81e08a5c2ba330659727ef187440c7e5cb5a55580d4eb1c",
             "data":{
                "headline":"Trinkwasser-Verunreinigung - Mönchberg",
                "provider":"MOWAS",
                "severity":"Severe",
                "urgency":"Immediate",
                "msgType":"Update",
                "transKeys":{
                   "event":"BBK-EVC-045"
                },
                "area":{
                   "type":"ZGEM",
                   "data":"8786,100001"
                },
                "valid":true
             }
          },
          "i18nTitle":{
             "de":"Trinkwasser-Verunreinigung - Mönchberg"
          },
          "sent":"2023-10-20T13:24:07+02:00"
       }
    ]
    ​
    ​​
    Unfortunately, an attempt to create a new item fails when I select JSON Data:





    I can only create the item if I select Raw Data.

    I then created a template as described here:


    The item prototype looks like this:
    Code:
    $..[?(@.id == "{#NINAWARNING}")].payload.data
    When testing the item prototype I now get the following error:





    What am I doing wrong?

    Thanks in advance,

    nik-k​
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    This looks like already generated alert by some 3rd party system. What is it that you want to get out of this? You mention item prototypes, but for what exactly? If this is already an alert by some system, then you probably should just parse out some of it and formulate a readable alert and save it as some item value. Some JS preprocessing would help you here.

    I just cannot understand, what you are trying to do...​

    Comment

    • nik-k
      Junior Member
      • Oct 2023
      • 4

      #3
      Hello cyber!

      Many thanks for your response.
      I get this json object from this api:

      An example would be the following call:
      https://warning.bund.de/api31/dashbo...760000000.json

      From this return I need the values below payload->data(type, urgency, headline, severity, valid) and the value of sent.
      My goal is to display the relevant part of these warnings in a widget on a dashboard​
      Last edited by nik-k; 27-10-2023, 14:42.

      Comment

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

        #4
        I still think jsonpath will not help you here (or any of item prototypes).. it is meant to extract one or many similar elements from json... but you need to pick multiple values and want to reconstruct it into somekind of "own" event text... You probably need JS preprocessing here instead.. to take your input apart, extract what you need and put it back together as you need...

        Comment

        • nik-k
          Junior Member
          • Oct 2023
          • 4

          #5
          Hi cyber, thank you very much for your answer.
          I thought it was pretty much the same thing here, only that the jsonobject looks a little different:

          It's a shame, maybe I'm just expressing myself poorly.​

          Comment

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

            #6
            not exactly same... There was an unknown number of "companies" with couple of metrics... which will be updated regularily.
            Here you have unknown number of not repeating events, which will not allow us to do any good item prototyping etc...

            Comment

            Working...