openwrt-munin-node/munin-node

30 lines
1.6 KiB
Plaintext
Raw Permalink Normal View History

#!/bin/sh
base="/etc/munin-node" # plugins should be installed at plugins.d inside $base
myname='openwrt-munin-node'
2016-03-15 20:19:41 +00:00
ver='1.2'
host=`cat /proc/sys/kernel/hostname`
modules=""
2015-02-19 22:44:42 +00:00
register_module() { mn=`echo $1|sed 's/:$//'`;me=`echo $2|sed 's/:$//'`;shift 2;for f in config fetch;do rme=$me;[ "`echo $me|head -c1`" == "_" ]&&rme="$f$me";eval "${f}_$mn() { $rme `[ "$f" == "config" -a "$me" == "$rme" ]&&echo config` $@ \$@; };";done; }
is_registered() { [ ! -z "`command -v config_$1`" ] && [ ! -z "`command -v fetch_$1`" ] && return 0;return 1; }
register_modules() { for mod in `ls -1 $base/plugins.d/*`;do [ -f $mod -a -x $mod ] || continue;modn=`basename $mod`;[ "$modn" != "if" ]&&modules="$modules $modn";register_module $modn $mod;done; }
register_iface_modules() { for iface in `ifconfig|grep '^\w'|awk '{print $1}'`;do [ "$iface" == "lo" ] && continue; iface_mod=`echo $iface|sed -e 's/\./VLAN/;s/\-/_/'`;modules="$modules if_$iface_mod";register_module if_$iface_mod _if $iface;done; }
register_modules
is_registered 'if' && register_iface_modules
echo "# munin node at $host"
while read cmd mod;do
cmd=${cmd%[-[:space:]]};mod=${mod%[-[:space:]]}
case $cmd in
list) echo $modules;;
config) is_registered $mod && config_$mod || echo "# Unknown plugin";echo .;;
fetch) is_registered $mod && fetch_$mod || echo "# Unknown plugin";echo .;;
nodes) echo -e "$host\n.";;
version) echo -e "munin node on $host version: $ver ($myname)\n.";;
help) echo "# Commands: list, config, fetch, nodes, version, help, quit";;
quit) exit 0;;
*) echo "# Unknown command. Try help."
esac
done