Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / munin / munin_events @ d7f54f3e

Historique | Voir | Annoter | Télécharger (2,84 ko)

1 56cd2c92 Viktor Szépe
#!/bin/sh
2 82edf596 Viktor Szépe
# -*- sh -*-
3
: <<=cut
4
5
=head1 NAME
6
7
munin_events - Plugin to monitor munin updates
8
9
=head1 APPLICABLE SYSTEMS
10
11
All systems with "bash", "logtail" and "munin"
12
13
=head1 CONFIGURATION
14
15
The following is the default configuration
16
17
  [munin_events]
18
  user munin
19
  env.muninupdate /var/log/munin/munin-update.log
20
  env.logtail2 /usr/sbin/logtail2
21
22
You could trigger alerts on update failures
23
24
  [munin_events]
25
  env.munin_fatal_critical 0
26
  env.munin_error_critical 0
27
  env.munin_warning_warning 0
28
  env.munin_warning_critical 5
29
30
=head1 INTERPRETATION
31
32
This plugin shows a graph with one line per munin state:
33
INFO, WARNING, ERROR, FATAL.
34
35
=head1 MAGIC MARKERS
36
37
  #%# family=auto
38
  #%# capabilities=autoconf
39
40
=head1 VERSION
41
42 e7bcfec0 Viktor Szépe
  1.2.20160514
43 82edf596 Viktor Szépe
44
=head1 AUTHOR
45
46
Viktor Szépe <viktor@szepe.net>
47
48
=head1 LICENSE
49
50
GPLv2
51
52
=cut
53
54
55
##############################
56
# Includes
57
58 56cd2c92 Viktor Szépe
# shellcheck disable=SC1090
59
. "$MUNIN_LIBDIR/plugins/plugin.sh"
60 82edf596 Viktor Szépe
61
##############################
62
# Configurable variables
63
muninupdate=${muninupdate:-/var/log/munin/munin-update.log}
64
logtail_bin=${logtail_bin:-/usr/sbin/logtail2}
65
66
##############################
67
# Functions
68
69
# Print one value
70
do_value() {
71 56cd2c92 Viktor Szépe
    FIELD="$1"
72
    EVENT_LABEL="$2"
73
74 7fed3b97 Lars Kruse
    EVENT_COUNT="$("$logtail_bin" -t "$muninupdate" 2> /dev/null | grep -c '^[0-9/: ]\{19\} \['"${EVENT_LABEL}"'\]')"
75 e7bcfec0 Viktor Szépe
    if echo "$EVENT_COUNT" | grep -q "[^0-9]"; then
76 82edf596 Viktor Szépe
        echo "Cannot determine event count" 1>&2
77
        exit 10
78
    fi
79
80
    echo "${FIELD}.value ${EVENT_COUNT}"
81
}
82
83
# Print the munin values
84
values() {
85
    do_value 'munin_info' 'INFO'
86
    do_value 'munin_warning' 'WARNING'
87
    do_value 'munin_error' 'ERROR'
88
    do_value 'munin_fatal' 'FATAL'
89
    # Set offset
90 56cd2c92 Viktor Szépe
    "$logtail_bin" "$muninupdate" > /dev/null 1>&2
91 82edf596 Viktor Szépe
    chmod 640 "${muninupdate}.offset"
92
}
93
94
# Print the munin config
95
config() {
96
    echo 'graph_title Munin update events groupped by log levels'
97
    echo 'graph_info This graph shows INFO, WARNING, ERROR and FATAL events'
98
    echo 'graph_category munin'
99
    echo 'graph_vlabel Number of events'
100
101
    echo 'graph_args --base 1000 -l 0'
102
    echo 'graph_total total'
103
    echo 'graph_printf %6.0lf'
104
105
    echo 'munin_info.label INFO'
106
    print_warning munin_info
107
    print_critical munin_info
108
    echo 'munin_warning.label WARNING'
109
    print_warning munin_warning
110
    print_critical munin_warning
111
    echo 'munin_error.label ERROR'
112
    print_warning munin_error
113
    print_critical munin_error
114
    echo 'munin_fatal.label FATAL'
115
    print_warning munin_fatal
116
    print_critical munin_fatal
117
}
118
119
# Print autoconfiguration hint
120
autoconf() {
121
    if [ -r "${muninupdate}" ] && [ -x "$logtail_bin" ]; then
122
        echo "yes"
123
    else
124
        echo "missing (${muninupdate} or (${logtail_bin})"
125
    fi
126
    exit
127
}
128
129
##############################
130
# Main
131
132
case "$1" in
133
    config)
134
        config
135
        ;;
136
    autoconf)
137
        autoconf
138
        ;;
139
    *)
140
        values
141
        ;;
142
esac