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

105 lines
2.1 KiB
Plaintext
Raw Normal View History

#!/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
#
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
2016-11-02 05:07:45 +01:00
#%# family=contrib
#%# 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}
# Fields (Array to avoid code duplication)
declare -a 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-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
echo 'no';
2016-11-02 02:24:55 +01:00
else
echo 'yes'
2016-11-02 02:24:55 +01:00
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"
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.
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() {
TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei '^[[:space:]]+[[:digit:]]+[[:space:]]+'"${1}"'.*$' | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g')
2016-11-02 02:24:55 +01:00
if [[ -z "${TMP_RETURN}" ]]
then
echo -1
else
echo "${TMP_RETURN}"
fi
}
2016-11-02 02:24:55 +01:00
# Print results
for i in "${FIELDS_ARR[@]}"
do
printf "${i}.value "
parseValue "${i}"
done