fff-nodewatcher: style: unify to spaces

Signed-off-by: Tim Niemeyer <tim@tn-x.org>
Reviewed-by: Jan Kraus <mayosemmel@gmail.com>
- two more tabs to spaces
Signed-off-by: Tobias Klaus <tk+ff@meskal.net>
This commit is contained in:
Tim Niemeyer 2016-06-11 17:20:47 +02:00 committed by Tobias Klaus
parent f765eef457
commit f458f196fc
1 changed files with 92 additions and 92 deletions

View File

@ -9,15 +9,15 @@ test -f /tmp/started || exit
#Get the configuration from the uci configuration file
#If it does not exists, then get it from a normal bash file with variables.
if [ -f /etc/config/nodewatcher ];then
SCRIPT_ERROR_LEVEL=`uci get nodewatcher.@script[0].error_level`
SCRIPT_LOGFILE=`uci get nodewatcher.@script[0].logfile`
SCRIPT_DATA_FILE=`uci get nodewatcher.@script[0].data_file`
MESH_INTERFACE=`uci get nodewatcher.@network[0].mesh_interface`
IFACEBLACKLIST=`uci get nodewatcher.@network[0].iface_blacklist`
IPWHITELIST=`uci get nodewatcher.@network[0].ip_whitelist`
SCRIPT_STATUS_FILE=`uci get nodewatcher.@script[0].status_text_file`
SCRIPT_ERROR_LEVEL=`uci get nodewatcher.@script[0].error_level`
SCRIPT_LOGFILE=`uci get nodewatcher.@script[0].logfile`
SCRIPT_DATA_FILE=`uci get nodewatcher.@script[0].data_file`
MESH_INTERFACE=`uci get nodewatcher.@network[0].mesh_interface`
IFACEBLACKLIST=`uci get nodewatcher.@network[0].iface_blacklist`
IPWHITELIST=`uci get nodewatcher.@network[0].ip_whitelist`
SCRIPT_STATUS_FILE=`uci get nodewatcher.@script[0].status_text_file`
else
. `dirname $0`/nodewatcher_config
. `dirname $0`/nodewatcher_config
fi
if [ $SCRIPT_ERROR_LEVEL -gt "1" ]; then
@ -32,73 +32,73 @@ fi
#this method checks id the logfile has bekome too big and deletes the first X lines
delete_log() {
if [ -f $SCRIPT_LOGFILE ]; then
if [ `ls -la $SCRIPT_LOGFILE | awk '{ print $5 }'` -gt "6000" ]; then
sed -i '1,60d' $SCRIPT_LOGFILE
if [ -f $SCRIPT_LOGFILE ]; then
if [ `ls -la $SCRIPT_LOGFILE | awk '{ print $5 }'` -gt "6000" ]; then
sed -i '1,60d' $SCRIPT_LOGFILE
err "`date`: Logfile has been made smaller"
fi
fi
fi
fi
}
inArray() {
local value
for value in $1; do
if [ "$value" = "$2" ]; then
return 0
fi
done
return 1
local value
for value in $1; do
if [ "$value" = "$2" ]; then
return 0
fi
done
return 1
}
#this method generates the crawl data xml file that is beeing fetched by netmon
#and provided by a small local httpd
crawl() {
#Get system data from other locations
err "`date`: Collecting basic system status data"
hostname="$(cat /proc/sys/kernel/hostname)"
description="$(uci get system.@system[0].description)"
if [ -n "$description" ]; then
description="<description>$description</description>"
fi
latitude="$(uci get system.@system[0].latitude)"
longitude="$(uci get system.@system[0].longitude)"
if [ -n "$longitude" -a -n "$latitude" ]; then
geo="<geo><lat>$latitude</lat><lng>$longitude</lng></geo>";
fi
position_comment="$(uci get system.@system[0].position_comment)"
if [ -n "$position_comment" ]; then
position_comment="<position_comment>$position_comment</position_comment>"
fi
contact="$(uci get system.@system[0].contact)"
if [ -n "$contact" ]; then
contact="<contact>$contact</contact>"
fi
uptime=$(awk '{ printf "<uptime>"$1"</uptime><idletime>"$2"</idletime>" }' /proc/uptime)
#Get system data from other locations
err "`date`: Collecting basic system status data"
hostname="$(cat /proc/sys/kernel/hostname)"
description="$(uci get system.@system[0].description)"
if [ -n "$description" ]; then
description="<description>$description</description>"
fi
latitude="$(uci get system.@system[0].latitude)"
longitude="$(uci get system.@system[0].longitude)"
if [ -n "$longitude" -a -n "$latitude" ]; then
geo="<geo><lat>$latitude</lat><lng>$longitude</lng></geo>";
fi
position_comment="$(uci get system.@system[0].position_comment)"
if [ -n "$position_comment" ]; then
position_comment="<position_comment>$position_comment</position_comment>"
fi
contact="$(uci get system.@system[0].contact)"
if [ -n "$contact" ]; then
contact="<contact>$contact</contact>"
fi
uptime=$(awk '{ printf "<uptime>"$1"</uptime><idletime>"$2"</idletime>" }' /proc/uptime)
memory=$(awk '
/^MemTotal/ { printf "<memory_total>"$2"</memory_total>" }
/^Cached:/ { printf "<memory_caching>"$2"</memory_caching>" }
/^Buffers/ { printf "<memory_buffering>"$2"</memory_buffering>" }
/^MemFree/ { printf "<memory_free>"$2"</memory_free>" }
' /proc/meminfo)
cpu=$(awk -F': ' '
cpu=$(awk -F': ' '
/model/ { printf "<cpu>"$2"</cpu>" }
/system type/ { printf "<chipset>"$2"</chipset>" }
' /proc/cpuinfo)
model="<model>$(cat /var/sysinfo/model)</model>"
local_time="`date +%s`"
load=$(awk '{ printf "<loadavg>"$3"</loadavg><processes>"$4"</processes>" }' /proc/loadavg)
model="<model>$(cat /var/sysinfo/model)</model>"
local_time="`date +%s`"
load=$(awk '{ printf "<loadavg>"$3"</loadavg><processes>"$4"</processes>" }' /proc/loadavg)
err "`date`: Collecting version information"
batman_adv_version=$(cat /sys/module/batman_adv/version)
kernel_version=$(uname -r)
fastd_version=$(fastd -v | awk '{ print $2 }')
nodewatcher_version=$SCRIPT_VERSION
if [ -f "$SCRIPT_STATUS_FILE" ]; then
status_text="<status_text>$(cat "$SCRIPT_STATUS_FILE")</status_text>"
fi
batman_adv_version=$(cat /sys/module/batman_adv/version)
kernel_version=$(uname -r)
fastd_version=$(fastd -v | awk '{ print $2 }')
nodewatcher_version=$SCRIPT_VERSION
if [ -f "$SCRIPT_STATUS_FILE" ]; then
status_text="<status_text>$(cat "$SCRIPT_STATUS_FILE")</status_text>"
fi
# example for /etc/openwrt_release:
#DISTRIB_ID="OpenWrt"
@ -107,7 +107,7 @@ crawl() {
#DISTRIB_CODENAME="attitude_adjustment"
#DISTRIB_TARGET="atheros/generic"
#DISTRIB_DESCRIPTION="OpenWrt Attitude Adjustment 12.09-rc1"
. /etc/openwrt_release
. /etc/openwrt_release
distname=$DISTRIB_ID
distversion=$DISTRIB_RELEASE
@ -116,14 +116,14 @@ crawl() {
#BUILD_DATE="build date: Di 29. Jan 19:33:34 CET 2013"
#OPENWRT_CORE_REVISION="35298"
#OPENWRT_FEEDS_PACKAGES_REVISION="35298"
. /etc/firmware_release
SYSTEM_DATA="<status>online</status>$status_text<hostname>$hostname</hostname>${description}${geo}${position_comment}${contact}<distname>$distname</distname><distversion>$distversion</distversion>$cpu$model$memory$load$uptime<local_time>$local_time</local_time><batman_advanced_version>$batman_adv_version</batman_advanced_version><kernel_version>$kernel_version</kernel_version><fastd_version>$fastd_version</fastd_version><nodewatcher_version>$nodewatcher_version</nodewatcher_version><firmware_version>$FIRMWARE_VERSION</firmware_version><firmware_community>$FIRMWARE_COMMUNITY</firmware_community><firmware_revision>$BUILD_DATE</firmware_revision><openwrt_core_revision>$OPENWRT_CORE_REVISION</openwrt_core_revision><openwrt_feeds_packages_revision>$OPENWRT_FEEDS_PACKAGES_REVISION</openwrt_feeds_packages_revision>"
. /etc/firmware_release
SYSTEM_DATA="<status>online</status>$status_text<hostname>$hostname</hostname>${description}${geo}${position_comment}${contact}<distname>$distname</distname><distversion>$distversion</distversion>$cpu$model$memory$load$uptime<local_time>$local_time</local_time><batman_advanced_version>$batman_adv_version</batman_advanced_version><kernel_version>$kernel_version</kernel_version><fastd_version>$fastd_version</fastd_version><nodewatcher_version>$nodewatcher_version</nodewatcher_version><firmware_version>$FIRMWARE_VERSION</firmware_version><firmware_community>$FIRMWARE_COMMUNITY</firmware_community><firmware_revision>$BUILD_DATE</firmware_revision><openwrt_core_revision>$OPENWRT_CORE_REVISION</openwrt_core_revision><openwrt_feeds_packages_revision>$OPENWRT_FEEDS_PACKAGES_REVISION</openwrt_feeds_packages_revision>"
err "`date`: Collecting information from network interfaces"
#Get interfaces
interface_data=""
#Loop interfaces
#Get interfaces
interface_data=""
#Loop interfaces
for filename in `grep 'up\|unknown' /sys/class/net/*/operstate`; do
ifpath=${filename%/operstate*}
iface=${ifpath#/sys/class/net/}
@ -145,7 +145,7 @@ crawl() {
traffic_rx=`cat $ifpath/statistics/rx_bytes`
traffic_tx=`cat $ifpath/statistics/tx_bytes`
interface_data=$interface_data"<$iface><name>$iface</name>$addrs<traffic_rx>$traffic_rx</traffic_rx><traffic_tx>$traffic_tx</traffic_tx>"
interface_data=$interface_data$(iwconfig ${iface} 2>/dev/null | awk -F':' '
@ -155,10 +155,10 @@ crawl() {
/Freq/{ split($3, f, " "); printf "<wlan_frequency>"f[1]f[2]"</wlan_frequency>" }
/Tx-Power/{ split($0, p, "="); sub(/[[:space:]]*$/, "", p[2]); printf "<wlan_tx_power>"p[2]"</wlan_tx_power>" }
')"</$iface>"
done
done
err "`date`: Collecting information from batman advanced and it´s interfaces"
#B.A.T.M.A.N. advanced
#B.A.T.M.A.N. advanced
if [ -f /sys/module/batman_adv/version ]; then
for iface in $(grep active /sys/class/net/*/batman_adv/iface_status); do
status=${iface#*:}
@ -184,41 +184,41 @@ crawl() {
i++
}
}' /sys/kernel/debug/batman_adv/bat0/originators)
batman_adv_gateway_mode=$(batctl gw)
batman_adv_gateway_list=$(awk \
'BEGIN { FS=" "; i=0 }
/Gateway/ { next }
/No gateways/ { next }
{ sub("=>", "true", $0)
sub(" ", "false", $0)
sub("\\(", "", $0)
sub("\\)", "", $0)
sub("\\[", "", $0)
sub("\\]:", "", $0)
sub(" ", " ", $0)
printf "<gateway_"i"><selected>"$1"</selected><gateway>"$2"</gateway><link_quality>"$3"</link_quality><nexthop>"$4"</nexthop><outgoing_interface>"$5"</outgoing_interface><gw_class>"$6" "$7" "$8"</gw_class></gateway_"i">"
i++
}' /sys/kernel/debug/batman_adv/bat0/gateways)
batman_adv_gateway_mode=$(batctl gw)
batman_adv_gateway_list=$(awk \
'BEGIN { FS=" "; i=0 }
/Gateway/ { next }
/No gateways/ { next }
{ sub("=>", "true", $0)
sub(" ", "false", $0)
sub("\\(", "", $0)
sub("\\)", "", $0)
sub("\\[", "", $0)
sub("\\]:", "", $0)
sub(" ", " ", $0)
printf "<gateway_"i"><selected>"$1"</selected><gateway>"$2"</gateway><link_quality>"$3"</link_quality><nexthop>"$4"</nexthop><outgoing_interface>"$5"</outgoing_interface><gw_class>"$6" "$7" "$8"</gw_class></gateway_"i">"
i++
}' /sys/kernel/debug/batman_adv/bat0/gateways)
fi
err "`date`: Collecting information about conected clients"
#CLIENTS
client_count=0
CLIENT_INTERFACES=$(bridge link | awk '$2 !~/^bat/{ printf $2" " }')
for clientif in ${CLIENT_INTERFACES}; do
local cc=$(bridge fdb show br $MESH_INTERFACE brport $clientif | grep -v self | grep -v permanent -c)
client_count=$((client_count + $cc))
done
#CLIENTS
client_count=0
CLIENT_INTERFACES=$(bridge link | awk '$2 !~/^bat/{ printf $2" " }')
for clientif in ${CLIENT_INTERFACES}; do
local cc=$(bridge fdb show br $MESH_INTERFACE brport $clientif | grep -v self | grep -v permanent -c)
client_count=$((client_count + $cc))
done
err "`date`: Putting all information into a XML-File and save it at "$SCRIPT_DATA_FILE
DATA="<?xml version='1.0' standalone='yes'?><data><system_data>$SYSTEM_DATA</system_data><interface_data>$interface_data</interface_data><batman_adv_interfaces>$BATMAN_ADV_INTERFACES</batman_adv_interfaces><batman_adv_originators>$batman_adv_originators</batman_adv_originators><batman_adv_gateway_mode>$batman_adv_gateway_mode</batman_adv_gateway_mode><batman_adv_gateway_list>$batman_adv_gateway_list</batman_adv_gateway_list><client_count>$client_count</client_count></data>"
DATA="<?xml version='1.0' standalone='yes'?><data><system_data>$SYSTEM_DATA</system_data><interface_data>$interface_data</interface_data><batman_adv_interfaces>$BATMAN_ADV_INTERFACES</batman_adv_interfaces><batman_adv_originators>$batman_adv_originators</batman_adv_originators><batman_adv_gateway_mode>$batman_adv_gateway_mode</batman_adv_gateway_mode><batman_adv_gateway_list>$batman_adv_gateway_list</batman_adv_gateway_list><client_count>$client_count</client_count></data>"
#write data to hxml file that provides the data on httpd
SCRIPT_DATA_DIR=$(dirname $SCRIPT_DATA_FILE)
test -d $SCRIPT_DATA_DIR || mkdir -p $SCRIPT_DATA_DIR
echo $DATA | gzip | tee $SCRIPT_DATA_FILE | alfred -s 64
#write data to hxml file that provides the data on httpd
SCRIPT_DATA_DIR=$(dirname $SCRIPT_DATA_FILE)
test -d $SCRIPT_DATA_DIR || mkdir -p $SCRIPT_DATA_DIR
echo $DATA | gzip | tee $SCRIPT_DATA_FILE | alfred -s 64
}
LANG=C