10-18-2018 12:55 PM - edited 10-18-2018 03:19 PM
Is there a way to get the device "name" using "address"?
GET /api/running/devices/device?select=name;address
gives
{ "collection": { "tailf-ncs:device": [ {"name": "DEVICE1","address": "1.1.1.1" }, {"name": "DEVICE2","address": "2.2.2.2" } ] }}
Looking something like
GET /api/running/devices/device?select=name;address=2.2.2.2
or
GET /api/running/devices/device[address=2.2.2.2]
But no luck. Tried also RESTCONF using "fields=name;address", again, no way to specify a value for address.
Solved! Go to Solution.
10-19-2018 06:14 AM
Thanks to an NSO expert, here is a great answer, in case anyone else needs the same:
curl -i 'http://admin:admin@localhost:8080/api/query' -X POST -T q.json -H "Content-Type: application/vnd.yang.data+json"
where file q.json is
{ "immediate-query": { "foreach": "/devices/device[address = '2.2.2.2']", "select": [ { "expression": "name", "result-type": ["string"] }, { "expression": "address", "result-type": ["string"] } ], "sort-by": ["name"], "limit": 100, "offset": 1 } }
10-19-2018 06:14 AM
Thanks to an NSO expert, here is a great answer, in case anyone else needs the same:
curl -i 'http://admin:admin@localhost:8080/api/query' -X POST -T q.json -H "Content-Type: application/vnd.yang.data+json"
where file q.json is
{ "immediate-query": { "foreach": "/devices/device[address = '2.2.2.2']", "select": [ { "expression": "name", "result-type": ["string"] }, { "expression": "address", "result-type": ["string"] } ], "sort-by": ["name"], "limit": 100, "offset": 1 } }
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide