2007-06-11 17:45:16 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2019-07-23 04:52:37 +02:00
|
|
|
# Simple Bourne Shell script that implements Munin protocoll and
|
2007-06-11 17:45:16 +02:00
|
|
|
# some common Linux plugins.
|
|
|
|
#
|
|
|
|
# For latest version, see http://muninlite.sf.net/
|
|
|
|
#
|
2020-02-08 22:24:18 +01:00
|
|
|
# Copyright (c) 2007-2011 Rune Nordbøe Skillingstad <rune@skillingstad.no>
|
2019-07-23 04:52:37 +02:00
|
|
|
#
|
2007-06-11 17:45:16 +02:00
|
|
|
# Licensed under GPLv2 (see LICENSE file for full License)
|
|
|
|
#
|
|
|
|
|
|
|
|
VERSION="@@VERSION@@"
|
|
|
|
|
2020-02-08 05:32:21 +01:00
|
|
|
set -eu
|
|
|
|
|
2007-11-30 11:43:07 +01:00
|
|
|
@@CONF@@
|
|
|
|
|
2020-02-07 14:17:43 +01:00
|
|
|
# if plugindir_ is present in $PLUGINS, executables (scripts, binaries) in the specified path
|
|
|
|
# and matching the pattern will be scanned and operated as plugins
|
2020-02-09 00:00:51 +01:00
|
|
|
PLUGIN_DIRECTORY=/etc/munin/plugins
|
2020-02-07 14:17:43 +01:00
|
|
|
PLUGINPATTERN="*"
|
2011-01-14 21:24:16 +01:00
|
|
|
|
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() {
|
2020-02-07 15:15:06 +01:00
|
|
|
echo "$PLUGINS"
|
2007-06-11 17:45:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
do_nodes() {
|
|
|
|
echo "$HOSTNAME"
|
|
|
|
echo "."
|
|
|
|
}
|
|
|
|
|
|
|
|
do_config() {
|
2020-02-07 14:51:47 +01:00
|
|
|
if echo "$PLUGINS" | grep -qwF "$1"; then
|
2020-02-07 15:15:06 +01:00
|
|
|
"config_$1"
|
2007-06-11 17:45:16 +02:00
|
|
|
else
|
|
|
|
echo "# Unknown service"
|
|
|
|
fi
|
|
|
|
echo "."
|
|
|
|
}
|
|
|
|
|
|
|
|
do_fetch() {
|
2020-02-07 14:51:47 +01:00
|
|
|
if echo "$PLUGINS" | grep -qwF "$1"; then
|
2020-02-07 15:15:06 +01:00
|
|
|
"fetch_$1"
|
2007-06-11 17:45:16 +02:00
|
|
|
else
|
|
|
|
echo "# Unknown service"
|
|
|
|
fi
|
|
|
|
echo "."
|
|
|
|
}
|
|
|
|
|
|
|
|
do_version() {
|
2020-02-07 14:35:52 +01:00
|
|
|
echo "munins node on $HOSTNAME version: $VERSION (muninlite)"
|
2007-06-11 17:45:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
do_quit() {
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# ===== Runtime config =====
|
|
|
|
RES=""
|
2020-02-08 04:58:35 +01:00
|
|
|
for PLUG in $PLUGINS; do
|
|
|
|
case "$PLUG" in
|
|
|
|
if_|if_err_)
|
|
|
|
interface_names=$(grep -E '^ *(ppp|eth|wlan|ath|ra|ipsec|tap|br-)[^:]{1,}:' /proc/net/dev | sed 's/^ *//; s/:.*$//')
|
|
|
|
for INTER in $interface_names; do
|
|
|
|
INTERRES=$(echo "$INTER" | sed -e 's/\./VLAN/' -e 's/\-/_/')
|
|
|
|
RES="$RES ${PLUG}${INTERRES}"
|
|
|
|
eval "fetch_${PLUG}${INTERRES}() { 'fetch_${PLUG%_}' '$INTER'; }"
|
|
|
|
eval "config_${PLUG}${INTERRES}() { 'config_${PLUG%_}' '$INTER'; }"
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
netstat)
|
|
|
|
if netstat -s >/dev/null 2>&1; then
|
|
|
|
RES="$RES netstat"
|
2011-01-14 21:24:16 +01:00
|
|
|
fi
|
2020-02-08 04:58:35 +01:00
|
|
|
;;
|
|
|
|
plugindir_)
|
|
|
|
for MYPLUGIN in $(if [ -d "$PLUGIN_DIRECTORY" ]; then find -L "$PLUGIN_DIRECTORY" -type f -name "$PLUGINPATTERN"; fi); do
|
|
|
|
if [ -f "$MYPLUGIN" ] && [ -x "$MYPLUGIN" ]; then
|
|
|
|
MYPLUGINNAME=$(basename "$MYPLUGIN")
|
|
|
|
# detect and avoid name collision
|
|
|
|
if echo "$RES" | grep -qwF "$MYPLUGINNAME"; then
|
|
|
|
MYPLUGINNAME="plugindir_$MYPLUGINNAME"
|
|
|
|
fi
|
|
|
|
RES="$RES $MYPLUGINNAME"
|
|
|
|
eval "fetch_${MYPLUGINNAME}() { '$MYPLUGIN'; }"
|
|
|
|
eval "config_${MYPLUGINNAME}() { '$MYPLUGIN' config; }"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
RES="$RES $PLUG"
|
|
|
|
;;
|
|
|
|
esac
|
2007-06-11 17:45:16 +02:00
|
|
|
done
|
2020-02-07 14:34:38 +01:00
|
|
|
# sort plugin names and remove surrounding whitespace
|
|
|
|
PLUGINS=$(echo "$RES" | xargs -r -n 1 echo | sort | xargs echo)
|
2007-06-11 17:45:16 +02:00
|
|
|
|
|
|
|
# ===== MAIN LOOP =====
|
|
|
|
FUNCTIONS="list nodes config fetch version quit"
|
2020-02-08 21:31:15 +01:00
|
|
|
HOSTNAME=$( { hostname -f || hostname || cat /proc/sys/kernel/hostname || echo "unknown"; } 2>/dev/null )
|
2007-06-11 17:45:16 +02:00
|
|
|
echo "# munin node at $HOSTNAME"
|
2020-02-08 04:58:06 +01:00
|
|
|
while read -r arg0 arg1
|
2019-07-23 04:52:37 +02:00
|
|
|
do
|
2007-06-11 17:45:16 +02:00
|
|
|
arg0=$(echo "$arg0" | xargs)
|
2019-07-23 04:52:37 +02:00
|
|
|
arg1=$(echo "$arg1" | xargs)
|
2020-02-07 14:51:47 +01:00
|
|
|
if ! echo "$FUNCTIONS" | grep -qwF "$arg0"; then
|
2020-02-07 15:15:06 +01:00
|
|
|
echo "# Unknown command. Try $(echo "$FUNCTIONS" | sed -e 's/\( [[:alpha:]]\{1,\}\)/,\1/g' -e 's/,\( [[:alpha:]]\{1,\}\)$/ or\1/')"
|
|
|
|
else
|
|
|
|
"do_$arg0" "$arg1"
|
2007-06-11 17:45:16 +02:00
|
|
|
fi
|
2019-07-23 04:52:37 +02:00
|
|
|
done
|