2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/mail/postfix_stats
2016-11-04 10:48:06 +01:00

136 lines
2.8 KiB
Bash
Executable File

#!/bin/sh
# -*- 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
There is no default configuration. This is an example config for Ubuntu:
[postfix_stats]
env.logfiles /var/log/syslog /var/log/syslog.1
env.pflogsumm pflogsumm
env.logfiles contains space separated syslog logfiles, usually current log
and previous log. You can add more log files if you want, but this may
increase the time required for analysis.
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).
=head1 INTERPRETATION
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.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
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
Thanks to: sumpfralle
=head1 LICENSE
GPLv2
=cut
#set -xv
SYS_LOG="${logfiles:-/var/log/syslog /var/log/syslog.0}"
# shellcheck disable=SC2154
PFLOGSUMM="${pflogsum}"
[ -z "$PFLOGSUMM" ] && PFLOGSUMM="$(which pflogsumm pflogsumm.pl | head -1)"
# Fields (Array to avoid code duplication) must be space separated
FIELDS_ARR="received delivered forwarded deferred bounced rejected held discarded"
#
# Autoconf Section
#
if [ "$1" = 'autoconf' ]; then
# Check if pflogsumm exist
if [ -z "${PFLOGSUMM}" ]
then
echo 'no (pflogsum not found in your system)'
else
echo 'yes'
fi
exit 0
fi
#
# Config Section
#
if [ "$1" = 'config' ]; then
echo 'graph_title Postfix statistics'
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
for i in $FIELDS_ARR; do
echo "${i}.label ${i}"
echo "${i}.type DERIVE"
echo "${i}.min 0"
echo "${i}.draw AREASTACK"
done
exit 0
fi
#
# Plugin Script
#
# Variable to store the pflogsumm result.
# shellcheck disable=SC2086
TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${SYS_LOG})
# Parse value from Raw result
#
# Return digit if regex are parsed correctly
#
# Return U (undefined) if any error occurs
#
parseValue() {
# shellcheck disable=SC2155
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'
else
echo "${TMP_RETURN}"
fi
}
# Print results
for i in $FIELDS_ARR; do
printf "%s.value " "${i}"
parseValue "${i}"
done