Ad Widget

Collapse

JSON discovery returns the value I wnat

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

    #1

    JSON discovery returns the value I wnat

    Hello,

    I have this test .json file I'm hosting before I get the real data, but each device will look like this:

    Code:
    [
      {
        "name": "A2-Mars",
        "format": "A2",
        "estate": "xyz",
        "location": "Mars",
        "metrics": {
          "pod_screen_percentage_unchanged": 1,
          "pod_screen_percentage_predominant_colour": 17,
          "pod_screen_percentage_desktop": 0,
          "pod_screen_percentage_black": 47,
          "pod_screen_unexpected_size": 0,
          "pod_screen_layout_changed": 0,
          "pod_screen_layout_mismatch": 0,
          "pod_screen_is_monitor_off": 0,
          "pod_broadsign_is_contactable": 1
        }
      },
      {
        "name": "A3-Venus",
        "format": "A3",
        "estate": "xyz",
        "location": "Venus",
        "metrics": {
          "pod_screen_percentage_unchanged": 1,
          "pod_screen_percentage_predominant_colour": 17,
          "pod_screen_percentage_desktop": 0,
          "pod_screen_percentage_black": 34,
          "pod_screen_unexpected_size": 0,
          "pod_screen_layout_changed": 0,
          "pod_screen_layout_mismatch": 0,
          "pod_screen_is_monitor_off": 0,
          "pod_broadsign_is_contactable": 1
        }
      }
    ]
    I basically want to create some graphs for "pod_screen_percentage_black" and also triggers when over 60 for 20mins.

    I'm created the Discovery rule and LLD macros such as
    Code:
    {#NAME}
    for
    Code:
    $.name
    plus the item prototype which is a dependant item with a key of
    Code:
    metrics.pod_screen_percentage_black[{#NAME}]
    In the preprocessing I am using a JSONPath and the parameters are set to text as numerical won't work:

    Code:
    $[?(@.name == '{#NAME}')].metrics.pod_screen_percentage_black
    Click image for larger version

Name:	image.png
Views:	69
Size:	41.4 KB
ID:	509393
    If I test:

    Click image for larger version

Name:	image.png
Views:	30
Size:	26.7 KB
ID:	509394

    If I change to numerical (unsigned) in the item protocol section I get:

    Click image for larger version

Name:	image.png
Views:	31
Size:	48.0 KB
ID:	509396

    Value of type "string" is not suitable for value type "Numeric (unsigned)". Value "[47]"

    When I test it though is looks ok:

    Click image for larger version

Name:	image.png
Views:	30
Size:	22.3 KB
ID:	509395

    What am I doing wrong?

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

    #2
    [47] is not excactly 47, what would suit "intger" or "unsigned"
    you can also add "$[?(@.name == '{#NAME}')].metrics.pod_screen_percentage_black.first()"

    Comment


    • G0nz0uk
      G0nz0uk commented
      Editing a comment
      So is that Zabbix adding the [ ] around the number making it more of a text reply then?
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #3
    Zabbix shows you everything as requested...
    look on examples...


    It is all something objects vs arrays ... All of it usually makes my head ache..

    Comment

    • G0nz0uk
      Member
      • Apr 2021
      • 46

      #4
      Thanks for the URL and example .first() as this worked as numeric (unsigned)

      "$[?(@.name == '{#NAME}')].metrics.pod_screen_percentage_black.first()"

      Comment

      Working...