2
# Support functions for shell munin plugins
6
# Clean up field name so it complies with munin requirements.
7
# Even though most versions of munin sanitises field names
8
# this at least avoids getting .s in field names which will
9
# very much still break munin.
11
# usage: name="$(clean_fieldname "$item")"
13
echo "$@" | sed -e 's/^[^A-Za-z_]/_/' -e 's/[^A-Za-z0-9_]/_/g'
17
# Look up warning environment variables in the following order:
19
# $2 = optional override of environment variable name
21
# Hmm, this first looks for field_warning, then $2 then warning. Not the
25
warn_env="${1}_warning"
26
defwarn_env=${2:-warning}
27
warntmp=$(eval "echo \$${warn_env}")
28
warntmpd=$(eval "echo \$${defwarn_env}")
30
warnout=${warntmp:-$warntmpd}
32
if [ -n "${warnout}" ]; then
39
# warning=${warning:-92}
40
# print_warning "$name"
43
warnout=$(get_warning $1 $2)
44
if [ -n "${warnout}" ]; then
45
echo "${1}.warning ${warnout}"
49
# Ditto for critical values
52
crit_env="${1}_critical"
53
defcrit_env=${2:-critical}
54
crittmp=$(eval "echo \$${crit_env}")
55
crittmpd=$(eval "echo \$${defcrit_env}")
57
critout=${crittmp:-$crittmpd}
59
if [ -n "${critout}" ]; then
65
critout=$(get_critical $1 $2)
66
if [ -n "${critout}" ]; then
67
echo "${1}.critical ${critout}"
73
# Multigraph feature is available in Munin 1.4.0 and later.
74
# But it also needs support on the node to stay perfectly
75
# compatible with old munin-masters.
77
# Using this procedure at the start of a multigraph plugin makes
78
# sure it does not interact with old node installations at all
79
# and thus does not break anything.
81
case $MUNIN_CAP_MULTIGRAPH:$1 in
82
1:*) return;; # Yes! Rock and roll!
84
echo 'no (no multigraph support)'
89
echo 'graph_title This plugin needs multigraph support'
90
echo 'multigraph.label No multigraph here'
91
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.'
95
*: ) echo 'multigraph.value 0'
103
# Detect if node/server supports dirty config (feature not yet supported)
104
case $MUNIN_CAP_DIRTYCONFIG in
112
# janl_: can I in a shell script save STDOUT so I can restore it after
113
# a "exec >>somefile"?
114
# james: exec 2>&4 etc.
115
# janl_: this saves handle 2 in handle 4?
116
# james: yes, that's basically the same as dup
118
# janl_: so... ... "exec 4>&2" to restore?
119
# james: Actually you can do: exec 4>&2- ... which closes 4 afterwards ...
120
# I think that's historical behaviour and not a newish extension