1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
# -*- sh -*-
# Support functions for shell munin plugins
#
clean_fieldname () {
# Clean up field name so it complies with munin requirements.
# Even though most versions of munin sanitises field names
# this at least avoids getting .s in field names which will
# very much still break munin.
#
# usage: name="$(clean_fieldname "$item")"
#
echo "$@" | sed -e 's/^[^A-Za-z_]/_/' -e 's/[^A-Za-z0-9_]/_/g'
}
# Look up warning environment variables in the following order:
# $1 = field name
# $2 = optional override of environment variable name
#
# Hmm, this first looks for field_warning, then $2 then warning. Not the
# order one expects.
get_warning () {
warn_env="${1}_warning"
defwarn_env=${2:-warning}
warntmp=$(eval "echo \$${warn_env}")
warntmpd=$(eval "echo \$${defwarn_env}")
warnout=${warntmp:-$warntmpd}
if [ -n "${warnout}" ]; then
echo "${warnout}"
fi
}
# Usage:
# warning=${warning:-92}
# print_warning "$name"
print_warning () {
warnout=$(get_warning $1 $2)
if [ -n "${warnout}" ]; then
echo "${1}.warning ${warnout}"
fi
}
# Ditto for critical values
get_critical () {
crit_env="${1}_critical"
defcrit_env=${2:-critical}
crittmp=$(eval "echo \$${crit_env}")
crittmpd=$(eval "echo \$${defcrit_env}")
critout=${crittmp:-$crittmpd}
if [ -n "${critout}" ]; then
echo "${critout}"
fi
}
print_critical () {
critout=$(get_critical $1 $2)
if [ -n "${critout}" ]; then
echo "${1}.critical ${critout}"
fi
}
is_multigraph () {
# Multigraph feature is available in Munin 1.4.0 and later.
# But it also needs support on the node to stay perfectly
# compatible with old munin-masters.
#
# Using this procedure at the start of a multigraph plugin makes
# sure it does not interact with old node installations at all
# and thus does not break anything.
#
case $MUNIN_CAP_MULTIGRAPH:$1 in
1:*) return;; # Yes! Rock and roll!
*:autoconf)
echo 'no (no multigraph support)'
exit 0
;;
*:config)
echo 'graph_title This plugin needs multigraph support'
echo 'multigraph.label No multigraph here'
echo 'multigraph.info This plugin has been installed in a munin-node that is too old to know about multigraph plugins. Even if your munin master understands multigraph plugins this is not enough, the node too needs to be new enough. Version 1.4.0 or later should work.'
exit 0
;;
*: ) echo 'multigraph.value 0'
exit 0
;;
esac
}
is_dirtyconfig () {
# Detect if node/server supports dirty config (feature not yet supported)
case $MUNIN_CAP_DIRTYCONFIG in
1) exit 1;;
*) exit 0;;
esac
}
# janl_: can I in a shell script save STDOUT so I can restore it after
# a "exec >>somefile"?
# james: exec 2>&4 etc.
# janl_: this saves handle 2 in handle 4?
# james: yes, that's basically the same as dup
# james: dup2, even
# janl_: so... ... "exec 4>&2" to restore?
# james: Actually you can do: exec 4>&2- ... which closes 4 afterwards ...
# I think that's historical behaviour and not a newish extension
|