1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00
Munin-Contrib/plugins/mail/postfix_stats
2016-11-04 05:11:19 +01:00

129 lines
2.6 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 can
increase the time required to parse it.
env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if are manually
downloaded and installed or pflogsumm if are installed by apt-get.
=head1 INTERPRETATION
This plugin adds up the RSS of all processes matching the
regex given as the process name, as reported by ps.
=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}"
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.
TMP_RAW=$(eval "${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() {
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