forked from freifunk-franken/firmware
35 lines
851 B
Bash
35 lines
851 B
Bash
#!/bin/sh
|
|
|
|
. /usr/share/libubox/jshn.sh
|
|
json_load_file /tmp/nodewatcher.json
|
|
|
|
json_select babel
|
|
|
|
json_add_array "neighbours"
|
|
|
|
if pgrep babeld >/dev/null; then
|
|
neighbours="$(echo dump | nc ::1 33123 | grep '^add neighbour' |
|
|
awk '{
|
|
for (i=2; i < NF; i += 2) {
|
|
vars[$i] = $(i+1)
|
|
}
|
|
}
|
|
{
|
|
printf "%s;%s;%s;>", vars["address"], vars["if"], vars["cost"]
|
|
}')"
|
|
|
|
IFS='>'; set $neighbours; IFS=$' \t\n'
|
|
for a; do
|
|
json_add_object
|
|
json_add_string "ip" "$(echo $a | awk '{split($0, b, ";"); printf b[1]}')"
|
|
json_add_string "outgoing_interface" "$(echo $a | awk '{split($0, b, ";"); printf b[2]}')"
|
|
json_add_string "link_cost" "$(echo $a | awk '{split($0, b, ";"); printf b[3]}')"
|
|
json_close_object #this_neighbour
|
|
done
|
|
fi
|
|
|
|
json_close_object #neighbours
|
|
|
|
json_dump > /tmp/nodewatcher.json
|
|
|
|
#exit 0 |