#!/bin/sh
#
# Plugin to show amount of smtp-connections per hour
#
# Contributed by Håkon Nessjøen <lunatic@cpan.org>
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# family=manual
#%# capabilities=autoconf

if [ "$1" = "autoconf" ]; then
        echo yes
        exit 0
fi

if [ "$1" = "config" ]; then

        echo 'graph_title Qmail SMTP connections'
        echo 'graph_args --base 1000 -l 0 '
        echo 'graph_vlabel connections/hour'
        echo 'graph_category Mail'
        echo 'graph_order rbl accepted total'
        echo 'rbl.label RBL rejected connections'
        echo 'rbl.min 0'
        echo 'rbl.draw AREA'
				echo 'accepted.label Accepted connections'
				echo 'accepted.min 0'
				echo 'accepted.draw STACK'
				echo 'total.label Total connections'
				echo 'total.min 0'
				echo 'total.draw LINE1'
        exit 0
fi

rbl=`cat /var/log/qmail/smtpd/@* /var/log/qmail/smtpd/current | grep -c rblsmtp`
accepted=`cat /var/log/qmail/smtpd/@* /var/log/qmail/smtpd/current | grep -c 'tcpserver: ok'`

echo -n "rbl.value " && ( echo $rbl || echo U )
echo -n "accepted.value " && ( echo $accepted || echo U )
echo "total.value $[$rbl + $accepted]"
