forked from freifunk-franken/firmware
142 lines
5.0 KiB
Bash
142 lines
5.0 KiB
Bash
#!/bin/sh
|
|
. /lib/functions.sh
|
|
|
|
. /usr/share/libubox/jshn.sh
|
|
json_load_file /tmp/nodewatcher.json
|
|
|
|
json_add_array "s2nproxy"
|
|
|
|
# Example for /etc/config/s2nproxy
|
|
#
|
|
# config s2nproxy 'DEVICE_NAME'
|
|
# option ip 'IP_ADDRESS'
|
|
# option device 'DEVICE_TYPE'
|
|
# option community 'COMMUNITY'
|
|
|
|
# SNMP Walk
|
|
walk() {
|
|
community=$1
|
|
ip=$2
|
|
oid=$3
|
|
echo $(snmpwalk -O vQ -P e -L n -v 1 -c $community $ip $oid)
|
|
}
|
|
|
|
# Format the dirty mikrotik mac address result
|
|
format_mac() {
|
|
echo $(echo $1 | xargs | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//' | sed 's/\ /\:/g')
|
|
}
|
|
|
|
s2np() {
|
|
if [ -z "$(uci -q get s2nproxy.$1.community)" ]; then
|
|
community="public"
|
|
else
|
|
community=$(uci get s2nproxy.$1.community)
|
|
fi
|
|
|
|
ip=$(uci get s2nproxy.$1.ip)
|
|
|
|
# Check if host is available
|
|
if ping -c 1 -W 1 $ip &> /dev/null ; then
|
|
json_add_object
|
|
json_add_string "ip" "$ip"
|
|
|
|
# Switch throught device types
|
|
case "$(uci -q get s2nproxy.$1.device)" in
|
|
airmaxac)
|
|
# Ubiquity AirMAX Richtfunk
|
|
name=$(walk $community $ip "iso.3.6.1.2.1.1.5.0" | xargs)
|
|
mac=$(format_mac "$(walk $community $ip 1.3.6.1.2.1.2.2.1.6.8)")
|
|
hw=$(walk $community $ip "iso.3.6.1.4.1.41112.1.4.1.1.9.1" | xargs)
|
|
signal=$(walk $community $ip "iso.3.6.1.4.1.41112.1.4.5.1.5")
|
|
capacity=$(walk $community $ip "iso.3.6.1.4.1.41112.1.4.5.1.10" / 1024)
|
|
capacity=$(printf %.2f "$((10**9 * $capacity / 1048576))e-9")
|
|
remotemac=$(format_mac "$(walk $community $ip iso.3.6.1.4.1.41112.1.4.5.1.4.1)")
|
|
latency=$(ping -qc1 -4 $ip 2>&1 | awk -F'/' 'END{ print (/^round-trip/? $4:"0") }')
|
|
json_add_string "type" "airmaxac"
|
|
json_add_string "mac" "$mac"
|
|
json_add_string "name" "$name"
|
|
json_add_string "hw" "$hw"
|
|
json_add_string "signal" "$signal"
|
|
json_add_string "capacity" "$capacity"
|
|
json_add_string "remotemac" "$remotemac"
|
|
json_add_string "latency" "$latency"
|
|
;;
|
|
|
|
mikrotikap)
|
|
# Mikrotik AP
|
|
name=$(walk $community $ip 1.3.6.1.2.1.1.5 | xargs)
|
|
fw=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.7.7 | xargs)
|
|
hw=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.7.9 | xargs)
|
|
frequency=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.1.3.1.7.1 | xargs)
|
|
frequency2=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.1.3.1.7.2 | xargs)
|
|
mac=$(format_mac "$(walk $community $ip 1.3.6.1.2.1.2.2.1.6.1)")
|
|
clients=$(( $(walk $community $ip 1.3.6.1.4.1.14988.1.1.1.3.1.6.1) + $(walk $community $ip 1.3.6.1.4.1.14988.1.1.1.3.1.6.2) ))
|
|
latency=$(ping -qc1 -4 $ip 2>&1 | awk -F'/' 'END{ print (/^round-trip/? $4:"0") }')
|
|
json_add_string "type" "mikrotikap"
|
|
json_add_string "mac" "$mac"
|
|
json_add_string "name" "$name"
|
|
json_add_string "hw" "$hw"
|
|
json_add_string "fw" "$fw"
|
|
json_add_string "frequency" "$frequency"
|
|
json_add_string "frequency2" "$frequency2"
|
|
json_add_string "clients" "$clients"
|
|
json_add_string "latency" "$latency"
|
|
;;
|
|
|
|
mikrotikw60grf)
|
|
# Mikrotik 60GHz Richtfunk
|
|
name=$(walk $community $ip 1.3.6.1.2.1.1.5 | xargs)
|
|
fw=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.7.7 | xargs)
|
|
hw=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.7.9 | xargs)
|
|
signal=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.1.8.1.8.1)
|
|
capacity=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.1.8.1.13.1)
|
|
frequency=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.1.8.1.6.1)
|
|
mac=$(format_mac "$(walk $community $ip 1.3.6.1.2.1.2.2.1.6.1)")
|
|
remotemac=$(format_mac "$(walk $community $ip 1.3.6.1.4.1.14988.1.1.1.8.1.5.1)")
|
|
latency=$(ping -qc1 -4 $ip 2>&1 | awk -F'/' 'END{ print (/^round-trip/? $4:"0") }')
|
|
json_add_string "type" "mikrotikw60grf"
|
|
json_add_string "mac" "$mac"
|
|
json_add_string "name" "$name"
|
|
json_add_string "hw" "$hw"
|
|
json_add_string "fw" "$fw"
|
|
json_add_string "signal" "$signal"
|
|
json_add_string "capacity" "$capacity"
|
|
json_add_string "frequency" "$frequency"
|
|
json_add_string "latency" "$latency"
|
|
json_add_string "remotemac" "$remotemac"
|
|
;;
|
|
|
|
mikrotikw60gst)
|
|
# Mikrotik 60GHz Sektor
|
|
name=$(walk $community $ip 1.3.6.1.2.1.1.5 | xargs)
|
|
fw=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.7.7 | xargs)
|
|
hw=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.7.9 | xargs)
|
|
frequency=$(walk $community $ip 1.3.6.1.4.1.14988.1.1.1.8.1.6.1)
|
|
mac=$(format_mac "$(walk $community $ip 1.3.6.1.2.1.2.2.1.6.1)")
|
|
latency=$(ping -qc1 -4 $ip 2>&1 | awk -F'/' 'END{ print (/^round-trip/? $4:"0") }')
|
|
json_add_string "type" "mikrotikw60gst"
|
|
json_add_string "mac" "$mac"
|
|
json_add_string "name" "$name"
|
|
json_add_string "hw" "$hw"
|
|
json_add_string "fw" "$fw"
|
|
json_add_string "latency" "$latency"
|
|
json_add_string "frequency" "$frequency"
|
|
;;
|
|
|
|
latenz)
|
|
latency=$(ping -qc1 -4 $ip 2>&1 | awk -F'/' 'END{ print (/^round-trip/? $4:"0") }')
|
|
json_add_string "type" "latenz"
|
|
json_add_string "latency" "$latency"
|
|
;;
|
|
esac
|
|
|
|
json_close_object
|
|
fi
|
|
}
|
|
|
|
config_load s2nproxy
|
|
config_foreach s2np s2nproxy
|
|
|
|
json_close_object #s2nproxy
|
|
|
|
json_dump > /tmp/nodewatcher.json |