Ad Widget

Collapse

Assistance with JSON data capture

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KieranDavies
    Junior Member
    • Dec 2021
    • 3

    #1

    Assistance with JSON data capture

    Hello,

    I am seeking assistance with capturing JSON data. Despite trying various methods, I haven't been able to achieve the desired results.

    Objective:
    I want to create a unified item that captures the JSON response, which is working fine. Additionally, I am looking to implement an auto-discovery mechanism (if feasible) to identify 'company' values, as the data changes daily. Subsequently, I need to store 'load' and 'requests' metrics for each dynamically discovered company.

    Example Data Output:


    Code:
    {
    "data": [
    {"company": "Company 001", "load": 0.2, "requests": 2273},
    {"company": "Company 002", "load": 0.2, "requests": 865},
    {"company": "Company 003", "load": 0.1, "requests": 518}
    ]
    }

    I would greatly appreciate your assistance with this task, as my intention is to maintain this data within Zabbix without the need to push it to an external database.

    Best regards,


  • Answer selected by KieranDavies at 25-10-2023, 15:54.
    cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    This one worked... Couple of changes to preprocessing..

    See..
    Click image for larger version

Name:	image.png
Views:	399
Size:	26.1 KB
ID:	472985
    Click image for larger version

Name:	image.png
Views:	390
Size:	14.1 KB
ID:	472986

    Comment

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

      #2
      EDIT: removed all that or someone might think its useful..
      Last edited by cyber; 25-10-2023, 14:48.

      Comment

      • KieranDavies
        Junior Member
        • Dec 2021
        • 3

        #3
        Hi Cyber, thank you for your input - When I try this method I get "Cannot create item: item with the same key "load[{#COMPANY}]" already exists." after discovery has been attempted.

        I have since got this working by using a python script and a combination of Zabbix API and Zabbix_Sender however it would be great to get this working just from inside Zabbix UI.

        Comment

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

          #4
          Well I did not do full end to end test with this.. just tested item preprocessing etc. let me check again.

          Comment

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

            #5
            This one worked... Couple of changes to preprocessing..

            See..
            Click image for larger version

Name:	image.png
Views:	399
Size:	26.1 KB
ID:	472985
            Click image for larger version

Name:	image.png
Views:	390
Size:	14.1 KB
ID:	472986

            Comment

            • KieranDavies
              Junior Member
              • Dec 2021
              • 3

              #6
              Hi Cyber, Great, thank you for your help on this
              Last edited by KieranDavies; 25-10-2023, 15:54.

              Comment

              • nik-k
                Junior Member
                • Oct 2023
                • 4

                #7
                I have a very similar problem, for which I have already created a thread, but unfortunately nothing has come back yet.
                In my case, for example, a JSON return that I get with the http agent can look like this:
                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"
                   }
                ]​
                ​
                What is interesting to me are the values under payload->data(headline,severity,urgency,area) and sent.

                I can only create the item if I select "Raw data" for the Request body type.

                I experimented a bit under Items->Preprocessing and finally created the following JSONPath:



                I get the following result if I check "Get value from host"



                Code:
                [
                   {
                      "hash":"2e7a0bfa5bf2a480521b79f272e1d134336fedbe5367fac145378d15fb4f3cef",
                      "id":"mow.DE-BY-AB-W169-20231019-001",
                      "type":"ALERT",
                      "version":5,
                      "data":{
                         "headline":"Trinkwasser-Verunreinigung - Mönchberg",
                         "urgency":"Immediate",
                         "valid":true,
                         "transKeys":{
                            "event":"BBK-EVC-045"
                         },
                         "provider":"MOWAS",
                         "area":{
                            "type":"ZGEM",
                            "data":"8786,100001"
                         },
                         "msgType":"Update",
                         "severity":"Severe"
                      }
                   },
                   {
                      "hash":"818682e7c089b229d81e08a5c2ba330659727ef187440c7e5cb5a55580d4eb1c",
                      "id":"mow.DE-BY-R-SE084-20231020-84-000",
                      "type":"ALERT",
                      "version":5,
                      "data":{
                         "headline":"Trinkwasser-Verunreinigung - Mönchberg",
                         "urgency":"Immediate",
                         "valid":true,
                         "transKeys":{
                            "event":"BBK-EVC-045"
                         },
                         "provider":"MOWAS",
                         "area":{
                            "type":"ZGEM",
                            "data":"8786,100001"
                         },
                         "msgType":"Update",
                         "severity":"Severe"
                      }
                   }
                ]


                Unfortunately, everything I've tried so far from here has failed. I have already tried the steps used here, but unfortunately without success.
                It would be really great if someone could point me in the right direction.​

                Comment

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

                  #8
                  I answered to your thread.. lets leave this one as it is... no need to mix up things.

                  Comment

                  Working...