|
| 1 | +#!/bin/sh |
| 2 | +# -*- sh -*- |
| 3 | +: <<=cut |
| 4 | +
|
| 5 | +=head1 NAME |
| 6 | +
|
| 7 | +munin_status - Plugin to monitor munin updates |
| 8 | +
|
| 9 | +=head1 APPLICABLE SYSTEMS |
| 10 | +
|
| 11 | +All systems with "sh", "pygtail", "awk" and "munin" |
| 12 | +
|
| 13 | +=head1 CONFIGURATION |
| 14 | +
|
| 15 | +The following is the default configuration |
| 16 | +
|
| 17 | + [munin_status] |
| 18 | + user munin |
| 19 | + env.muninupdate /var/log/munin/munin-update.log |
| 20 | + env.pygtail /opt/local/bin/pygtail |
| 21 | +
|
| 22 | +You could trigger alerts on update failures |
| 23 | +
|
| 24 | + [munin_status] |
| 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 | + 0.1 |
| 43 | +
|
| 44 | +=head1 AUTHOR |
| 45 | +
|
| 46 | + |
| 47 | +
|
| 48 | +=head1 LICENSE |
| 49 | +
|
| 50 | +GPLv2 |
| 51 | +
|
| 52 | +=cut |
| 53 | + |
| 54 | + |
| 55 | +############################## |
| 56 | +# Includes |
| 57 | + |
| 58 | +# shellcheck disable=SC1091 |
| 59 | +. "$MUNIN_LIBDIR/plugins/plugin.sh" |
| 60 | + |
| 61 | +############################## |
| 62 | +# Configurable variables |
| 63 | +muninupdate=${muninupdate:-/var/log/munin/munin-update.log} |
| 64 | +pygtail_bin=${pygtail_bin:-/opt/local/bin/pygtail} |
| 65 | + |
| 66 | +############################## |
| 67 | +# Functions |
| 68 | + |
| 69 | +# Print the munin values |
| 70 | +values() { |
| 71 | + # Set offset |
| 72 | + "$pygtail_bin" "$muninupdate" | awk ' |
| 73 | + BEGIN { split("INFO WARNING ERROR FATAL", a); for (i = 1; a[i]; ++i) A[i] = 0 } |
| 74 | + { for (i = 1; a[i]; ++i) if (match($0, a[i])) ++A[i] } |
| 75 | + END { for (i = 1; a[i]; ++i) print "munin_"tolower(a[i])".value " A[i]} |
| 76 | + ' |
| 77 | + chmod 640 "${muninupdate}.offset" |
| 78 | +} |
| 79 | + |
| 80 | +# Print the munin config |
| 81 | +config() { |
| 82 | + echo 'graph_title Munin update status groupped by log levels' |
| 83 | + echo 'graph_info This graph shows INFO, WARNING, ERROR and FATAL status' |
| 84 | + echo 'graph_category munin' |
| 85 | + echo 'graph_vlabel Number of status' |
| 86 | + |
| 87 | + echo 'graph_args --base 1000 -l 0' |
| 88 | + echo 'graph_total total' |
| 89 | + echo 'graph_printf %6.0lf' |
| 90 | + |
| 91 | + echo 'munin_info.label INFO' |
| 92 | + print_warning munin_info |
| 93 | + print_critical munin_info |
| 94 | + echo 'munin_warning.label WARNING' |
| 95 | + print_warning munin_warning |
| 96 | + print_critical munin_warning |
| 97 | + echo 'munin_error.label ERROR' |
| 98 | + print_warning munin_error |
| 99 | + print_critical munin_error |
| 100 | + echo 'munin_fatal.label FATAL' |
| 101 | + print_warning munin_fatal |
| 102 | + print_critical munin_fatal |
| 103 | +} |
| 104 | + |
| 105 | +# Print autoconfiguration hint |
| 106 | +autoconf() { |
| 107 | + if [ -r "${muninupdate}" ] && [ -x "$pygtail_bin" ]; then |
| 108 | + echo "yes" |
| 109 | + else |
| 110 | + echo "missing (${muninupdate} or (${pygtail_bin})" |
| 111 | + fi |
| 112 | + exit |
| 113 | +} |
| 114 | + |
| 115 | +############################## |
| 116 | +# Main |
| 117 | + |
| 118 | +case "$1" in |
| 119 | + config) |
| 120 | + config |
| 121 | + ;; |
| 122 | + autoconf) |
| 123 | + autoconf |
| 124 | + ;; |
| 125 | + *) |
| 126 | + values |
| 127 | + ;; |
| 128 | +esac |
0 commit comments