Ad Widget

Collapse

jsonpath with dot

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ab-tech
    Junior Member
    • Sep 2020
    • 20

    #1

    jsonpath with dot

    Hello,
    i'm search to collect data from a json url.
    i'm able to execute from zabbix server terminal
    Code:
    curl -k https://10.200.100.12:10443/rest/tool/netwatch/print -u admin:12345678 -X POST | jq .
    and have this output
    Code:
    [                        
      {                    
        ".id": "*1",          
        "comment": "CHECK WAN1",
        "disabled": "false",
        "done-tests": "18692",  
        "down-script": "",
        "failed-tests": "0",
        "host": "8.8.8.8",            
        "http-codes": "",
        "interval": "15s",
        "since": "2024-02-10 04:35:11",
        "status": "up",  
        "test-script": "",
        "timeout": "5s",
        "type": "simple",
        "up-script": ""
      },                  
    {                    
        ".id": "*2",        
        "comment": "CHECK WAN2",
        "disabled": "false",  
        "done-tests": "18692",
        "down-script": "",
        "failed-tests": "0",
        "host": "1.1.1.1",            
        "http-codes": "",
        "interval": "15s",
        "since": "2024-02-10 04:35:11",
        "status": "up",
        "test-script": "",
        "timeout": "5s",
        "type": "simple",
        "up-script": ""
      }
    ]
    so i want collect status of WAN1 (8.8.8.8)
    "status": "up",

    i create item and in preprocessing add a
    jsonpath with parameters
    $.id[?(@.host=='8.8.8.8')].status

    but when i test i have this error
    • cannot extract value from json by path "$.id[?(@.host=='8.8.8.8')].status": no data matches the specified path
    i read
    https://www.zabbix.com/documentation...items/jsonpath
    but i think my expression is ok, but i have error
    so i presume is initial dot...
    can someone help me?

    thank you in advance
    Attached Files
  • ISiroshtan
    Senior Member
    • Nov 2019
    • 324

    #2
    As far as I can say the expression is wrong

    Try the
    Code:
    $[?(@.host=='8.8.8.8')].status
    On https://jsonpath.com/ this one works as expected. Also I do know that Zabbix implementation of JSONPath has few quirks, but I think here they should not be in play.

    P.S. be ready that result might be something like ["up"], not just "up" (tho I'm not rightfully remember how it will end up exactly.

    Comment

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

      #3
      It is not clear what you want to find with this expression?
      If you are interested in the status of a host with a given Ip, then the expression is like this :

      Code:
      $[?(@.host=='8.8.8.8')].status.first()
      If you are interested in the status of a node with a specific ID :

      Code:
      $[?(@.['.id']=='*2')].status.first()

      Last edited by Hamardaban; 13-02-2024, 15:44.

      Comment

      • ab-tech
        Junior Member
        • Sep 2020
        • 20

        #4
        big thank you.
        for now i'm using
        Code:
        $[?(@.host=='8.8.8.8')].status.first()
        because id maybe change.
        so i'm more confident with host or comment ...

        thank you again

        Comment

        Working...