firmware/src/packages/fff/fff-nodewatcher/files/usr/lib/nodewatcher.d/10-systemdata.sh

120 lines
4.4 KiB
Bash
Raw Normal View History

nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-only
#
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
# Netmon Nodewatcher (C) 2010-2012 Freifunk Oldenburg
SCRIPT_STATUS_FILE=$(uci get nodewatcher.@script[0].status_text_file)
SCRIPT_VERSION=$(cat /etc/nodewatcher_version)
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
debug() {
(>&2 echo "nodewatcher: $1")
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
}
debug "Collecting basic system status data"
SYSTEM_DATA="<status>online</status>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
hostname="$(cat /proc/sys/kernel/hostname)"
mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-client/address 2>/dev/null)
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
[ "$hostname" = "OpenWrt" ] && hostname="$mac"
[ "$hostname" = "FFF" ] && hostname="$mac"
SYSTEM_DATA="$SYSTEM_DATA<hostname>$hostname</hostname>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
description="$(uci -q get fff.system.description)"
[ -n "$description" ] && SYSTEM_DATA="$SYSTEM_DATA<description><![CDATA[$description]]></description>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
latitude="$(uci -q get fff.system.latitude)"
longitude="$(uci -q get fff.system.longitude)"
if [ -n "$longitude" -a -n "$latitude" ]; then
SYSTEM_DATA="$SYSTEM_DATA<geo><lat>$latitude</lat><lng>$longitude</lng></geo>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
fi
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
position_comment="$(uci -q get fff.system.position_comment)"
[ -n "$position_comment" ] && SYSTEM_DATA="$SYSTEM_DATA<position_comment><![CDATA[$position_comment]]></position_comment>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
contact="$(uci -q get fff.system.contact)"
[ -n "$contact" ] && SYSTEM_DATA="$SYSTEM_DATA<contact>$contact</contact>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
uptime=$(awk '{ printf "<uptime>"$1"</uptime><idletime>"$2"</idletime>" }' /proc/uptime)
SYSTEM_DATA="$SYSTEM_DATA$uptime"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
memory=$(awk '
/^MemTotal/ { printf "<memory_total>"$2"</memory_total>" }
/^MemAvail/ { printf "<memory_available>"$2"</memory_available>" }
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
/^Cached:/ { printf "<memory_caching>"$2"</memory_caching>" }
/^Buffers/ { printf "<memory_buffering>"$2"</memory_buffering>" }
/^MemFree/ { printf "<memory_free>"$2"</memory_free>" }
' /proc/meminfo)
SYSTEM_DATA="$SYSTEM_DATA$memory"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
cpu=$(awk -F': ' '
/model/ { printf "<cpu>"$2"</cpu>" }
/system type/ { printf "<chipset>"$2"</chipset>" }
/platform/ { printf "<chipset>"$2"</chipset>" }
' /proc/cpuinfo)
SYSTEM_DATA="$SYSTEM_DATA$cpu"
SYSTEM_DATA="$SYSTEM_DATA<model>$(cat /var/sysinfo/model)</model>"
SYSTEM_DATA="$SYSTEM_DATA<local_time>$(date +%s)</local_time>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
load=$(awk '{ printf "<loadavg>"$3"</loadavg><processes>"$4"</processes>" }' /proc/loadavg)
SYSTEM_DATA="$SYSTEM_DATA$load"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
debug "Collecting version information"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
if [ -e /sys/module/batman_adv/version ]; then
SYSTEM_DATA="$SYSTEM_DATA<batman_advanced_version>$(cat /sys/module/batman_adv/version)</batman_advanced_version>"
fi
SYSTEM_DATA="$SYSTEM_DATA<kernel_version>$(uname -r)</kernel_version>"
SYSTEM_DATA="$SYSTEM_DATA<nodewatcher_version>$SCRIPT_VERSION</nodewatcher_version>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
if [ -x /usr/bin/fastd ]; then
SYSTEM_DATA="$SYSTEM_DATA<fastd_version>$(/usr/bin/fastd -v | awk '{ print $2 }')</fastd_version>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
fi
if [ -x /usr/sbin/babeld ]; then
SYSTEM_DATA="$SYSTEM_DATA<babel_version>$(/usr/sbin/babeld -V 2>&1)</babel_version>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
fi
# example for /etc/openwrt_release:
#DISTRIB_ID="OpenWrt"
#DISTRIB_RELEASE="Attitude Adjustment"
#DISTRIB_REVISION="r35298"
#DISTRIB_CODENAME="attitude_adjustment"
#DISTRIB_TARGET="atheros/generic"
#DISTRIB_DESCRIPTION="OpenWrt Attitude Adjustment 12.09-rc1"
. /etc/openwrt_release
SYSTEM_DATA="$SYSTEM_DATA<distname>$DISTRIB_ID</distname>"
SYSTEM_DATA="$SYSTEM_DATA<distversion>$DISTRIB_RELEASE</distversion>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
# example for /etc/firmware_release:
#FIRMWARE_VERSION="95f36685e7b6cbf423f02cf5c7f1e785fd4ccdae-dirty"
#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="$SYSTEM_DATA<firmware_version>$FIRMWARE_VERSION</firmware_version>"
SYSTEM_DATA="$SYSTEM_DATA<firmware_revision>$BUILD_DATE</firmware_revision>"
SYSTEM_DATA="$SYSTEM_DATA<openwrt_core_revision>$OPENWRT_CORE_REVISION</openwrt_core_revision>"
SYSTEM_DATA="$SYSTEM_DATA<openwrt_feeds_packages_revision>$OPENWRT_FEEDS_PACKAGES_REVISION</openwrt_feeds_packages_revision>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
debug "Collecting hood information and additional status data"
SYSTEM_DATA="$SYSTEM_DATA<hood>$(uci -q get "system.@system[0].hood")</hood>"
SYSTEM_DATA="$SYSTEM_DATA<hoodid>$(uci -q get "system.@system[0].hoodid")</hoodid>"
if [ -s "$SCRIPT_STATUS_FILE" ]; then
SYSTEM_DATA="$SYSTEM_DATA<status_text>$(cat "$SCRIPT_STATUS_FILE")</status_text>"
fi
# Checks if fastd is running
vpn_active=0
pidof fastd >/dev/null && vpn_active=1
SYSTEM_DATA="$SYSTEM_DATA<vpn_active>$vpn_active</vpn_active>"
nodewatcher: split into nodewatcher.d scripts for individual task 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>
2020-01-07 14:40:20 +01:00
echo -n "<system_data>$SYSTEM_DATA</system_data>"
exit 0