root / plugins / postfix / postfix_stats @ 17f78427
Historique | Voir | Annoter | Télécharger (3,56 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 |
group adm |
| 20 |
env.logfiles /var/log/mail.log /var/log/mail.log.1 |
| 21 |
env.pflogsumm pflogsumm |
| 22 |
|
| 23 |
env.logfiles contains space separated syslog logfiles, usually current log |
| 24 |
and previous log. You can add more log files if you want, but this may |
| 25 |
increase the time required for analysis. |
| 26 |
|
| 27 |
env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if it was manually |
| 28 |
downloaded and installed, or "pflogsumm" if it was installed by a package |
| 29 |
manager (like apt-get). |
| 30 |
|
| 31 |
Use the last part of the symlink name for filtering by hostname from logfile, |
| 32 |
which contains logs from multiple hosts (e.g. received via rsyslog from remote |
| 33 |
hosts). |
| 34 |
|
| 35 |
For example: |
| 36 |
|
| 37 |
cd /etc/munin/plugins |
| 38 |
ln -s /path/to/postfix_stats postfix_stats_HOSTNAME |
| 39 |
|
| 40 |
=head1 INTERPRETATION |
| 41 |
|
| 42 |
This plugin displays the messages: received, delivered, rejected... |
| 43 |
Average per minute is made and it shows the total message count. |
| 44 |
It is useful to know the load and messages being processed. |
| 45 |
|
| 46 |
=head1 MAGIC MARKERS |
| 47 |
|
| 48 |
#%# family=auto |
| 49 |
#%# capabilities=autoconf |
| 50 |
|
| 51 |
=head1 VERSION |
| 52 |
0.3 support for hostname grep (useful when multiple hosts in one log) |
| 53 |
0.2 plugin completely rewritten |
| 54 |
0.1 first release. |
| 55 |
|
| 56 |
=head1 BUGS |
| 57 |
|
| 58 |
None known |
| 59 |
|
| 60 |
=head1 AUTHOR |
| 61 |
|
| 62 |
Originally: David Obando (david@cryptix.de) |
| 63 |
Modified by: github.com/cristiandeluxe |
| 64 |
Modified by: github.com/4nd3r |
| 65 |
Thanks to: sumpfralle |
| 66 |
|
| 67 |
=head1 LICENSE |
| 68 |
|
| 69 |
GPLv2 |
| 70 |
|
| 71 |
=cut |
| 72 |
|
| 73 |
#set -xv |
| 74 |
MAIL_LOG="${logfiles:-/var/log/mail.log /var/log/mail.log.1}"
|
| 75 |
|
| 76 |
FILTER_HOSTNAME=$(basename "$0" | sed -r 's/postfix_stats_?//') |
| 77 |
|
| 78 |
# shellcheck disable=SC2154 |
| 79 |
PFLOGSUMM="${pflogsum}"
|
| 80 |
[ -z "$PFLOGSUMM" ] && PFLOGSUMM="$(which pflogsumm pflogsumm.pl | head -1)" |
| 81 |
|
| 82 |
# Fields (Array to avoid code duplication) must be space separated |
| 83 |
FIELDS_ARR="received delivered forwarded deferred bounced rejected held discarded" |
| 84 |
|
| 85 |
# |
| 86 |
# Autoconf Section |
| 87 |
# |
| 88 |
if [ "$1" = 'autoconf' ]; then |
| 89 |
# Check if pflogsumm exist |
| 90 |
if [ -z "${PFLOGSUMM}" ]
|
| 91 |
then |
| 92 |
echo 'no (pflogsum not found in your system)' |
| 93 |
else |
| 94 |
echo 'yes' |
| 95 |
fi |
| 96 |
exit 0 |
| 97 |
fi |
| 98 |
|
| 99 |
# |
| 100 |
# Config Section |
| 101 |
# |
| 102 |
if [ "$1" = 'config' ]; then |
| 103 |
if [ -n "${FILTER_HOSTNAME}" ]; then
|
| 104 |
echo "graph_title Postfix statistics for ${FILTER_HOSTNAME}"
|
| 105 |
else |
| 106 |
echo 'graph_title Postfix statistics' |
| 107 |
fi |
| 108 |
echo 'graph_vlabel Postfix statistics' |
| 109 |
echo 'graph_category mail' |
| 110 |
echo 'graph_scale no' |
| 111 |
echo 'graph_period minute' |
| 112 |
echo 'graph_total Total' |
| 113 |
|
| 114 |
# Generate config for each field |
| 115 |
for i in $FIELDS_ARR; do |
| 116 |
echo "${i}.label ${i}"
|
| 117 |
echo "${i}.type DERIVE"
|
| 118 |
echo "${i}.min 0"
|
| 119 |
echo "${i}.draw AREASTACK"
|
| 120 |
done |
| 121 |
|
| 122 |
exit 0 |
| 123 |
fi |
| 124 |
|
| 125 |
# |
| 126 |
# Plugin Script |
| 127 |
# |
| 128 |
|
| 129 |
# Variable to store the pflogsumm result. |
| 130 |
if [ -n "${FILTER_HOSTNAME}" ]; then
|
| 131 |
# shellcheck disable=SC2086 |
| 132 |
TMP_RAW=$(grep -Fh " ${FILTER_HOSTNAME} postfix/" ${MAIL_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill)
|
| 133 |
else |
| 134 |
# shellcheck disable=SC2086 |
| 135 |
TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${MAIL_LOG})
|
| 136 |
fi |
| 137 |
|
| 138 |
# Parse value from Raw result |
| 139 |
# |
| 140 |
# Return digit if regex are parsed correctly |
| 141 |
# |
| 142 |
# Return U (undefined) if any error occurs |
| 143 |
# |
| 144 |
parseValue() {
|
| 145 |
# shellcheck disable=SC2155 |
| 146 |
local TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei "^[[:space:]]+[[:digit:]]+[[:space:]]+${1}.*$" | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g')
|
| 147 |
if [ -z "${TMP_RETURN}" ]; then
|
| 148 |
echo 'U' |
| 149 |
else |
| 150 |
echo "${TMP_RETURN}"
|
| 151 |
fi |
| 152 |
} |
| 153 |
|
| 154 |
# Print results |
| 155 |
for i in $FIELDS_ARR; do |
| 156 |
printf "%s.value " "${i}"
|
| 157 |
parseValue "${i}"
|
| 158 |
done |
