~ubuntu-branches/ubuntu/maverick/munin/maverick

« back to all changes in this revision

Viewing changes to plugins/plugin.sh.in

  • Committer: Bazaar Package Importer
  • Author(s): Holger Levsen, Stig Sandbeck Mathisen, Tom Feiner
  • Date: 2010-01-14 12:10:51 UTC
  • mfrom: (8.1.13 sid)
  • Revision ID: james.westby@ubuntu.com-20100114121051-6xovy6hqfh1wrl0u
Tags: 1.4.3-2
[ Stig Sandbeck Mathisen ]
* Add versioned dependency for librrds-perl.
  If used with librrds-perl 1.2 or older, the font path is wrong.

[ Tom Feiner ]
* Update watch file.
* Add patch from munin ticket #828, to suppress "occasional" unknown 
  states to avoid alerts. Thanks to Steve Wilson for the patch!
* Removed asterisks from NEWS.Debian and rewrite as non bulleted list, as
  advised by the developers reference.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- sh -*-
 
2
# Support functions for shell munin plugins
 
3
#
 
4
 
 
5
clean_fieldname () {
 
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.
 
10
    #
 
11
    # usage: name="$(clean_fieldname "$item")"
 
12
    # 
 
13
    echo "$@" | sed -e 's/^[^A-Za-z_]/_/' -e 's/[^A-Za-z0-9_]/_/g'
 
14
}
 
15
 
 
16
 
 
17
# Look up warning environment variables in the following order:
 
18
# $1 = field name
 
19
# $2 = optional override of environment variable name
 
20
#
 
21
# Hmm, this first looks for field_warning, then $2 then warning.  Not the
 
22
# order one expects.
 
23
 
 
24
get_warning () {
 
25
    warn_env="${1}_warning"
 
26
    defwarn_env=${2:-warning}
 
27
    warntmp=$(eval "echo \$${warn_env}")
 
28
    warntmpd=$(eval "echo \$${defwarn_env}")
 
29
 
 
30
    warnout=${warntmp:-$warntmpd}
 
31
 
 
32
    if [ -n "${warnout}" ]; then
 
33
        echo "${warnout}"
 
34
    fi
 
35
}
 
36
 
 
37
 
 
38
# Usage: 
 
39
#   warning=${warning:-92}
 
40
#   print_warning "$name"
 
41
 
 
42
print_warning () {
 
43
        warnout=$(get_warning $1 $2)
 
44
        if [ -n "${warnout}" ]; then
 
45
                echo "${1}.warning ${warnout}"
 
46
        fi
 
47
}
 
48
 
 
49
# Ditto for critical values
 
50
 
 
51
get_critical () {
 
52
        crit_env="${1}_critical"
 
53
        defcrit_env=${2:-critical}
 
54
        crittmp=$(eval "echo \$${crit_env}")
 
55
        crittmpd=$(eval "echo \$${defcrit_env}")
 
56
 
 
57
        critout=${crittmp:-$crittmpd}
 
58
 
 
59
        if [ -n "${critout}" ]; then
 
60
                echo "${critout}"
 
61
        fi
 
62
}
 
63
 
 
64
print_critical () {
 
65
        critout=$(get_critical $1 $2)
 
66
        if [ -n "${critout}" ]; then
 
67
                echo "${1}.critical ${critout}"
 
68
        fi
 
69
}
 
70
 
 
71
 
 
72
is_multigraph () {
 
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.
 
76
    #
 
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.
 
80
    #
 
81
    case $MUNIN_CAP_MULTIGRAPH:$1 in
 
82
        1:*) return;; # Yes! Rock and roll!
 
83
        *:autoconf)
 
84
            echo 'no (no multigraph support)'
 
85
            exit 0
 
86
            ;;
 
87
 
 
88
        *:config)
 
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.'
 
92
            exit 0
 
93
            ;;
 
94
 
 
95
        *: ) echo 'multigraph.value 0'
 
96
            exit 0
 
97
            ;;
 
98
    esac
 
99
}
 
100
 
 
101
 
 
102
is_dirtyconfig () {
 
103
    # Detect if node/server supports dirty config (feature not yet supported)
 
104
    case $MUNIN_CAP_DIRTYCONFIG in
 
105
        1) exit 1;;
 
106
        *) exit 0;;
 
107
    esac
 
108
}
 
109
 
 
110
 
 
111
 
 
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
 
117
# james: dup2, even
 
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
 
121