forked from freifunk-franken/firmware
Tim Niemeyer
b6c7acd704
This splits up the data extraction/assembly of the nodewatcher script into several parts and distributes them across packages, so that each nodewatcher.d subscript is located in the package providing the relevant functionality. This allows to extend the nodewatcher data by enabling/disabling packages. This scheme is not perfectly fulfilled for fff-network vs. fff-wireless, as data cannot uniquely assigned there and the XML syntax does not allow separation anyway. In general, this moves code without applying code improvements, yielding at an easy comparison of moved fragments. However, the following changes were done to improve experience: - The function writing debug output has been renamed from "err" to "debug" - Since we catch the stdout of the nodewatcher.d functions anyway, those scripts were adjusted to echo output directly instead of first writing it into a variable and then outputting it at the end. - The uci config has been kept, but initialization for the network part has been moved to the fff-network package. - Space indent has been changed to tab, which is more common in the firmware and requires less space. - Remove support for nodewatcher run without uci config. Script-based nodewatcher on other platforms will have altered code anyway, and splitting it up will prevent effective use as a blueprint for those cases. After this change, nodewatcher in firmware is supposed to be used only for this firmware. Note that since the nodewatcher.d scripts are evaluated by using their echo output, having a function created uncaught output to stdout there will corrupt the XML. Signed-off-by: Tim Niemeyer <tim@tn-x.org> [rebase and adjustments for current master, use simpler mechanism to call nodewatcher.d scripts, use tab indent, remove debug() definition where not needed, do not remove uci config, add commit message, use echo -n] Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de> Reviewed-by: Fabian Bläse <fabian@blaese.de> [remove 'local' modifier for variable not inside a function, fix typo] Signed-off-by: Fabian Bläse <fabian@blaese.de>
72 lines
1.7 KiB
Bash
Executable File
72 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# Netmon Nodewatcher (C) 2010-2012 Freifunk Oldenburg
|
|
# License; GPL v3
|
|
|
|
test -f /tmp/started || exit
|
|
|
|
# Allow only one instance
|
|
lockfile="/var/lock/${0##*/}.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
|
|
|
|
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)
|
|
|
|
if [ "$SCRIPT_ERROR_LEVEL" -gt "1" ]; then
|
|
debug() {
|
|
echo "$1" >> "$SCRIPT_LOGFILE"
|
|
}
|
|
else
|
|
debug() {
|
|
:
|
|
}
|
|
fi
|
|
|
|
#This method checks if the log file has become too big and deletes the first X lines
|
|
delete_log() {
|
|
if [ -f "$SCRIPT_LOGFILE" ]; then
|
|
if [ "$(find "$SCRIPT_LOGFILE" -printf "%s")" -gt "6000" ]; then
|
|
sed -i '1,60d' "$SCRIPT_LOGFILE"
|
|
debug "$(date): Logfile has been made smaller"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
#This method generates the crawl data XML file that is being fetched by netmon
|
|
#and provided by a small local httpd
|
|
crawl() {
|
|
debug "$(date): Putting all information into a XML-File and save it at $SCRIPT_DATA_FILE"
|
|
|
|
DATA="<?xml version='1.0' standalone='yes'?><data>"
|
|
|
|
for f in /usr/lib/nodewatcher.d/*.sh; do
|
|
tmp="$($f)"
|
|
DATA="$DATA$tmp"
|
|
done
|
|
|
|
DATA="$DATA</data>"
|
|
|
|
#write data to xml 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
|
|
|
|
#Prüft ob das logfile zu groß geworden ist
|
|
debug "$(date): Check logfile"
|
|
delete_log
|
|
|
|
#Erzeugt die statusdaten
|
|
debug "$(date): Generate actual status data"
|
|
crawl
|
|
|
|
exit 0
|