Ad Widget

Collapse

Has anyone monitored data from a json file? I think I'm close to getting it to work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • G0nz0uk
    Member
    • Apr 2021
    • 46

    #1

    Has anyone monitored data from a json file? I think I'm close to getting it to work

    Hello,

    I think I'm close to getting this to work.

    We have a number of host devices (just Linux/Windows machines) that have a json file running on them show some data I need to monitor in Zabbix. I'm testing with just 1 host device at the moment.

    The path to each device is like this:

    Code:
    http://192.168.1.1/pod/v0/metrics.json
    Code:
    {
    "screen_percentage_black": 25,
    "screen_unexpected_size": 0,
    }
    I'm just concentrating on "screen_percentage_black" and trigger a warning if over 50

    So I've created a template

    A test works and can read the the json file:

    Click image for larger version  Name:	image.png Views:	1 Size:	80.7 KB ID:	510204

    Over to the discovery. I created a Dependent item and a key as devices.json.fetch


    LLD:

    Click image for larger version  Name:	image.png Views:	1 Size:	88.5 KB ID:	510206

    Does my key look correct?

    Click image for larger version  Name:	image.png Views:	1 Size:	114.5 KB ID:	510207

    Pre-processing

    I use:

    Code:
    $[?(@.name == '{#HOST.NAME}')].screen_percentage_black.first()
    Click image for larger version  Name:	image.png Views:	1 Size:	77.0 KB ID:	510208



    Now if I go to a host where I've assigned this template to and test I get this error, I was hoping it would return a value of 25 as seen in the json:

    Code:
    cannot extract value from json by path "$[?(@.name == '{#HOST.NAME}')].screen_percentage_black.first()": invalid object format, expected opening character '{' or '[' at: '$[?(@.name == '{#HOST.NAME}')].screen_percentage_black.first()'
    r/zabbix - Has anyone monitored information in a json file on host device?
    Any help would be most appreciated. I think I'm close.

    It seems to accept this though, but I can't seem to get a test trigger working.

    Code:
    $['screen_percentage_black']
    Thanks
    Attached Files
    Last edited by G0nz0uk; 07-01-2026, 20:58.
  • guntis_liepins
    Junior Member
    • Oct 2025
    • 12

    #2
    I want to get idea - why do you use LLD rules instead of network discovery by http ?
    Do you have multiple IPs with

    ...

    each having exacly this json
    {
    "screen_percentage_black": 25,
    "screen_unexpected_size": 0,
    }

    Or your webserver returns JSON with aray of elements?

    Your examples and preprocessing does not add up for me , it seem.

    Comment


    • G0nz0uk
      G0nz0uk commented
      Editing a comment
      I got it all working, I was over complicating it all in the end!

      I now have a discovery question, but I'll raise a different post on that. I need to link this template to a main one, but this json file does exist on all devices so I want to see if I can discover it first then run it, not sure if it's possible.
  • SanMonitor
    Member
    • Aug 2022
    • 48

    #3

    Hey G0nz0uk,
    Your key always has to be unique, if two hosts have the same blackness level value you'll get errors, you also don't want a changing value in your key. Better to use hostname, IP or SNMPINDEX as variable.

    Just like guntis says, can you share a full example of your JSON output? Your preprocessing uses a 'name' variable that we don't see in the sample given.

    Comment

    • irontmp
      Member
      • Sep 2023
      • 36

      #4
      Originally posted by G0nz0uk
      Hello,

      I think I'm close to getting this to work.

      We have several host devices (just Linux/Windows machines) that have a json file running on them show some data I need to monitor in Zabbix. I'm testing with just 1 host device at the moment.

      The path to each device is like this:

      Code:
      http://192.168.1.1/pod/v0/metrics.json
      Code:
      {
      "screen_percentage_black": 25,
      "screen_unexpected_size": 0,
      }
      I'm just concentrating on "screen_percentage_black" and trigger a warning if over 50

      So I've created a template

      A test works and can read the the json file:

      Click image for larger version Name:	image.png Views:	1 Size:	80.7 KB ID:	510204

      Over to the discovery. I created a Dependent item and a key as devices.json.fetch


      LLD:

      Click image for larger version Name:	image.png Views:	1 Size:	88.5 KB ID:	510206

      Does my key look correct?

      Click image for larger version Name:	image.png Views:	1 Size:	114.5 KB ID:	510207

      Pre-processing

      I use:

      Code:
      $[?(@.name == '{#HOST.NAME}')].screen_percentage_black.first()
      Click image for larger version Name:	image.png Views:	1 Size:	77.0 KB ID:	510208



      Now if I go to a host where I've assigned this template and test, I get this error. I was hoping it would return a value of 25 as seen in the JSON, but it behaves differently depending on the data, much like how downloading a file works when you Descargar Minecraft.
      Code:
      cannot extract value from json by path "$[?(@.name == '{#HOST.NAME}')].screen_percentage_black.first()": invalid object format, expected opening character '{' or '[' at: '$[?(@.name == '{#HOST.NAME}')].screen_percentage_black.first()'
      r/zabbix - Has anyone monitored information in a json file on host device?
      Any help would be most appreciated. I think I'm close.

      It seems to accept this though, but I can't seem to get a test trigger working.

      Code:
      $['screen_percentage_black']
      Thanks
      The error happens because your JSON is a single object, not a list of objects. You don’t need a filter based on the host name. You can simply extract the value of screen_percentage_black directly from the JSON. Once that’s working, you can create a trigger in Zabbix to raise a warning whenever the value goes over 50.

      Comment

      • G0nz0uk
        Member
        • Apr 2021
        • 46

        #5
        Thanks I've got it all working.

        Comment

        Working...