From 11ef32178d0b3d4f6cd9ac28123278efedc41c79 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Sat, 16 May 2015 09:38:23 +0200 Subject: [PATCH] Added jq filter to convert new format to old format This makes it easily possible to continue using the legacy ffmap-d3 front end with the new backend while migrating. --- README.md | 15 +++++++++++++++ ffmap-d3.jq | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 ffmap-d3.jq diff --git a/README.md b/README.md index 809f393..c345bb3 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,21 @@ will prefix `sudo` where necessary. - online - gateway +## Old data format + +If you want to still use the old [ffmap-d3](https://github.com/ffnord/ffmap-d3) +front end, you can use the file `ffmap-d3.jq` to convert the new output to the +old one: + +``` +jq -n -f ffmap-d3.jq \ + --argfile nodes nodedb/nodes.json \ + --argfile graph nodedb/graph.json \ + > nodedb/ffmap-d3.json +``` + +Then point your ffmap-d3 instance to the `ffmap-d3.json` file. + # Removing owner information If you'd like to redact information about the node owner from `nodes.json`, diff --git a/ffmap-d3.jq b/ffmap-d3.jq new file mode 100644 index 0000000..ebeece1 --- /dev/null +++ b/ffmap-d3.jq @@ -0,0 +1,52 @@ +{ + "meta": { + "timestamp": $nodes.timestamp + }, + "nodes": ( + $graph.batadv.nodes + | map( + if has("node_id") and .node_id + then ( + $nodes.nodes[.node_id] as $node + | { + "id": .id, + "uptime": $node.statistics.uptime, + "flags": ($node.flags + {"client": false}), + "name": $node.nodeinfo.hostname, + "clientcount": (if $node.statistics.clients >= 0 then $node.statistics.clients else 0 end), + "hardware": $node.nodeinfo.hardware.model, + "firmware": $node.nodeinfo.software.firmware.release, + "geo": (if $node.nodeinfo.location then [$node.nodeinfo.location.latitude, $node.nodeinfo.location.longitude] else null end), + #"lastseen": $node.lastseen, + "network": $node.nodeinfo.network + } + ) + else + { + "flags": {}, + "id": .id, + "geo": null, + "clientcount": 0 + } + end + ) + ), + "links": ( + $graph.batadv.links + | map( + $graph.batadv.nodes[.source].node_id as $source_id + | $graph.batadv.nodes[.target].node_id as $target_id + | select( + $source_id and $target_id and + ($nodes.nodes | (has($source_id) and has($target_id))) + ) + | { + "target": .target, + "source": .source, + "quality": "\(.tq), \(.tq)", + "id": ($source_id + "-" + $target_id), + "type": (if .vpn then "vpn" else null end) + } + ) + ) +}