Ad Widget

Collapse

Jsonpath in dependent item prototype

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zabbixuserfk
    Member
    • Apr 2020
    • 37

    #1

    Jsonpath in dependent item prototype


    Hello there,

    I'm trying to get the "device-status" for each device from a json that I've (over)simplified here :

    Code:
    [
        {
          "device": {
            "device-name": "toto",
            "device-status": "Online"
          }
        },
        {  
          "device": {
            "device-name": "titi",
            "device-status": "Online"
          }
        },
        {
          "device": {
            "device-name": "tata",
            "device-status": "Online"
          }
        }
    ]​
    This json is returned by a zabbix agent item and I've made a LLD on that master item.
    Nothing fancy here except a {#DEVICE_NAME} LLD macro with the jsonpath $.device.['device-name'] (see attachment 1) on which I can base my dependent item prototype defined as seen on attachment 2.
    The items have been created, but I struggle to find the right jsonpath for the preprocessing of my item prototype (see attachment 3)... None of these seem to be correct, as I don't get any data in Zabbix or get the following error : 1. Failed: cannot extract value from json by path "$.[?(@.device['device-name']=="toto")].['device-status']": no data matches the specified path

    Code:
    $.[?(@.device['device-name']=="{#DEVICE_NAME}")].['device-status']
    $.[?(@.device.['device-name']=="{#DEVICE_NAME}")].['device-status']
    $.device[?(@.['device-name']=="{#DEVICE_NAME}")].['device-status']
    $.device.[?(@.['device-name']=="{#DEVICE_NAME}")].['device-status']
    Funny thing : With this syntax, my items aren't unsupported, but simply empty...

    $.[?(@.device.['device-name']=="{#DEVICE_NAME}")].['device-status']


    I've used similar syntaxes in the past, but I don't get where my error is. Could someone see it and help me please ?



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

    #2
    device-name and device-status are same level items... so you really cannot form a path like device.device-name.device-status...

    Comment

    • zabbixuserfk
      Member
      • Apr 2020
      • 37

      #3
      I've finally managed to do it with :
      Code:
      $..[?(@['device-name'] == "{#DEVICE_NAME}")].['device-status']

      Comment

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

        #4
        Have to bookmark it... I always struggle with jsonpath... It just does not agree with me..

        Comment

        • zabbixuserfk
          Member
          • Apr 2020
          • 37

          #5
          Thank you anyway for taking time to answer

          Comment

          Working...