2007-06-11 17:45:16 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
#
|
|
|
|
|
# Simple Bourne Shell script that implements Munin protocoll and
|
|
|
|
|
# some common Linux plugins.
|
|
|
|
|
#
|
|
|
|
|
# For latest version, see http://muninlite.sf.net/
|
|
|
|
|
#
|
2011-01-14 21:24:16 +01:00
|
|
|
|
# Copyright (c) 2007-2011 Rune Nordb<64>e Skillingstad <rune@skillingstad.no>
|
2007-06-11 17:45:16 +02:00
|
|
|
|
#
|
|
|
|
|
# Licensed under GPLv2 (see LICENSE file for full License)
|
|
|
|
|
#
|
|
|
|
|
# $Id: $
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
VERSION="@@VERSION@@"
|
|
|
|
|
|
2007-11-30 11:43:07 +01:00
|
|
|
|
@@CONF@@
|
|
|
|
|
|
2011-01-14 21:24:16 +01:00
|
|
|
|
# if plugindir_ is present in $PLUGINS,
|
|
|
|
|
# iexecutables (scripts, binaries) matching the following pattern will be scanned and operated as plugins
|
|
|
|
|
PLUGINPATTERN=$(dirname $0)"/munin-node-plugin.d/*"
|
|
|
|
|
|
2007-06-11 17:45:16 +02:00
|
|
|
|
# Remove unwanted plugins from this list
|
|
|
|
|
PLUGINS="@@PLUGINS@@"
|
2007-11-30 11:43:07 +01:00
|
|
|
|
# ===== LIB FUNCTIONS =====
|
|
|
|
|
clean_fieldname() {
|
|
|
|
|
echo "$@" | sed -e 's/^[^A-Za-z_]/_/' -e 's/[^A-Za-z0-9_]/_/g'
|
|
|
|
|
}
|
2007-06-11 17:45:16 +02:00
|
|
|
|
|
|
|
|
|
# ===== 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
|
2019-07-19 05:56:35 +02:00
|
|
|
|
for INTER in $(grep '^ *\(ppp\|eth\|wlan\|ath\|ra\|ipsec\|tap\)\([^:]\)\{1,\}:' /proc/net/dev | cut -f1 -d: | sed 's/ //g');
|
2007-06-11 17:45:16 +02:00
|
|
|
|
do
|
2011-01-27 11:02:06 +01:00
|
|
|
|
INTERRES=$(echo $INTER | sed 's/\./VLAN/')
|
|
|
|
|
RES="$RES if_$INTERRES"
|
|
|
|
|
eval "fetch_if_${INTERRES}() { fetch_if $INTER $@; };"
|
|
|
|
|
eval "config_if_${INTERRES}() { config_if $INTER $@; };"
|
2007-06-11 17:45:16 +02:00
|
|
|
|
done
|
|
|
|
|
elif [ "$PLUG" = "if_err_" ]; then
|
2019-07-19 05:56:35 +02:00
|
|
|
|
for INTER in $(grep '^ *\(ppp\|eth\|wlan\|ath\|ra\|ipsec\|tap\)\([^:]\)\{1,\}:' /proc/net/dev | cut -f1 -d: | sed 's/ //g');
|
2007-06-11 17:45:16 +02:00
|
|
|
|
do
|
2011-01-27 11:02:06 +01:00
|
|
|
|
INTERRES=$(echo $INTER | sed 's/\./VLAN/')
|
|
|
|
|
RES="$RES if_err_$INTERRES"
|
|
|
|
|
eval "fetch_if_err_${INTERRES}() { fetch_if_err $INTER $@; };"
|
|
|
|
|
eval "config_if_err_${INTERRES}() { config_if_err $INTER $@; };"
|
2007-06-11 17:45:16 +02:00
|
|
|
|
done
|
|
|
|
|
elif [ "$PLUG" = "netstat" ]; then
|
|
|
|
|
if netstat -s >/dev/null 2>&1; then
|
|
|
|
|
RES="$RES netstat"
|
|
|
|
|
fi
|
2011-01-14 21:24:16 +01:00
|
|
|
|
elif [ "$PLUG" = "plugindir_" ]; then
|
|
|
|
|
for MYPLUGIN in $(ls -1 $PLUGINPATTERN 2>/dev/null );
|
|
|
|
|
do
|
|
|
|
|
if [ -f $MYPLUGIN -a -x $MYPLUGIN ]; then
|
|
|
|
|
MYPLUGINNAME=$(basename $MYPLUGIN)
|
|
|
|
|
#ensure we don't have name collision
|
|
|
|
|
if echo "$RES" | grep "\b$MYPLUGINNAME\b" >/dev/null 2>&1 ; then
|
|
|
|
|
MYPLUGINNAME="plugindir_$MYPLUGINNAME"
|
|
|
|
|
fi
|
|
|
|
|
RES="$RES $MYPLUGINNAME"
|
|
|
|
|
eval "fetch_${MYPLUGINNAME}() { $MYPLUGIN ; };"
|
|
|
|
|
eval "config_${MYPLUGINNAME}() { $MYPLUGIN config ; };"
|
|
|
|
|
fi
|
|
|
|
|
done
|
2007-06-11 17:45:16 +02:00
|
|
|
|
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
|
|
|
|
|
|