muninlite/munin-node.in

110 lines
2.3 KiB
Plaintext
Raw Normal View History

#!/bin/sh
#
# Simple Bourne Shell script that implements Munin protocoll and
# some common Linux plugins.
#
# For latest version, see http://muninlite.sf.net/
#
# Copyright (c) 2007 Rune Nordb<64>e Skillingstad <rune@skillingstad.no>
#
# Licensed under GPLv2 (see LICENSE file for full License)
#
# $Id: $
#
VERSION="@@VERSION@@"
@@CONF@@
# Remove unwanted plugins from this list
PLUGINS="@@PLUGINS@@"
# ===== LIB FUNCTIONS =====
clean_fieldname() {
echo "$@" | sed -e 's/^[^A-Za-z_]/_/' -e 's/[^A-Za-z0-9_]/_/g'
}
# ===== PLUGINS CODE =====
@@PLSTR@@
# ===== NODE CODE =====
do_list() {
echo $PLUGINS
}
do_nodes() {
echo "$HOSTNAME"
echo "."
}
do_config() {
if echo "$PLUGINS" | grep "\b$1\b" >/dev/null 2>&1; then
config_$1
else
echo "# Unknown service"
fi
echo "."
}
do_fetch() {
if echo "$PLUGINS" | grep "\b$1\b" >/dev/null 2>&1; then
fetch_$1
else
echo "# Unknown service"
fi
echo "."
}
do_version() {
echo "munins node on $HOSTNAME version: $VERSION (munin-lite)"
}
do_quit() {
exit 0
}
# ===== Runtime config =====
RES=""
for PLUG in $PLUGINS
do
if [ "$PLUG" = "if_" ]; then
for INTER in $(grep '^ *\(eth\|wlan\|ath\|ra\)[0-9]\{1,\}:' /proc/net/dev | cut -f1 -d: | sed 's/ //g');
do
RES="$RES if_$INTER"
eval "fetch_if_${INTER}() { fetch_if $INTER $@; };"
eval "config_if_${INTER}() { config_if $INTER $@; };"
done
elif [ "$PLUG" = "if_err_" ]; then
for INTER in $(grep '^ *\(eth\|wlan\|ath\|ra\)[0-9]\{1,\}:' /proc/net/dev | cut -f1 -d: | sed 's/ //g');
do
RES="$RES if_err_$INTER"
eval "fetch_if_err_${INTER}() { fetch_if_err $INTER $@; };"
eval "config_if_err_${INTER}() { config_if_err $INTER $@; };"
done
elif [ "$PLUG" = "netstat" ]; then
if netstat -s >/dev/null 2>&1; then
RES="$RES netstat"
fi
else
RES="$RES $PLUG";
fi
done
PLUGINS=$RES
# ===== MAIN LOOP =====
FUNCTIONS="list nodes config fetch version quit"
HOSTNAME=$(hostname -f 2>/dev/null || hostname)
echo "# munin node at $HOSTNAME"
while read arg0 arg1
do
arg0=$(echo "$arg0" | xargs)
arg1=$(echo "$arg1" | xargs)
if ! echo "$FUNCTIONS" | grep "\b$arg0\b" >/dev/null 2>&1 ; then
echo "# Unknown command. Try" $(echo "$FUNCTIONS" | sed -e 's/\( [[:alpha:]]\{1,\}\)/,\1/g' -e 's/,\( [[:alpha:]]\{1,\}\)$/ or\1/')
continue
fi
do_$arg0 $arg1
done