root / plugins / mail / postfix_stats @ daf5b94a
Historique | Voir | Annoter | Télécharger (2,72 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# -*- sh -*- |
| 3 |
|
| 4 |
: <<=cut |
| 5 |
|
| 6 |
=head1 NAME |
| 7 |
|
| 8 |
postfix_stats - Munin plugin to monitor postfix statistics. |
| 9 |
|
| 10 |
=head1 APPLICABLE SYSTEMS |
| 11 |
|
| 12 |
Any system where pflogsumm script can be executed. |
| 13 |
|
| 14 |
=head1 CONFIGURATION |
| 15 |
|
| 16 |
There is no default configuration. This is an example config for Ubuntu: |
| 17 |
|
| 18 |
[postfix_stats] |
| 19 |
env.logfiles /var/log/syslog /var/log/syslog.1 |
| 20 |
env.pflogsumm pflogsumm |
| 21 |
|
| 22 |
env.logfiles contains space separated syslog logfiles, usually current log |
| 23 |
and previous log. You can add more log files if you want, but this can |
| 24 |
increase the time required to parse it. |
| 25 |
|
| 26 |
env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if are manually |
| 27 |
downloaded and installed or pflogsumm if are installed by apt-get. |
| 28 |
|
| 29 |
=head1 INTERPRETATION |
| 30 |
|
| 31 |
This plugin adds up the RSS of all processes matching the |
| 32 |
regex given as the process name, as reported by ps. |
| 33 |
|
| 34 |
=head1 MAGIC MARKERS |
| 35 |
|
| 36 |
#%# family=auto |
| 37 |
#%# capabilities=autoconf |
| 38 |
|
| 39 |
=head1 VERSION |
| 40 |
0.2 plugin completely rewritten |
| 41 |
0.1 first release. |
| 42 |
|
| 43 |
=head1 BUGS |
| 44 |
|
| 45 |
None known |
| 46 |
|
| 47 |
=head1 AUTHOR |
| 48 |
|
| 49 |
Originally: David Obando (david@cryptix.de) |
| 50 |
Modified by: github.com/cristiandeluxe |
| 51 |
Thanks to: sumpfralle |
| 52 |
|
| 53 |
=head1 LICENSE |
| 54 |
|
| 55 |
GPLv2 |
| 56 |
|
| 57 |
=cut |
| 58 |
|
| 59 |
#set -xv |
| 60 |
SYS_LOG="${logfiles:-/var/log/syslog /var/log/syslog.0}"
|
| 61 |
|
| 62 |
# shellcheck disable=SC2154 |
| 63 |
PFLOGSUMM="${pflogsum}"
|
| 64 |
[ -z "$PFLOGSUMM" ] && PFLOGSUMM="$(which pflogsumm pflogsumm.pl | head -1)" |
| 65 |
|
| 66 |
# Fields (Array to avoid code duplication) must be space separated |
| 67 |
FIELDS_ARR="received delivered forwarded deferred bounced rejected held discarded" |
| 68 |
|
| 69 |
# |
| 70 |
# Autoconf Section |
| 71 |
# |
| 72 |
if [ "$1" = 'autoconf' ]; then |
| 73 |
# Check if pflogsumm exist |
| 74 |
if [ -z "${PFLOGSUMM}" ]
|
| 75 |
then |
| 76 |
echo 'no (pflogsum not found in your system)' |
| 77 |
else |
| 78 |
echo 'yes' |
| 79 |
fi |
| 80 |
exit 0 |
| 81 |
fi |
| 82 |
|
| 83 |
# |
| 84 |
# Config Section |
| 85 |
# |
| 86 |
if [ "$1" = 'config' ]; then |
| 87 |
echo 'graph_title Postfix statistics' |
| 88 |
echo 'graph_vlabel Postfix statistics' |
| 89 |
echo 'graph_category mail' |
| 90 |
echo 'graph_scale no' |
| 91 |
echo 'graph_period minute' |
| 92 |
echo 'graph_total Total' |
| 93 |
|
| 94 |
# Generate config for each field |
| 95 |
for i in $FIELDS_ARR; do |
| 96 |
echo "${i}.label ${i}"
|
| 97 |
echo "${i}.type DERIVE"
|
| 98 |
echo "${i}.min 0"
|
| 99 |
echo "${i}.draw AREASTACK"
|
| 100 |
done |
| 101 |
|
| 102 |
exit 0 |
| 103 |
fi |
| 104 |
|
| 105 |
# |
| 106 |
# Plugin Script |
| 107 |
# |
| 108 |
|
| 109 |
# Variable to store the pflogsumm result. |
| 110 |
# shellcheck disable=SC2086 |
| 111 |
TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${SYS_LOG})
|
| 112 |
|
| 113 |
# Parse value from Raw result |
| 114 |
# |
| 115 |
# Return digit if regex are parsed correctly |
| 116 |
# |
| 117 |
# Return U (undefined) if any error occurs |
| 118 |
# |
| 119 |
parseValue() {
|
| 120 |
# shellcheck disable=SC2155 |
| 121 |
local TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei "^[[:space:]]+[[:digit:]]+[[:space:]]+${1}.*$" | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g')
|
| 122 |
if [ -z "${TMP_RETURN}" ]; then
|
| 123 |
echo 'U' |
| 124 |
else |
| 125 |
echo "${TMP_RETURN}"
|
| 126 |
fi |
| 127 |
} |
| 128 |
|
| 129 |
# Print results |
| 130 |
for i in $FIELDS_ARR; do |
| 131 |
printf "%s.value " "${i}"
|
| 132 |
parseValue "${i}"
|
| 133 |
done |
