The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/bin/sh
#
# Plugin to show Spamassasin stats gathered from maillogs
#
# Contributed by Rob Lensen <rob@bsdfreaks.nl>
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# family=manual
#%# capabilities=autoconf

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

maillogs=/usr/local/bin/maillogs
if [ ! -f $maillogs ]; then
    maillogs=/usr/local/sbin/maillogs
fi

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

        echo 'graph_title SpamAssassin Mail Filtering'
        echo 'graph_args --base 1000 -l 0 '
        echo 'graph_vlabel Messages /hour'
        echo 'graph_category Mail'
        echo 'graph_info This graph show the Spamassasin results.'
        $maillogs spamassassin | awk "
        BEGIN {
            X = 0
        }
        {
            X = split(\$1,RBL,\":\")
            for ( i = 1 ; i <= 4 ; i++)
            {
                print RBL[i]\".label \"RBL[i]
                print RBL[i]\".type COUNTER\"
                print RBL[i]\".cdef \" RBL[i]\",3600,\* \"
                i++
                    
            }
            for ( i = 5 ; i <= X ; i++)
            {
                print RBL[i]\".label \"RBL[i]
                print RBL[i]\".type GAUGE\"
                print RBL[i]\".cdef \" RBL[i]\",.01,\* \"

                    i++
            }
       }"
        exit 0
fi

print_values(){
    X=0
     $maillogs spamassassin | awk "
        BEGIN {
            X = 0
        }
        {
            X = split(\$1,RBL,\":\")
            for ( i = 1 ; i <= X ; i++)
            {
                print RBL[i]\".value \"RBL[i+1]
                    i++
            }
        }"
}

print_values