2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/postfix/postfix_stats

159 lines
3.6 KiB
Plaintext
Raw Normal View History

#!/bin/sh
2016-11-04 05:11:19 +01:00
# -*- sh -*-
: <<=cut
=head1 NAME
postfix_stats - Munin plugin to monitor postfix statistics.
=head1 APPLICABLE SYSTEMS
Any system where pflogsumm script can be executed.
=head1 CONFIGURATION
2016-11-04 10:48:06 +01:00
There is no default configuration. This is an example config for Ubuntu:
2016-11-04 05:11:19 +01:00
[postfix_stats*]
group adm
env.logfiles /var/log/mail.log /var/log/mail.log.1
2016-11-04 05:11:19 +01:00
env.pflogsumm pflogsumm
env.logfiles contains space separated syslog logfiles, usually current log
2016-11-04 10:48:06 +01:00
and previous log. You can add more log files if you want, but this may
increase the time required for analysis.
2016-11-04 05:11:19 +01:00
2016-11-04 10:48:06 +01:00
env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if it was manually
downloaded and installed, or "pflogsumm" if it was installed by a package
manager (like apt-get).
2016-11-04 05:11:19 +01:00
2017-04-15 17:12:48 +02:00
Use the last part of the symlink name for filtering by hostname from logfile,
which contains logs from multiple hosts (e.g. received via rsyslog from remote
hosts).
2017-04-13 12:36:17 +02:00
2017-04-14 16:44:15 +02:00
For example:
cd /etc/munin/plugins
ln -s /path/to/postfix_stats postfix_stats_HOSTNAME
2016-11-04 05:11:19 +01:00
=head1 INTERPRETATION
2016-11-04 10:48:06 +01:00
This plugin displays the messages: received, delivered, rejected...
Average per minute is made and it shows the total message count.
It is useful to know the load and messages being processed.
2016-11-04 05:11:19 +01:00
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
2017-04-13 12:36:17 +02:00
0.3 support for hostname grep (useful when multiple hosts in one log)
2016-11-04 05:11:19 +01:00
0.2 plugin completely rewritten
0.1 first release.
=head1 BUGS
None known
=head1 AUTHOR
Originally: David Obando (david@cryptix.de)
Modified by: github.com/cristiandeluxe
2017-04-13 12:36:17 +02:00
Modified by: github.com/4nd3r
2016-11-04 05:11:19 +01:00
Thanks to: sumpfralle
=head1 LICENSE
GPLv2
=cut
#set -xv
2017-04-13 11:51:43 +02:00
MAIL_LOG="${logfiles:-/var/log/mail.log /var/log/mail.log.1}"
2017-04-14 16:31:49 +02:00
FILTER_HOSTNAME=$(basename "$0" | sed -r 's/postfix_stats_?//')
2017-04-13 11:40:17 +02:00
# shellcheck disable=SC2154
2016-11-04 05:11:19 +01:00
PFLOGSUMM="${pflogsum}"
[ -z "$PFLOGSUMM" ] && PFLOGSUMM="$(which pflogsumm pflogsumm.pl | head -1)"
2016-11-02 02:24:55 +01:00
2016-11-04 05:11:19 +01:00
# Fields (Array to avoid code duplication) must be space separated
FIELDS_ARR="received delivered forwarded deferred bounced rejected held discarded"
2016-11-02 02:24:55 +01:00
#
# Autoconf Section
#
if [ "$1" = 'autoconf' ]; then
2016-11-04 05:11:19 +01:00
# Check if pflogsumm exist
if [ -z "${PFLOGSUMM}" ]
2016-11-02 02:24:55 +01:00
then
2016-11-04 05:11:19 +01:00
echo 'no (pflogsum not found in your system)'
2016-11-02 02:24:55 +01:00
else
echo 'yes'
2016-11-02 02:24:55 +01:00
fi
2016-11-04 05:11:19 +01:00
exit 0
2016-11-02 02:24:55 +01:00
fi
#
# Config Section
#
if [ "$1" = 'config' ]; then
2017-04-14 16:31:49 +02:00
if [ -n "${FILTER_HOSTNAME}" ]; then
echo "graph_title Postfix statistics for ${FILTER_HOSTNAME}"
2017-04-13 11:40:17 +02:00
else
echo 'graph_title Postfix statistics'
fi
echo 'graph_vlabel Postfix statistics'
echo 'graph_category mail'
echo 'graph_scale no'
echo 'graph_period minute'
echo 'graph_total Total'
# Generate config for each field
2016-11-04 05:11:19 +01:00
for i in $FIELDS_ARR; do
echo "${i}.label ${i}"
echo "${i}.type DERIVE"
echo "${i}.min 0"
2016-11-02 07:06:36 +01:00
echo "${i}.draw AREASTACK"
done
exit 0
2016-11-02 02:24:55 +01:00
fi
#
# Plugin Script
#
# Variable to store the pflogsumm result.
2017-04-14 16:31:49 +02:00
if [ -n "${FILTER_HOSTNAME}" ]; then
2017-04-14 16:36:37 +02:00
# shellcheck disable=SC2086
2017-04-15 17:06:12 +02:00
TMP_RAW=$(grep -Fh " ${FILTER_HOSTNAME} postfix/" ${MAIL_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill)
2017-04-13 11:40:17 +02:00
else
2017-04-14 16:36:37 +02:00
# shellcheck disable=SC2086
2017-04-13 12:09:29 +02:00
TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${MAIL_LOG})
2017-04-13 11:40:17 +02:00
fi
2016-11-02 02:24:55 +01:00
# Parse value from Raw result
#
# Return digit if regex are parsed correctly
#
2016-11-04 05:11:19 +01:00
# Return U (undefined) if any error occurs
2016-11-02 02:24:55 +01:00
#
parseValue() {
# shellcheck disable=SC2155
2016-11-04 05:11:19 +01:00
local TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei "^[[:space:]]+[[:digit:]]+[[:space:]]+${1}.*$" | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g')
if [ -z "${TMP_RETURN}" ]; then
echo 'U'
2016-11-02 02:24:55 +01:00
else
echo "${TMP_RETURN}"
fi
}
2016-11-02 02:24:55 +01:00
# Print results
2016-11-04 05:11:19 +01:00
for i in $FIELDS_ARR; do
printf "%s.value " "${i}"
parseValue "${i}"
done