openconfig / gnmic

gNMIc is a gNMI CLI client and collector
https://gnmic.openconfig.net
Apache License 2.0
166 stars 52 forks source link

gnmic get always returns value "null" #454

Closed PatBoEPFL closed 1 month ago

PatBoEPFL commented 1 month ago

Hello,

I'm trying to use gnmic to get information and counters of Dell SONiC switches. Using the gnmi_get command works (https://github.com/google/gnxi), but the path returns "null" gnmic get command.

gnmic --skip-verify -a <switch-fqdn>:8080 -u admin -p '<password>' get --path "/openconfig-interfaces:interfaces/interface[name=Ethernet10]/state/counters"                                                ✔  2234  13:52:17
[
  {
    "source": "sw-t-in-s19-pod1-lf1.xaas.epfl.ch:8080",
    "timestamp": 1717415576110559354,
    "time": "2024-06-03T13:52:56.110559354+02:00",
    "updates": [
      {
        "Path": "openconfig-interfaces:interfaces/interface[name=Ethernet10]/state/counters",
        "values": {
          "openconfig-interfaces:interfaces/interface/state/counters": null
        }
      }
    ]
  }
]

The same with gnmi_get:

gnmi_get -insecure -target_addr <switch-fqdn>:8080 -target_name <switch-fqdn> -username admin -password '<password>' -xpath "/openconfig-interfaces:interfaces/interface[name=Ethernet10]/state/counters"
== GetRequest:
 prefix: <
>
path: <
  elem: <
    name: "openconfig-interfaces:interfaces"
  >
  elem: <
    name: "interface"
    key: <
      key: "name"
      value: "Ethernet10"
    >
  >
  elem: <
    name: "state"
  >
  elem: <
    name: "counters"
  >
>
encoding: JSON_IETF

== GetResponse:
 notification: <
  timestamp: 1717415537672547244
  prefix: <
  >
  update: <
    path: <
      elem: <
        name: "openconfig-interfaces:interfaces"
      >
      elem: <
        name: "interface"
        key: <
          key: "name"
          value: "Ethernet10"
        >
      >
      elem: <
        name: "state"
      >
      elem: <
        name: "counters"
      >
    >
    val: <
      json_ietf_val: "{\"openconfig-interfaces:counters\":{\"in-bits-per-second\":\"128\",\"in-broadcast-pkts\":\"33\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"28980\",\"in-octets\":\"6333087\",\"in-octets-per-second\":\"16\",\"in-pkts\":\"35269\",\"in-pkts-per-second\":\"0\",\"in-unicast-pkts\":\"6256\",\"in-utilization\":0,\"last-clear\":\"0\",\"out-bits-per-second\":\"454640\",\"out-broadcast-pkts\":\"67646278\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"7002023\",\"out-octets\":\"26047537625\",\"out-octets-per-second\":\"56830\",\"out-pkts\":\"76343046\",\"out-pkts-per-second\":\"177\",\"out-unicast-pkts\":\"1694680\",\"out-utilization\":0}}"
    >
  >
>

I've tested this Dell SONiC 4.1.2, with different paths and only get 'null" as response. I couldn't any flags that I may have added.

Best regards, Patrice

hellt commented 1 month ago

Try moving the / after the : in the path

PatBoEPFL commented 1 month ago

Here is the output (hopefully I did understand you correctly):

$ gnmic --skip-verify -a <switch-fqdn>:8080 -u admin -p '<password>' get --path "openconfig-interfaces:/interfaces/interface[name=Ethernet10]/state/counters"
[
  {
    "source": "sw-t-in-s19-pod1-lf1.xaas.epfl.ch:8080",
    "timestamp": 1717493251746880522,
    "time": "2024-06-04T11:27:31.746880522+02:00",
    "updates": [
      {
        "Path": "openconfig-interfaces:openconfig-interfaces:interfaces/interface[name=Ethernet10]/state/counters",
        "values": {
          "openconfig-interfaces:interfaces/interface/state/counters": null
        }
      }
    ]
  }
]

I tried also two path variants:

$ gnmic --skip-verify -a <switch-fqnd>:8080 -u admin -p '<password>' get --path "/interfaces/interface[name=Ethernet10]/state/counters"
[
  {
    "source": "sw-t-in-s19-pod1-lf1.xaas.epfl.ch:8080",
    "timestamp": 1717493695400886222,
    "time": "2024-06-04T11:34:55.400886222+02:00",
    "updates": [
      {
        "Path": "openconfig-interfaces:interfaces/interface[name=Ethernet10]/state/counters",
        "values": {
          "openconfig-interfaces:interfaces/interface/state/counters": null
        }
      }
    ]
  }
]

$ gnmic --skip-verify -a <switch-fqdn>:8080 -u admin -p '<password>' get --path "interfaces/interface[name=Ethernet10]/state/counters"
[
  {
    "source": "sw-t-in-s19-pod1-lf1.xaas.epfl.ch:8080",
    "timestamp": 1717493707277195478,
    "time": "2024-06-04T11:35:07.277195478+02:00",
    "updates": [
      {
        "Path": "openconfig-interfaces:interfaces/interface[name=Ethernet10]/state/counters",
        "values": {
          "openconfig-interfaces:interfaces/interface/state/counters": null
        }
      }
    ]
  }
]

All those variants show the same result.

hellt commented 1 month ago

Ok, maybe the good path forward is to leverage gnmic's flags to enable the printout of the request in the prototext format and compare it with the prototext format you got from gnmi_get tool

you need to add

--format prototext --print-request
PatBoEPFL commented 1 month ago

Here is the output with those two more flags:

$ gnmic --skip-verify -a <switch-fqdn>:8080 -u admin -p '<password>' get --path "interfaces/interface[name=Ethernet10]/state/counters" --format prototext --print-request
path:  {
  elem:  {
    name:  "interfaces"
  }
  elem:  {
    name:  "interface"
    key:  {
      key:  "name"
      value:  "Ethernet10"
    }
  }
  elem:  {
    name:  "state"
  }
  elem:  {
    name:  "counters"
  }
}

Get Response:
notification:  {
  timestamp:  1717503002822758800
  update:  {
    path:  {
      elem:  {
        name:  "openconfig-interfaces:interfaces"
      }
      elem:  {
        name:  "interface"
        key:  {
          key:  "name"
          value:  "Ethernet10"
        }
      }
      elem:  {
        name:  "state"
      }
      elem:  {
        name:  "counters"
      }
    }
    val:  {}
  }
}

Another way to write null output for val ;-)

karimra commented 1 month ago

Add -e json_ietf to your gnmic command

PatBoEPFL commented 1 month ago

Hello,

It works:

$ gnmic --skip-verify -a <switch-fqdn>:8080 -u admin -p '<password>' get --path "interfaces/interface[name=Ethernet10]/state/counters" --format prototext --print-request -e json_ietf
Get Request:
path:  {
  elem:  {
    name:  "interfaces"
  }
  elem:  {
    name:  "interface"
    key:  {
      key:  "name"
      value:  "Ethernet10"
    }
  }
  elem:  {
    name:  "state"
  }
  elem:  {
    name:  "counters"
  }
}
encoding:  JSON_IETF

Get Response:
notification:  {
  timestamp:  1717577544652442254
  update:  {
    path:  {
      elem:  {
        name:  "openconfig-interfaces:interfaces"
      }
      elem:  {
        name:  "interface"
        key:  {
          key:  "name"
          value:  "Ethernet10"
        }
      }
      elem:  {
        name:  "state"
      }
      elem:  {
        name:  "counters"
      }
    }
    val:  {
      json_ietf_val:  "{\"openconfig-interfaces:counters\":{\"in-bits-per-second\":\"0\",\"in-broadcast-pkts\":\"55\",\"in-discards\":\"0\",\"in-errors\":\"0\",\"in-multicast-pkts\":\"39771\",\"in-octets\":\"8937943\",\"in-octets-per-second\":\"0\",\"in-pkts\":\"49188\",\"in-pkts-per-second\":\"0\",\"in-unicast-pkts\":\"9362\",\"in-utilization\":0,\"last-clear\":\"0\",\"out-bits-per-second\":\"1508632\",\"out-broadcast-pkts\":\"102625805\",\"out-discards\":\"0\",\"out-errors\":\"0\",\"out-multicast-pkts\":\"9383004\",\"out-octets\":\"39442583645\",\"out-octets-per-second\":\"188579\",\"out-pkts\":\"115556271\",\"out-pkts-per-second\":\"376\",\"out-unicast-pkts\":\"3547163\",\"out-utilization\":0}}"
    }
  }
}

And with only the -e json_ietf flag:

$ gnmic --skip-verify -a <switch-fqdn>:8080 -u admin -p '<password>' get --path "interfaces/interface[name=Ethernet10]/state/counters" -e json_ietf
[
  {
    "source": "sw-t-in-s19-pod1-lf1.xaas.epfl.ch:8080",
    "timestamp": 1717577555938484391,
    "time": "2024-06-05T10:52:35.938484391+02:00",
    "updates": [
      {
        "Path": "openconfig-interfaces:interfaces/interface[name=Ethernet10]/state/counters",
        "values": {
          "openconfig-interfaces:interfaces/interface/state/counters": {
            "openconfig-interfaces:counters": {
              "in-bits-per-second": "0",
              "in-broadcast-pkts": "55",
              "in-discards": "0",
              "in-errors": "0",
              "in-multicast-pkts": "39771",
              "in-octets": "8937943",
              "in-octets-per-second": "0",
              "in-pkts": "49188",
              "in-pkts-per-second": "0",
              "in-unicast-pkts": "9362",
              "in-utilization": 0,
              "last-clear": "0",
              "out-bits-per-second": "927656",
              "out-broadcast-pkts": "102629786",
              "out-discards": "0",
              "out-errors": "0",
              "out-multicast-pkts": "9383139",
              "out-octets": "39443846396",
              "out-octets-per-second": "115957",
              "out-pkts": "115560459",
              "out-pkts-per-second": "395",
              "out-unicast-pkts": "3547417",
              "out-utilization": 0
            }
          }
        }
      }
    ]
  }
]

Many thanks :-)