gnmi-gateway
gnmi-gateway copied to clipboard
Openconfig Path Question
I'm using gnmi-gateway (details below)
./gnmi-gateway --version
gnmi-gateway version v0.11.1-002a9b0 (Built 2021-08-23T22:15:23Z)
I'm trying to figure out how to translate an Openconfig path into my configuration.
If I use gnmic tool as follows :
root@XXXX-XXXX-logs:~# gnmic -a <hostname>:6030 -u <user> -p <password> --insecure subscribe --path "/interfaces/interface/state/counters" --stream-mode on_change > output.txt
^Croot@XXXX-XXXX-logs:~# tail output.txt
{
"Path": "interfaces/interface[name=Management1]/state/counters/out-unicast-pkts",
"values": {
"interfaces/interface/state/counters/out-unicast-pkts": 237966235
}
}
]
}
You can see I get output
In my gnmi-gateway configuration file
{
"request": {
"default": {
"subscribe": {
"prefix": {
},
"subscription": [
{
"path": {
"elem": [
{
"name": "/interfaces/interface/state/counters"
}
]
}
}
]
}
}
},
"target": {
"<host>": {
"addresses": [
"<host>:6030"
],
"credentials": {
"username": "xxxxxx",
"password": "xxxxxx"
},
"request": "default",
"meta": {
"NoTLSVerify": "yes"
}
}
}
}
When using that same path I get
{"level":"info","time":"2021-08-23T18:22:58-07:00","message":"Target <host>.gh.st: Disconnected"}
E0823 18:22:58.050605 71921 reconnect.go:114] client.Subscribe (target "<host>.st") failed: rpc error: code = InvalidArgument desc = failed to subscribe to /\/interfaces\/interface\/state\/counters: path invalid: failed to access node "/interfaces/interface/state/counters" in node ""; reconnecting in 1.040217184s
INFO: 2021/08/23 18:22:58 [transport] transport: loopyWriter.run returning. connection error: desc = "transport is closing"
Can you advise how I use more specific paths ?
Hi @gavmckee80! The value of elem
is a list of each of the elements between the slashes in the xpath-style string that you would use with gNMIc. For /interfaces/interface/state/counters
it would look something like:
{
"request": {
"default": {
"subscribe": {
"prefix": {
},
"subscription": [
{
"path": {
"elem": [
{
"name": "interfaces"
},
{
"name": "interface"
},
{
"name": "state"
},
{
"name": "counters"
}
]
}
}
]
}
}
},
"target": {
"<host>": {
"addresses": [
"<host>:6030"
],
"credentials": {
"username": "xxxxxx",
"password": "xxxxxx"
},
"request": "default",
"meta": {
"NoTLSVerify": "yes"
}
}
}
}
You're also able to use xpath-style paths with the "simple" Target Loader in gnmi-gateway. For example your simple config file would look something like:
connection:
my-router:
addresses:
- my-router.test.example.net:9339
credentials:
username: myusername
password: mypassword
request: default
meta:
NoTLSVerify: yes
request:
default:
paths:
- /interfaces/interface/state/counters
@colinmcintosh , thanks for coming back to me - this is a great project and saves me writing a bunch of code :D , which is even better.
I'll probably load from Netbox at some point , I'm just trying to get all the components to work , Clustering etc.
Another question on paths first.
I have two seperate requestss defined , one for Arista (eos) and one for Palo Alto (panos).
The second path in eos is to get the CPU stats
Again testing
gnmic -a arista-sw1:6030 -u eos -p password --insecure subscribe --path "components/component/cpu" --stream-mode on_change
{
"source": "arista-sw1:6030",
"subscription-name": "default-1629846458",
"timestamp": 1629847029458359290,
"time": "2021-08-24T23:17:09.45835929Z",
"updates": [
{
"Path": "components/component[name=CPU0]/cpu/utilization/state/instant",
"values": {
"components/component/cpu/utilization/state/instant": 6
}
}
]
}
........
When I spin up the GNMI GW I don't seem to get the CPU related output.
{
"request": {
"eos": {
"subscribe": {
"prefix": {
},
"subscription": [
{
"path": {
"elem": [
{
"name": "interfaces"
},
{
"name": "interface"
},
{
"name": "state"
},
{
"name": "counters"
}
]
}
},
{
"path": {
"elem": [
{
"name": "components"
},
{
"name": "component"
},
{
"name": "cpu"
}
]
}
}
]
}
},
"panos": {
"subscribe": {
"prefix": {
},
"subscription": [
{
"path": {
"elem": [
{
"name": "interfaces"
},
{
"name": "interface"
},
{
"name": "state"
},
{
"name": "counters"
}
]
}
}
]
}
}
},
"target": {
"arista-sw1": {
"addresses": [
"arista-sw1:6030"
],
"credentials": {
"username": "eos",
"password": "password"
},
"request": "eos",
"meta": {
"NoTLSVerify": "yes"
}
}
},
"panos-fw1": {
"addresses": [
"panos-fw1:9339"
],
"credentials": {
"username": "panos",
"password": "password"
},
"request": "panos",
"meta": {
"NoTLSVerify": "yes"
}
}
}
Is there a way to set the origin for a request also ? Something like ....
gnmi -addr arista-sw1:6030 -username admin
get origin=eos_native '/Kernel/proc/cpu/utilization/total'