This patch adds json to the mqtt monitoring package. #216
|
@ -0,0 +1,37 @@
|
|||
#!/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
|
|
@ -0,0 +1 @@
|
|||
*/5 * * * * sleep $(/usr/bin/random 70 85); /usr/sbin/json-mqtt-proxy
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
MACADDR=$(/bin/sed 's/://g' < /sys/class/net/br-client/address)
|
||||
SCRIPT_DATA_FILE=$(uci get nodewatcher.@script[0].data_file).json
|
||||
|
||||
if [ -n "$(uci -q get fff.mqtt.server)" ] ; then
|
||||
mosquitto_pub -h "$(uci get fff.mqtt.server)" -p 1883 -t /monitoring/v2/"$MACADDR" -f "$SCRIPT_DATA_FILE"
|
||||
|
||||
fi
|
|
@ -0,0 +1,100 @@
|
|||
#!/bin/sh
|
||||
|
||||
IFACEBLACKLIST=$(uci get nodewatcher.@network[0].iface_blacklist)
|
||||
IPWHITELIST=$(uci get nodewatcher.@network[0].ip_whitelist)
|
||||
|
||||
debug() {
|
||||
(>&2 echo "nodewatcher: $1")
|
||||
}
|
||||
|
||||
inArray() {
|
||||
local value
|
||||
for value in $1; do
|
||||
[ "$value" = "$2" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
debug "Collecting information from network interfaces"
|
||||
|
||||
SCRIPT_DATA_FILE=$(uci get nodewatcher.@script[0].data_file).json
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
json_load_file $SCRIPT_DATA_FILE
|
||||
|
||||
json_add_array "interfaces"
|
||||
|
||||
# Loop through interfaces: for entry in $IFACES; do
|
||||
for filename in $(grep 'up\|unknown' /sys/class/net/*/operstate); do
|
||||
ifpath=${filename%/operstate*}
|
||||
iface=${ifpath#/sys/class/net/}
|
||||
|
||||
inArray "$IFACEBLACKLIST" "$iface" && continue
|
||||
|
||||
json_add_object ""
|
||||
|
||||
json_add_string "name" "$iface"
|
||||
|
||||
#Get interface data for whitelisted interfaces
|
||||
# shellcheck disable=SC2016
|
||||
mac_addr=$(ip addr show dev $iface | awk '/ether/ { printf $2 }')
|
||||
json_add_string "mac_addr" "$mac_addr"
|
||||
mtu=$(ip addr show dev $iface | awk '/mtu/ { printf $5 }')
|
||||
json_add_string "mtu" "$mtu"
|
||||
|
||||
if inArray "$IPWHITELIST" "$iface"; then
|
||||
# shellcheck disable=SC2016
|
||||
json_add_array ipv4_addr
|
||||
IN=$(ip addr show dev $iface | awk '/inet / { split($2, a, "/"); printf a[1]";" }')
|
||||
IFS=';'; set $IN; IFS=$' \t\n'
|
||||
for a; do json_add_string "" "$a"; done
|
||||
json_close_object #ipv4_addr
|
||||
|
||||
json_add_array ipv6_addr
|
||||
IN=$(ip addr show dev $iface | awk '/inet6/ && /scope global/ { printf $2";" }')
|
||||
IFS=';'; set $IN; IFS=$' \t\n'
|
||||
for a; do json_add_string "" "$a"; done
|
||||
json_close_object #ipv6_addr
|
||||
|
||||
json_add_array ipv6_link_local_addr
|
||||
IN=$(ip addr show dev $iface | awk '/inet6/ && /scope link/ { printf $2 }')
|
||||
IFS=';'; set $IN; IFS=$' \t\n'
|
||||
for a; do json_add_string "" "$a"; done
|
||||
json_close_object #ipv6_link_local_addr
|
||||
fi
|
||||
|
||||
json_add_object "traffic"
|
||||
traffic_rx=$(cat "$ifpath/statistics/rx_bytes")
|
||||
json_add_string "rx" "$(cat "$ifpath/statistics/rx_bytes")"
|
||||
traffic_tx=$(cat "$ifpath/statistics/tx_bytes")
|
||||
json_add_string "tx" "$traffic_tx"
|
||||
json_close_object #traffic
|
||||
|
||||
wlan_mode=$(iwconfig $iface 2>/dev/null | awk -F':' '/Mode/{ split($2, m, " "); printf m[1] }')
|
||||
if [[ $wlan_mode ]]; then
|
||||
json_add_object "wlan"
|
||||
wlan_cell=$(iwconfig $iface 2>/dev/null | awk -F':' '/Cell/{ split($0, c, " "); printf c[5] }')
|
||||
wlan_essid=$(iwconfig $iface 2>/dev/null | awk -F':' '/ESSID/ { split($0, e, "\""); printf e[2] }')
|
||||
wlan_frequency=$(iwconfig $iface 2>/dev/null | awk -F':' '/Freq/{ split($3, f, " "); printf f[1]f[2] }')
|
||||
wlan_tx_power=$(iwconfig $iface 2>/dev/null | awk -F':' '/Tx-Power/{ split($0, p, "="); sub(/[[:space:]]*$/, "", p[2]); printf p[2] }')
|
||||
wlan_ssid=$(iw dev $iface info 2>/dev/null | awk '/ssid/{ split($0, s, " "); printf s[2]}')
|
||||
wlan_type=$(iw dev $iface info 2>/dev/null | awk '/type/ { split($0, t, " "); printf t[2]}')
|
||||
wlan_channel=$(iw dev $iface info 2>/dev/null | awk '/channel/{ split($0, c, " "); printf c[2]}')
|
||||
wlan_width=$(iw dev $iface info 2>/dev/null | awk '/width/{ split($0, w, ": "); sub(/ .*/, "", w[2]); printf w[2]}')
|
||||
[[ $wlan_mode ]] && json_add_string "mode" "$wlan_mode"
|
||||
[[ $wlan_cell ]] && json_add_string "cell" "$wlan_cell"
|
||||
[[ $wlan_essid ]] && json_add_string "essid" "$wlan_essid"
|
||||
[[ $wlan_frequency ]] && json_add_string "frequency" "$wlan_frequency"
|
||||
[[ "$wlan_tx_power" ]] && json_add_string "tx_power" "$wlan_tx_power"
|
||||
[[ $wlan_ssid ]] && json_add_string "ssid" "$wlan_ssid"
|
||||
[[ $wlan_type ]] && json_add_string "type" "$wlan_type"
|
||||
[[ $wlan_channel ]] && json_add_string "channel" "$wlan_channel"
|
||||
[[ $wlan_width ]] && json_add_string "width" "$wlan_width"
|
||||
json_close_object #wlan
|
||||
fi
|
||||
|
||||
json_close_object #iface object
|
||||
done
|
||||
|
||||
json_dump > $SCRIPT_DATA_FILE
|
||||
#exit 0
|
|
@ -0,0 +1,36 @@
|
|||
#!/bin/sh
|
||||
|
||||
MESH_INTERFACE=$(uci get nodewatcher.@network[0].mesh_interface)
|
||||
SCRIPT_DATA_FILE=$(uci get nodewatcher.@script[0].data_file).json
|
||||
|
||||
debug() {
|
||||
(>&2 echo "nodewatcher: $1")
|
||||
}
|
||||
|
||||
debug "Collecting information about connected clients"
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
json_load_file $SCRIPT_DATA_FILE
|
||||
|
||||
json_add_object "clients"
|
||||
|
||||
json_add_array interfaces
|
||||
|
||||
client_count=0
|
||||
CLIENT_INTERFACES=$(ls "/sys/class/net/$MESH_INTERFACE/brif" | grep -v '^bat')
|
||||
|
||||
for clientif in ${CLIENT_INTERFACES}; do
|
||||
json_add_object ""
|
||||
cc=$(bridge fdb show br "$MESH_INTERFACE" brport "$clientif" | grep -v self | grep -v permanent -c)
|
||||
client_count=$((client_count + cc))
|
||||
json_add_string "$clientif" "$cc"
|
||||
json_close_object #iface object
|
||||
done
|
||||
|
||||
json_close_object #interfaces array
|
||||
json_add_string "count" "$client_count"
|
||||
json_close_object #clients
|
||||
|
||||
json_dump > $SCRIPT_DATA_FILE
|
||||
|
||||
#exit 0
|
|
@ -0,0 +1 @@
|
|||
*/5 * * * * sleep $(/usr/bin/random 0 29); /usr/sbin/nodewatcher-json
|
|
@ -0,0 +1,145 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
json_init
|
||||
|
||||
SCRIPT_STATUS_FILE=$(uci get nodewatcher.@script[0].status_text_file)
|
||||
SCRIPT_VERSION=$(cat /etc/nodewatcher_version)
|
||||
SCRIPT_DATA_FILE=$(uci get nodewatcher.@script[0].data_file).json
|
||||
|
||||
debug() {
|
||||
(>&2 echo "nodewatcher: $1")
|
||||
}
|
||||
|
||||
debug "Collecting basic system status data"
|
||||
|
||||
json_add_object "system"
|
||||
|
||||
json_add_string "status" "online"
|
||||
hostname="$(cat /proc/sys/kernel/hostname)"
|
||||
mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-client/address 2>/dev/null)
|
||||
|
||||
[ "$hostname" = "OpenWrt" ] && hostname="$mac"
|
||||
[ "$hostname" = "FFF" ] && hostname="$mac"
|
||||
|
||||
json_add_string "hostname" "$hostname"
|
||||
|
||||
description="$(uci -q get fff.system.description)"
|
||||
[ -n "$description" ] && json_add_string "description" "$description"
|
||||
|
||||
latitude="$(uci -q get fff.system.latitude)"
|
||||
longitude="$(uci -q get fff.system.longitude)"
|
||||
if [ -n "$longitude" -a -n "$latitude" ]; then
|
||||
json_add_object "geo"
|
||||
json_add_string "lat" "$latitude"
|
||||
json_add_string "lng" "$longitude"
|
||||
json_close_object #geo
|
||||
fi
|
||||
|
||||
position_comment="$(uci -q get fff.system.position_comment)"
|
||||
[ -n "$position_comment" ] && json_add_string "position_comment" "$position_comment"
|
||||
|
||||
contact="$(uci -q get fff.system.contact)"
|
||||
[ -n "$contact" ] && json_add_string "contact" "$contact"
|
||||
|
||||
json_add_string "uptime" $(awk '{ printf $1 }' /proc/uptime)
|
||||
json_add_string "idletime" $(awk '{ printf $2 }' /proc/uptime)
|
||||
|
||||
# Add Memory
|
||||
json_add_object "memory"
|
||||
json_add_string "total" $(awk '/^MemTotal/ { printf $2 }' /proc/meminfo)
|
||||
json_add_string "available" $(awk '/^MemAvail/ { printf $2 }' /proc/meminfo)
|
||||
json_add_string "caching" $(awk '/^Cached/ { printf $2 }' /proc/meminfo)
|
||||
json_add_string "buffering" $(awk '/^Buffers/ { printf $2 }' /proc/meminfo)
|
||||
json_add_string "free" $(awk '/^MemFree/ { printf $2 }' /proc/meminfo)
|
||||
json_close_object #memory
|
||||
|
||||
# Add CPU
|
||||
json_add_array cpu
|
||||
IN=$(awk -F': ' ' /model/ { printf $2";" }' /proc/cpuinfo)
|
||||
IFS=';'; set $IN; IFS=$' \t\n'
|
||||
for a; do json_add_string "" "$a"; done
|
||||
json_close_object #cpu
|
||||
|
||||
# Add Chipset
|
||||
IN=$(awk -F': ' ' /system type/ { printf $2";" }' /proc/cpuinfo)
|
||||
IFS=';'; set $IN; IFS=$' \t\n'
|
||||
for a; do json_add_string "chipset" "$a"; done
|
||||
|
||||
IN=$(awk -F': ' ' /platform/ { printf $2";" }' /proc/cpuinfo)
|
||||
IFS=';'; set $IN; IFS=$' \t\n'
|
||||
for a; do json_add_string "chipset" "$a"; done
|
||||
|
||||
model=$(cat /var/sysinfo/model)
|
||||
[ -n "$model" ] && json_add_string "model" "$model"
|
||||
local_time=$(date +%s)
|
||||
[ -n "$local_time" ] && json_add_string "local_time" "$local_time"
|
||||
loadavg=$(awk '{ printf $3 }' /proc/loadavg)
|
||||
[ -n "$loadavg" ] && json_add_string "loadavg" "$loadavg"
|
||||
processes=$(awk '{ printf $4 }' /proc/loadavg)
|
||||
[ -n "$processes" ] && json_add_string "processes" "$processes"
|
||||
|
||||
debug "Collecting version information"
|
||||
json_close_object #system
|
||||
|
||||
if [ -e /sys/module/batman_adv/version ]; then
|
||||
batman_advanced_version=$(cat /sys/module/batman_adv/version)
|
||||
json_add_object "batman_advanced"
|
||||
json_add_string "version" "$batman_advanced_version"
|
||||
json_close_object #batman_advanced
|
||||
fi
|
||||
|
||||
json_select system
|
||||
json_add_string "kernel_version" "$(uname -r)"
|
||||
json_add_string "nodewatcher_version" "$SCRIPT_VERSION"
|
||||
|
||||
if [ -x /usr/bin/fastd ]; then
|
||||
json_add_string "fastd_version" "$(/usr/bin/fastd -v | awk '{ print $2 }')"
|
||||
fi
|
||||
|
||||
json_close_object #system
|
||||
|
||||
if [ -x /usr/sbin/babeld ]; then
|
||||
json_add_object "babel"
|
||||
json_add_string "version" "$(/usr/sbin/babeld -V 2>&1)"
|
||||
json_close_object #babel
|
||||
fi
|
||||
|
||||
json_select system
|
||||
json_add_object "dist"
|
||||
. /etc/openwrt_release
|
||||
json_add_string "name" "$DISTRIB_ID"
|
||||
json_add_string "version" "$DISTRIB_RELEASE"
|
||||
json_close_object #dist
|
||||
|
||||
json_add_object "firmware"
|
||||
. /etc/firmware_release
|
||||
json_add_string "version" "$FIRMWARE_VERSION"
|
||||
json_add_string "revision" "$BUILD_DATE"
|
||||
json_add_object "openwrt"
|
||||
json_add_string "core_revision" "$OPENWRT_CORE_REVISION"
|
||||
json_add_string "feeds_packages_revision" "$OPENWRT_FEEDS_PACKAGES_REVISION"
|
||||
json_close_object #openwrt
|
||||
json_close_object #firmware
|
||||
|
||||
debug "Collecting hood information and additional status data"
|
||||
|
||||
json_add_object "hood"
|
||||
hoodname="$(uci -q get "system.@system[0].hood")"
|
||||
[ -n "$hoodname" ] && json_add_string "name" "$hoodname"
|
||||
hoodid="$(uci -q get "system.@system[0].hoodid")"
|
||||
[ -n "$hoodid" ] && json_add_string "id" "$hoodid"
|
||||
json_close_object #hood
|
||||
|
||||
if [ -s "$SCRIPT_STATUS_FILE" ]; then
|
||||
status_text="$(cat "$SCRIPT_STATUS_FILE")"
|
||||
json_add_string "status_text" "$status_text"
|
||||
fi
|
||||
|
||||
# Checks if fastd is running
|
||||
vpn_active=0
|
||||
pidof fastd >/dev/null && vpn_active=1
|
||||
json_add_string "vpn_active" "$vpn_active"
|
||||
|
||||
json_dump > $SCRIPT_DATA_FILE
|
||||
#exit 0
|
|
@ -0,0 +1,45 @@
|
|||
#!/bin/sh
|
||||
|
||||
test -f /tmp/started || exit
|
||||
|
||||
# Allow only one instance
|
||||
lockfile="/var/lock/${0##*/}.json.lock"
|
||||
if ! lock -n "$lockfile"; then
|
||||
echo "Only one instance of $0 allowed."
|
||||
exit 1
|
||||
fi
|
||||
trap "lock -u \"$lockfile\"" INT TERM EXIT
|
||||
|
||||
[ -s /etc/config/nodewatcher ] || exit 1
|
||||
[ "$(uci get nodewatcher.@script[0].disabled)" = "1" ] && exit 0
|
||||
|
||||
SCRIPT_DATA_FILE=$(uci get nodewatcher.@script[0].data_file).json
|
||||
|
||||
debug() {
|
||||
(>&2 echo "nodewatcher: $1")
|
||||
}
|
||||
|
||||
#This method generates the crawl data JSON file that is being fetched by netmon
|
||||
#and provided by a small local httpd
|
||||
crawl() {
|
||||
debug "Putting all information into a JSON-File and save it at $SCRIPT_DATA_FILE"
|
||||
|
||||
for f in /usr/lib/nodewatcher-json.d/*.sh; do
|
||||
tmp="$($f)"
|
||||
if [ $? -ne 0 ]; then
|
||||
debug "Error when executing subscript $f, exiting!"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
SCRIPT_DATA_DIR=$(dirname "$SCRIPT_DATA_FILE")
|
||||
test -d "$SCRIPT_DATA_DIR" || mkdir -p "$SCRIPT_DATA_DIR"
|
||||
}
|
||||
|
||||
LANG=C
|
||||
|
||||
#Erzeugt die statusdaten
|
||||
debug "Generate actual status data"
|
||||
crawl
|
||||
|
||||
exit 0
|
||||
McUles marked this conversation as resolved
Outdated
ChristianD
commented
Das gefällt mir hier nicht. Wie schon in einem anderen Kommentar gesagt, würde ich mqtt und nodewatcher-json gerne trennen. Ich würde da sogar soweit gehen und 2 Cronjobs anlegen: root@knoblauchsland-ths:/usr/lib/micron.d# cat fff-nodewatcher im moment haben wir es so, ich würde daher vorschlagen die /usr/sbin/nodewatcher-json läuft wie der /usr/sbin/nodewatcher mit sleep 0 29 und ein weiterer Cronjob nennen wir ihn nodewatcherjson-mqtt-proxy läuft dann wie der /usr/sbin/alfred-mqtt-proxy mit 70 85. Diesen 2. Cronjob würde ich dann ins fff-mqtt-monitoring Paket packen. Als kleinen Bonus sind wir Alfred hier auf jeden Fall auch los geworden :) Das gefällt mir hier nicht.
Wie schon in einem anderen Kommentar gesagt, würde ich mqtt und nodewatcher-json gerne trennen. Ich würde da sogar soweit gehen und 2 Cronjobs anlegen:
root@knoblauchsland-ths:/usr/lib/micron.d# cat fff-nodewatcher
*/5 * * * * sleep $(/usr/bin/random 0 29); /usr/sbin/nodewatcher
root@knoblauchsland-ths:/usr/lib/micron.d# cat fff-alfred-monitoring-proxy
*/5 * * * * sleep $(/usr/bin/random 70 85); /usr/sbin/alfred-monitoring-proxy
root@knoblauchsland-ths:/usr/lib/micron.d# cat fff-alfred-mqtt-proxy
*/5 * * * * sleep $(/usr/bin/random 70 85); /usr/sbin/alfred-mqtt-proxy
im moment haben wir es so, ich würde daher vorschlagen die /usr/sbin/nodewatcher-json läuft wie der /usr/sbin/nodewatcher mit sleep 0 29 und ein weiterer Cronjob nennen wir ihn nodewatcherjson-mqtt-proxy läuft dann wie der /usr/sbin/alfred-mqtt-proxy mit 70 85. Diesen 2. Cronjob würde ich dann ins fff-mqtt-monitoring Paket packen.
Als kleinen Bonus sind wir Alfred hier auf jeden Fall auch los geworden :)
|
|
@ -0,0 +1,143 @@
|
|||
#!/bin/sh
|
||||
. /lib/functions.sh
|
||||
SCRIPT_DATA_FILE=$(uci get nodewatcher.@script[0].data_file).json
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
json_load_file $SCRIPT_DATA_FILE
|
||||
|
||||
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 > $SCRIPT_DATA_FILE
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
SCRIPT_DATA_FILE=$(uci get nodewatcher.@script[0].data_file).json
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
json_load_file $SCRIPT_DATA_FILE
|
||||
|
||||
config_load simple-tc
|
||||
tc_enabled="0"
|
||||
tc_in="0"
|
||||
tc_out="0"
|
||||
parseTcInterface() {
|
||||
local iface="$1"
|
||||
|
||||
config_get ifname "$iface" ifname
|
||||
[ "wan" = "$ifname" ] || return
|
||||
|
||||
config_get tc_enabled "$iface" enabled "0"
|
||||
config_get tc_in "$iface" limit_ingress "0"
|
||||
config_get tc_out "$iface" limit_egress "0"
|
||||
}
|
||||
config_foreach parseTcInterface 'interface'
|
||||
|
||||
json_add_object "traffic_control"
|
||||
json_add_object "wan"
|
||||
|
||||
json_add_string "enabled" "$tc_enabled"
|
||||
json_add_string "in" "$tc_in"
|
||||
json_add_string "out" "$tc_out"
|
||||
|
||||
json_close_object #wan
|
||||
json_close_object #traffic_control
|
||||
|
||||
json_dump > $SCRIPT_DATA_FILE
|
||||
|
||||
#exit 0
|
|
@ -0,0 +1,33 @@
|
|||
#!/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_add_object "airtime"
|
||||
|
||||
w2dump="$(iw dev w2ap survey dump 2> /dev/null | sed '/Survey/,/\[in use\]/d')"
|
||||
if [ -n "$w2dump" ] ; then
|
||||
json_add_object "w2"
|
||||
w2_ACT="$(ACTIVE=$(echo "$w2dump" | grep "active time:"); set ${ACTIVE:-0 0 0 0 0}; echo -e "${4}")"
|
||||
w2_BUS="$(BUSY=$(echo "$w2dump" | grep "busy time:"); set ${BUSY:-0 0 0 0 0}; echo -e "${4}")"
|
||||
json_add_string "active" "$w2_ACT"
|
||||
json_add_string "busy" "$w2_BUS"
|
||||
json_close_object #w2
|
||||
fi
|
||||
|
||||
w5dump="$(iw dev w5ap survey dump 2> /dev/null | sed '/Survey/,/\[in use\]/d')"
|
||||
if [ -n "$w5dump" ] ; then
|
||||
json_add_object "w5"
|
||||
w5_ACT="$(ACTIVE=$(echo "$w5dump" | grep "active time:"); set ${ACTIVE:-0 0 0 0 0}; echo -e "${4}")"
|
||||
w5_BUS="$(BUSY=$(echo "$w5dump" | grep "busy time:"); set ${BUSY:-0 0 0 0 0}; echo -e "${4}")"
|
||||
json_add_string "active" "$w5_ACT"
|
||||
json_add_string "busy" "$w5_BUS"
|
||||
json_close_object #w5
|
||||
fi
|
||||
json_close_object #airtime
|
||||
|
||||
json_dump > $SCRIPT_DATA_FILE
|
||||
|
||||
#exit 0
|
Das
-m "$(cat $SCRIPT_DATA_FILE)"
ist vermutlich nicht so geschickt. Irgendwann ist nämlich auch mal der Puffer für Kommandozeile voll :)Meine lokale man page sagt:
Kann das das openwrt
mosquitto_pub
vielleicht auch?Alternativ gibt es auch noch:
Damit könnte man sich das zwischenspeichern in einer Datei eventuell komplett sparen.
Die Datei direkt übergeben mit -f funktioniert.
Einsparen der Datei wird nicht so einfach funktionieren weil die einzelnen Scripts die Datei öffnen und ergänzen.
Hier werden auch in vorherige Nodes Daten eingefügt.
Wenn es hier noch eine schlauere Idee gibt, gerne.
Ich würde die Datei gerne behalten. Es kann ja sein das jemand (also irgendein Script o.ä.) anders auch an die json ran will und was damit tun will und nicht nur der mqtt. Wir sollten Nodewatcher-json und mqtt mMn getrennt halten.
Eventuell sollte man daraus sogar 2 Patches machen:
(Name frei erfunden, gerne anpassen ;))
Im Moment sind die Patches ja eh ein ziemliches durcheinander und sollten noch sortiert werden.
Mittelfristig müsste man dann überlegen ob man dem Monitoring wieder ein API verpasst wo man die json hinwirft oder ob das Monitoring auch einfach auf den mqtt zugreift und sich dort die Daten holt, mir wäre letztes deutlich lieber weil man dann weniger in der Firmware pflegen muss.