2013-11-03 09:20:42 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Plugin to show Postfix statistics - needs pflogsumm
|
|
|
|
#
|
|
|
|
# Contributed by David Obando (david@cryptix.de) - 16.04.2007
|
2016-11-02 02:24:55 +01:00
|
|
|
# Rewrited by Cristian Deluxe (me@cristiandeluxe.com) - 02.11.2016
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Example config for Ubuntu (You need: apt-get install pflogsumm)
|
|
|
|
#
|
|
|
|
# [postfix_stats]
|
|
|
|
# env.logfile /var/log/syslog
|
|
|
|
# env.logfile2 /var/log/syslog.1
|
|
|
|
# env.pflogsumm pflogsumm
|
2013-11-03 09:20:42 +01:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# Magic markers - optional - used by installation scripts and
|
|
|
|
# munin-config:
|
|
|
|
#
|
2016-11-02 05:07:45 +01:00
|
|
|
#%# family=contrib
|
2013-11-03 09:20:42 +01:00
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
#set -xv
|
2016-11-02 02:24:55 +01:00
|
|
|
SYS_LOG=${logfile:-/var/log/syslog}
|
|
|
|
SYS_LOG2=${logfile2:-/var/log/syslog.0}
|
|
|
|
PFLOGSUMM=${pflogsumm:-pflogsumm.pl}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Autoconf Section
|
|
|
|
#
|
2016-11-02 04:53:27 +01:00
|
|
|
if [ "$1" = 'autoconf' ]; then
|
2016-11-02 02:24:55 +01:00
|
|
|
# Try to find pflogsumm with default name
|
|
|
|
PFLOG_EXIST=$(command -v pflogsumm.pl)
|
|
|
|
|
|
|
|
# Try to find pflogsumm without any extension
|
|
|
|
if [[ -z "${PFLOG_EXIST}" ]]
|
|
|
|
then
|
|
|
|
PFLOG_EXIST=$(command -v pflogsumm)
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "${PFLOG_EXIST}" ]]
|
|
|
|
then
|
2016-11-02 04:53:27 +01:00
|
|
|
echo 'no';
|
2016-11-02 02:24:55 +01:00
|
|
|
else
|
2016-11-02 04:53:27 +01:00
|
|
|
echo 'yes'
|
2016-11-02 02:24:55 +01:00
|
|
|
fi
|
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Config Section
|
|
|
|
#
|
2016-11-02 04:53:27 +01:00
|
|
|
if [ "$1" = 'config' ]; then
|
|
|
|
echo 'graph_title Postfix statistics'
|
|
|
|
echo 'graph_vlabel Postfix statistics'
|
|
|
|
echo 'graph_category mail'
|
|
|
|
echo 'graph_scale no'
|
2016-11-02 06:34:57 +01:00
|
|
|
echo 'graph_period minute'
|
2016-11-02 04:53:27 +01:00
|
|
|
echo 'graph_total Total'
|
|
|
|
echo 'received.label received'
|
2016-11-02 05:03:01 +01:00
|
|
|
echo 'received.type DERIVE'
|
|
|
|
echo 'received.min 0'
|
2016-11-02 04:53:27 +01:00
|
|
|
echo 'delivered.label delivered'
|
2016-11-02 05:03:01 +01:00
|
|
|
echo 'delivered.type DERIVE'
|
|
|
|
echo 'delivered.min 0'
|
2016-11-02 04:53:27 +01:00
|
|
|
echo 'forwarded.label forwarded'
|
2016-11-02 05:03:01 +01:00
|
|
|
echo 'forwarded.type DERIVE'
|
|
|
|
echo 'forwarded.min 0'
|
2016-11-02 04:53:27 +01:00
|
|
|
echo 'deferred.label deferred'
|
2016-11-02 05:03:01 +01:00
|
|
|
echo 'deferred.type DERIVE'
|
|
|
|
echo 'deferred.min 0'
|
2016-11-02 04:53:27 +01:00
|
|
|
echo 'bounced.label bounced'
|
2016-11-02 05:03:01 +01:00
|
|
|
echo 'bounced.type DERIVE'
|
|
|
|
echo 'bounced.min 0'
|
2016-11-02 04:53:27 +01:00
|
|
|
echo 'rejected.label rejected'
|
2016-11-02 05:03:01 +01:00
|
|
|
echo 'rejected.type DERIVE'
|
|
|
|
echo 'rejected.min 0'
|
2016-11-02 04:53:27 +01:00
|
|
|
echo 'held.label held'
|
2016-11-02 05:03:01 +01:00
|
|
|
echo 'held.type DERIVE'
|
|
|
|
echo 'held.min 0'
|
2016-11-02 04:53:27 +01:00
|
|
|
echo 'discarded.label discarded'
|
2016-11-02 05:03:01 +01:00
|
|
|
echo 'discarded.type DERIVE'
|
|
|
|
echo 'discarded.min 0'
|
2016-11-02 02:24:55 +01:00
|
|
|
exit 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# Plugin Script
|
|
|
|
#
|
|
|
|
|
|
|
|
# Variable to store the pflogsumm result.
|
|
|
|
TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill "${SYS_LOG}" "${SYS_LOG2}")
|
|
|
|
|
|
|
|
# Parse value from Raw result
|
|
|
|
#
|
|
|
|
# Return digit if regex are parsed correctly
|
|
|
|
#
|
|
|
|
# Return -1 if any error occurs
|
|
|
|
#
|
|
|
|
parseValue() {
|
2016-11-02 04:04:47 +01:00
|
|
|
TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei '^[[:space:]]+[[:digit:]]+[[:space:]]+'"${1}"'.*$' | grep -oEi '[[:digit:]]+[[:space:]]+' | sed 's: ::g')
|
2016-11-02 02:24:55 +01:00
|
|
|
if [[ -z "${TMP_RETURN}" ]]
|
|
|
|
then
|
|
|
|
echo -1
|
|
|
|
else
|
|
|
|
echo "${TMP_RETURN}"
|
|
|
|
fi
|
|
|
|
}
|
2013-11-03 09:20:42 +01:00
|
|
|
|
2016-11-02 02:24:55 +01:00
|
|
|
# Print results
|
2016-11-02 04:53:27 +01:00
|
|
|
printf 'received.value '
|
|
|
|
parseValue 'received'
|
|
|
|
printf 'delivered.value '
|
|
|
|
parseValue 'delivered'
|
|
|
|
printf 'forwarded.value '
|
|
|
|
parseValue 'forwarded'
|
|
|
|
printf 'deferred.value '
|
|
|
|
parseValue 'deferred'
|
|
|
|
printf 'bounced.value '
|
|
|
|
parseValue 'bounced'
|
|
|
|
printf 'rejected.value '
|
|
|
|
parseValue 'rejected'
|
|
|
|
printf 'held.value '
|
|
|
|
parseValue 'held'
|
|
|
|
printf 'discarded.value '
|
|
|
|
parseValue 'discarded'
|