forked from freifunk-franken/firmware
145 lines
4.6 KiB
Bash
145 lines
4.6 KiB
Bash
#!/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 |