Initial import master 0.1
authorEmmanuel Lacour <elacour@easter-eggs.com>
Mon, 8 Feb 2010 14:12:09 +0000 (15:12 +0100)
committerEmmanuel Lacour <elacour@easter-eggs.com>
Mon, 8 Feb 2010 14:12:09 +0000 (15:12 +0100)
A modified version of Fili Wiese amavis-debian munin plugin that shows all
statuses reported by amavisd-new.

amavisd-new [new file with mode: 0755]

diff --git a/amavisd-new b/amavisd-new
new file mode 100755 (executable)
index 0000000..c2d8ac4
--- /dev/null
@@ -0,0 +1,139 @@
+#!/bin/sh
+# 
+# Name: amavisd-new
+# Description: Munin plugin to monitor amavisd-new mail-filter
+#              Based on a plugin authored by Fili Wiese that may be found on
+#              http://muninexchange.projects.linpro.no/ under the name
+#              amavis-debian with some addition to show all type of amavis
+#              mails statuses: Total, Clean, Spammy, spam, Infected, Banned,
+#              Bad-header and other
+#
+# Parameters understood:
+#      config   (required)
+#      autoconf (optional)
+#
+# Config variables:
+#   AMAVIS_LOG - file where amavis logs are written
+#      STATEFILE       - file which is needed to keep track of AMAVIS_LOG
+#      LOGTAIL         - location of logtail
+#      BC              - location of bc
+#
+# Copyright (C) 2010 Emmanuel Lacour <elacour@home-dn.net>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+# 
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+# 
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
+#  USA.
+#
+
+AMAVIS_LOG=${logfile:-/var/log/mail.log}
+STATEFILE=/var/lib/munin/plugin-state/amavisd-new.offset
+LOGTAIL=${logtail:-`which logtail`}
+BC=${bc:-`which bc`}
+
+mktempfile () {
+       mktemp
+}       
+
+if [ "$1" = "autoconf" ]; then
+        if [ -f "${AMAVIS_LOG}" -a -n "${LOGTAIL}" -a -x "${LOGTAIL}" -a -n "${BC}" -a -x "${BC}" ] ; then
+               echo yes
+               exit 0
+       else
+               echo no
+               exit 1
+       fi
+fi
+
+if [ "$1" = "config" ]; then
+       echo 'graph_title Amavisd-new statistics'
+       echo 'graph_category amavis'
+       echo 'graph_order total clean spammy spam infected banned badh other'
+       echo 'graph_vlabel Mails'
+       echo 'graph_scale no'
+       echo 'total.info Total count of emails'
+       echo 'total.label Total'
+       echo 'total.draw AREA'
+       echo 'clean.info Count of clean emails'
+       echo 'clean.label Clean'
+       echo 'clean.draw LINE1'
+       echo 'spammy.info Count of spams emails (tag2 level)'
+       echo 'spammy.label Spammy'
+       echo 'spammy.draw LINE1'
+       echo 'spam.info Count of spams emails (kill level)'
+       echo 'spam.label Spam'
+       echo 'spam.draw LINE1'
+       echo 'infected.info Count of infected emails (virus)'
+       echo 'infected.label Infected'
+       echo 'infected.draw LINE1'
+       echo 'banned.info Count of emails with banned files'
+       echo 'banned.label Banned'
+       echo 'banned.draw LINE1'
+       echo 'badh.info Count of emails with bad headers'
+       echo 'badh.label Bad-header'
+       echo 'badh.draw LINE1'
+       echo 'other.info Count of emails that dont fit other categories'
+       echo 'other.label Others'
+       echo 'other.draw LINE1'
+       exit 0
+fi
+
+clean=0
+infected=0
+spammy=0
+spam=0
+banned=0
+badh=0
+other=0
+total=0
+
+ARGS=0
+`$LOGTAIL -f /etc/hosts 2>/dev/null >/dev/null`
+if [ $? = 66 ]; then
+    if [ ! -n "$logtail" ]; then
+       ARGS=1
+    fi
+fi
+
+TEMP_FILE=$(mktempfile munin-amavisd-new.XXXXXX)
+
+if [ -n "$TEMP_FILE" -a -f "$TEMP_FILE" ]
+then
+       if [ $ARGS != 0 ]; then
+           $LOGTAIL -f ${AMAVIS_LOG} -o $STATEFILE | grep 'amavis\[.*\]:' | grep -v 'TIMED OUT' > ${TEMP_FILE}
+       else
+           $LOGTAIL -f ${AMAVIS_LOG} -o $STATEFILE | grep 'amavis\[.*\]:' | grep -v 'TIMED OUT' > ${TEMP_FILE}
+       fi
+       total=$(wc -l < ${TEMP_FILE})
+       clean=$(grep -Ec '(Passed|Blocked) CLEAN' ${TEMP_FILE})
+       infected=$(grep -Ec '(Passed|Blocked) INFECTED' ${TEMP_FILE})
+       spammy=$(grep -Ec '(Passed|Blocked) SPAMMY' ${TEMP_FILE})
+       spam=$(grep -E '(Passed|Blocked) SPAM' ${TEMP_FILE} | grep -Ev '(Passed|Blocked) SPAMMY' | wc -l)
+       banned=$(grep -Ec '(Passed|Blocked) BANNED' ${TEMP_FILE})
+       badh=$(grep -Ec '(Passed|Blocked) BAD-HEADER' ${TEMP_FILE})
+       other=$(echo ${total}-${clean}-${infected}-${spammy}-${spam}-${banned}-${badh} | ${BC})
+       
+       /bin/rm -f $TEMP_FILE
+fi
+
+
+echo "clean.value ${clean}"
+echo "infected.value ${infected}"
+echo "spammy.value ${spammy}"
+echo "spam.value ${spam}"
+echo "banned.value ${banned}"
+echo "badh.value ${badh}"
+echo "other.value ${other}"
+echo "total.value ${total}"
+
+