#!/bin/sh base="/etc/munin-node" # plugins should be installed at plugins.d inside $base myname='openwrt-munin-node' ver='1.1' host=`cat /proc/sys/kernel/hostname` modules="" 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