firmware/src/packages/fff/fff-babeld/files/usr/lib/nodewatcher-json.d/81-babeld.sh

37 lines
912 B
Bash

#!/bin/sh
SCRIPT_DATA_FILE=$(uci get nodewatcher.@script[0].data_file).json
. /usr/share/libubox/jshn.sh
json_load_file $SCRIPT_DATA_FILE
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 > $SCRIPT_DATA_FILE
#exit 0