jq Filter
jq
curl https://harvester.ffh.zone/api/nodes.json | jq '.'
oder
nc -U /var/run/fastd.mesh_fastd_20.sock | jq '.'
Hostname + IP-Adresse
.peers[] | select(.connection != null ) | { name: .name, addr: .address }
Hostname + Domain
.nodes[] | { name: .nodeinfo.hostname, domain: .nodeinfo.system.site_code }
Supernode-Peers
.nodes[] | select( .nodeinfo.hostname == "freifunk-60e32736a538") | .statistics.mesh_vpn.groups.backbone.peers
Supernode-Peers ohne Supernodes/Harvester
.peers[] | select(.connection != null ) | .name | select( test("^(?!sn\\d+|harvester)"))
TP-Link MR3020 Knoten: Hostname + Kontakt
.nodes[] | select( .nodeinfo.hardware.model//empty | test("^TP-Link TL-MR3020.*"; "gni") ) | { name: .nodeinfo.hostname, model: .nodeinfo.hardware.model, contact: .nodeinfo.owner.contact }
32/4 Knoten, die gerade mit sn02 verbunden sind: Hostname + Kontakt
'.nodes[] | select( .nodeinfo.hardware.model//empty | test("^TP-Link TL-(MR3020|MR3420|WA730RE|WA750RE|WA7510|WA801|WA830RE|WA850RE|WA860RE|WA901|WR710|WR740|WR741|WR743|WR802|WR810|WR841|WR842|WR940|WR941).*"; "gni") ) | select( .statistics.mesh_vpn.groups.backbone.peers.sn02.established ) | { name: .nodeinfo.hostname, contact: .nodeinfo.owner.contact }'
Beispielbaum
{
"firstseen": "2017-03-19T11:20:33+0100",
"lastseen": "2018-09-06T00:25:38+0200",
"flags": {
"online": true,
"gateway": false
},
"statistics": {
"node_id": "18a6f7e58ad8",
"clients": 1,
"rootfs_usage": 0.4167,
"loadavg": 0.28,
"memory_usage": 0.6446641465542309,
"uptime": 1832050.6,
"idletime": 1376216.96,
"gateway": "88:e6:40:20:a0:01",
"gateway6": "88:e6:40:ba:a0:02",
"processes": {
"total": 48,
"running": 2
},
"mesh_vpn": {
"groups": {
"backbone": {
"peers": {
"sn01": null,
"sn02": null,
"sn03": null,
"sn04": null,
"sn05": null,
"sn06": null,
"sn07": null,
"sn08": null,
"sn09": null,
"sn10": {
"established": 247235.59
}
},
"groups": null
}
}
},
"traffic": {
"tx": {
"bytes": 2048492108,
"packets": 13110502,
"dropped": 27411
},
"rx": {
"bytes": 36291731220,
"packets": 222046893
},
"forward": {
"bytes": 3552,
"packets": 48
},
"mgmt_tx": {
"bytes": 84532243024,
"packets": 179772550
},
"mgmt_rx": {
"bytes": 28974931934,
"packets": 73603313
}
}
},
"nodeinfo": {
"node_id": "18a6f7e58ad8",
"network": {
"mac": "18:a6:f7:e5:8a:d8",
"addresses": [
"2a02:790:ff:5:1aa6:f7ff:fee5:8ad8",
"fe80::1aa6:f7ff:fee5:8ad8",
"2a02:790:ff:10:1aa6:f7ff:fee5:8ad8",
"fdca:ffee:8::1aa6:f7ff:fee5:8ad8",
"2a02:790:ff:6:1aa6:f7ff:fee5:8ad8",
"2a02:790:ff:9:1aa6:f7ff:fee5:8ad8",
"2a02:790:ff:4:1aa6:f7ff:fee5:8ad8",
"2a02:790:ff:2:1aa6:f7ff:fee5:8ad8"
],
"mesh": {
"bat0": {
"interfaces": {
"wireless": [
"16:8a:15:00:79:09"
],
"other": [
"16:8a:15:00:79:0b"
],
"tunnel": [
"16:8a:15:00:79:0f"
]
}
}
},
"mesh_interfaces": null
},
"system": {
"site_code": "ffh.legacy"
},
"hostname": "freifunk-empelde-sandweg",
"location": {
"longitude": 9.664145,
"latitude": 52.344771
},
"software": {
"autoupdater": {
"enabled": true,
"branch": "stable"
},
"batman-adv": {
"version": "2018.1",
"compat": 15
},
"babeld": {},
"fastd": {
"enabled": true,
"version": "v18"
},
"firmware": {
"base": "gluon-v2017.1-451-gd2091f58",
"release": "vH8"
},
"status-page": {
"api": 0
}
},
"hardware": {
"nproc": 1,
"model": "TP-Link TL-WR841N/ND v11"
},
"vpn": false
}
}
Weitere Beispiele
Count IPv4 and IPv6 Fastd Connection
for f in /var/run/fastd.mesh_fastd*.sock; do nc -U $f | jq -r '.peers[] | select(.connection != null ) | .address'; done | awk '/^\[/ { IP6=IP6+1 } /^[0-9]/ { IP4=IP4+1 } END { print "IPvL: " IP4; print "IPv6: " IP6 }'
Histogram - How Long are Peers already connected
for f in /var/run/fastd.mesh_fastd*.sock; do nc -U $f | jq ".peers[] | select(.connection != null ) | .connection.established "; done | sort -n | python -c 'import sys; print("\n".join([str(int(l)/1000/60/60/24) for l in sys.stdin.readlines()]))' | uniq -c
Count of nodes without selected ipv6-gateway
curl -s "https://harvester.ffh.zone/api/meshviewer.json" | jq '.nodes | map(select(.gateway6 == null)) | length'
Nodes without selected ipv4-gateway
curl -s "https://harvester.ffh.zone/api/meshviewer.json" | jq '.nodes | map(select(.gateway == null))'
Strings von Elementen bauen so CSV ähnlich
curl -s "https://harvester.ffh.zone/api/meshviewer.json" | jq '.nodes | map(select(.is_gateway and .hostname == "sn01" )) | .[] | " \(.node_id) \(.mac)" ' | tr -d '"'
Replacement in Strings
curl -s "https://harvester.ffh.zone/api/meshviewer.json" | jq '.nodes[] | select(.gateway != null and (.is_gateway | not)) | .gateway | gsub(":";"")'