Ad Widget

Collapse

Parse JSON response

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lhirdman
    Junior Member
    • Oct 2019
    • 1

    #1

    Parse JSON response

    Hi!
    First time poster here, not that experienced with Zabbix. I'm currently working in a project to migrate from Shinken/Nagios to Zabbix 4.2.

    I'm monitoring some applications with a health check page returning health status of application and also showing dependencies. I have tried to get both the health status and the message from the page to show up in the same item or trigger to no avail.
    The item I created is an HTTP agent check and the format of the health check page looks like this:
    Code:
    {
        "dependencies": [
            {
                "isHealthy": true,
                "message": "App1 is connected and configured correctly",
                "name": "App1 name"
            },
            {
                "isHealthy": false,
                "message": "App2 is b0rked",
                "name": "App2"
            },
            {
                "isHealthy": true,
                "message": "App3 is connected and configured correctly",
                "name": "App3"
            },
            {
                "isHealthy": false,
                "message": "App4 doesn't like your code",
                "name": "App4 name"
            }
        ],
        "isHealthy": false,
        "message": "App2 and App4 failed",
        "name": "MainApp",
        "version": "1.1.4-prod"
    }
    What I would like to do is to at least be able to monitor the Health status of main app ($.isHealthy) and in the same time publish the content of $.message.
    When I create an item that reads the output from the health check and add a preprocessor to it any subsequent preprocessor inherits the output of the previous preprocessor so I can't extract more than one key, value pair that way.
    Is it possible to create macros based on different part of the json so I could use them when describing the problem in a trigger?
    I have googled around but not found anything substantial only to use external scripts or userchecks which I will do if there's no way to extract multiple fields from the json into the item or a trigger.

  • troffasky
    Senior Member
    • Jul 2008
    • 567

    #2
    You want an HTTP agent item first to contain the entire blob of JSON.
    Then for each parameter you want to extract, create a Dependent Item with your HTTP agent item as the Master. Give it a JSON Path preprocessing step, something like $.dependencies[0].isHealthy for App1 [or are they numbered from 1? can't remember].

    If somebody knows an easy way to populate [or, "low level discover"] all the potential dependent items with preproc steps, I'd like to hear it.

    Edit: just re-read your post. Seems like you actually already know how to do the JSON Path bit.
    Last edited by troffasky; 25-01-2020, 01:24.

    Comment

    • Hamardaban
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • May 2019
      • 2713

      #3
      The key phrase is: create as many dependent items, how many metrics you need to track.

      Comment

      • gert.derouck
        Member
        • Jan 2020
        • 69

        #4
        For the dependent items, you could use LLD with JSON Path preprocessing step and LLD macro's.


        Low-level discovery now accepts optional user-defined LLD macros with a custom path specified in JSONPath syntax.
        Example: I use this for discovering Jenkins jobs via its API.

        Comment

        Working...