This has triggered the regular trauma and cold sweats I endure trying to remember what random combination of brackets, dots, and pipes got my jq query working … so to help future me, or anyone else …
You can get the entire device list and jq parse it for os like this - note the strings will all be lowercase compared to directly using the API as above:
jq '.devices[] | select( .os == "ping")'
You can output filtered json of what you want specifically after that, for example:
jq --compact-output '.devices[] | select( .os == "something") | {hostname: .hostname, sysname: .sysName, ip: .ip }'
Result:
{"hostname":"xxxx","sysname":"xxx.blah","ip":"1.1.1.1"}
{"hostname":"yyyy","sysname":"yyyy.blah","ip":"2.2.2.2"}
{"hostname":"zzzz","sysname":"zzzz.blah","ip":"3.3.3.3"}
Or to dump it all to CSV (there are multiple indecipherable methods to do this):
jq -r '.devices[] | to_entries|map(.value) | @csv'
Example result:
34,"2021-01-13 14:29:29","xxxx-SW01","xxxx-sw01",,"1.1.1.1","","xxxx","authPriv","xxxx","xxxx","xxx","xxx","xxx","v3",161,"udp",,,0,,".1.3.6.1.4.1.14988.1","RouterOS CRS112-8G-4S","xxxx","xxxx","CRS112-8G-4S","Level 5",58,"routeros",1,"",0,0,13474284,0,"2023-01-13 10:22:51",,12.29,38.59,"2023-01-13 08:52:29","2021-10-17 00:12:16",18.1,"","network","xxxx","mikrotik.svg",0,1,,1,2,0,"42","xxxx","xxxx",-xx.xxx006,xx.xxx295
For header rows: (keys_unsorted, [.[]])
don’t have the way to make that output once inline right now - will update later when I get it:
"device_id","inserted","hostname","sysName","display","ip","overwrite_ip","community","authlevel","authname","authpass","authalgo","cryptopass","cryptoalgo","snmpver","port","transport","timeout","retries","snmp_disable","bgpLocalAs","sysObjectID","sysDescr","sysContact","version","hardware","features","location_id","os","status","status_reason","ignore","disabled","uptime","agent_uptime","last_polled","last_poll_attempted","last_polled_timetaken","last_discovered_timetaken","last_discovered","last_ping","last_ping_timetaken","purpose","type","serial","icon","poller_group","override_sysLocation","notes","port_association_mode","max_depth","disable_notify","dependency_parent_id","dependency_parent_hostname","location","lat","lng"