1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-24 09:57:09 +00:00

Category Tree: reduce number of categories

This commit is contained in:
dipohl 2017-02-22 04:48:52 +01:00
parent 84c28707eb
commit c4b2d9a8e3
22 changed files with 377 additions and 377 deletions

110
plugins/amavis/amavis-debian Executable file
View file

@ -0,0 +1,110 @@
#!/bin/sh
#
# Plugin to monitor the amavis mail filter for Debian
# (based upon a plugin authored by Geoffroy Desvernay)
#
# This plugin is built and tested on Debian Etch using:
# munin 1.2.5-1
# amavisd-new 2.4.2-6.1
#
# With some minor modification it should also work on non-debian systems
# This, however, is up to you
#
# Munin graph will sum up: Passed CLEAN, Blocked VIRUS, Blocked SPAM, 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
#
# Enjoy!
# Fili Wiese
#
AMAVIS_LOG=${logfile:-/var/log/mail.log}
STATEFILE=/var/lib/munin/plugin-state/amavis.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 Amavis filter statistics'
echo 'graph_category antivirus'
echo 'graph_order total clean spam virus other'
echo 'graph_vlabel Mails filtered'
echo 'graph_scale no'
echo 'total.label Total'
echo 'total.draw AREA'
echo 'total.colour DDDDDD'
echo 'clean.label Passed CLEAN'
echo 'clean.draw LINE1'
echo 'clean.colour 32FA00'
echo 'spam.label Blocked SPAM'
echo 'spam.draw LINE1'
echo 'spam.colour FF0000'
echo 'virus.label Blocked VIRUS'
echo 'virus.draw LINE1'
echo 'virus.colour 880088'
echo 'other.label Other'
echo 'other.draw LINE1'
echo 'other.colour 0099FF'
exit 0
fi
clean=0
virus=0
spams=0
other=0
total=0
ARGS=0
`$LOGTAIL /etc/hosts 2>/dev/null >/dev/null`
if [ $? = 66 ]; then
if [ ! -n "$logtail" ]; then
ARGS=1
fi
fi
TEMP_FILE=`mktempfile munin-amavis.XXXXXX`
if [ -n "$TEMP_FILE" -a -f "$TEMP_FILE" ]
then
if [ $ARGS != 0 ]; then
$LOGTAIL ${AMAVIS_LOG} $STATEFILE | grep 'amavis\[.*\]:' | grep -v 'TIMED OUT' > ${TEMP_FILE}
else
$LOGTAIL ${AMAVIS_LOG} $STATEFILE | grep 'amavis\[.*\]:' | grep -v 'TIMED OUT' > ${TEMP_FILE}
fi
total=`cat ${TEMP_FILE} | wc -l`
clean=`grep 'CLEAN' ${TEMP_FILE} | wc -l`
virus=`grep 'INFECTED' ${TEMP_FILE} | wc -l`
spam=`grep 'Blocked SPAM' ${TEMP_FILE} | wc -l`
other=`echo ${total}-${clean}-${virus}-${other}-${spam} | ${BC}`
/bin/rm -f $TEMP_FILE
fi
echo "clean.value ${clean}"
echo "virus.value ${virus}"
echo "spam.value ${spam}"
echo "other.value ${other}"
echo "total.value ${total}"

192
plugins/amavis/amavis_ Executable file
View file

@ -0,0 +1,192 @@
#!/usr/bin/perl -w
#
# Plugin to monitor amavisd-new statistics. Values are retrieved by querying
# the BerkeleyDB database 'snmp.db', in which amavisd-new stores its
# statistics.
#
# The plugin requires the Perl module BerkeleyDB.
#
# To use, setup /etc/munin/plugin-conf.d/amavis e.g. as follows:
#
# [amavis_*]
# env.amavis_db_home /var/lib/amavis/db
# user amavis
#
# Where env.amavis_db_home is the path to the amavisd-new BerkeleyDB files
# (/var/amavis/db by default).
#
# Then create symlinks in the Munin plugin directory named "amavis_time",
# "amavis_cache" and "amavis_content", or use munin-node-configure.
#
# Parameters:
#
# config
# autoconf
# suggest
#
# Config variables:
#
# amavis_db_home - where the amavisd-new berkeley db files are located
#
# Magic markers
#%# family=auto
#%# capabilities=autoconf
#%# capabilities=suggest
use strict;
no warnings 'uninitialized';
use BerkeleyDB;
my($dbfile) = 'snmp.db';
my($db_home) = # DB databases directory
defined $ENV{'amavis_db_home'} ? $ENV{'amavis_db_home'} : '/var/amavis/db';
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
if (-x "/usr/sbin/amavisd-agent") {
print "yes\n";
exit 0;
} else {
print "no (/usr/sbin/amavisd-agent not found or not executable)\n";
exit 1;
}
} elsif ($ARGV[0] and $ARGV[0] eq "suggest") {
print "time\n";
print "cache\n";
print "content\n";
exit 0;
}
my $stats_type = "";
if ($0 =~ /^(?:|.*\/)amavis_(cache|content|time)$/) {
$stats_type = $1;
} else {
print "You need to create a symlink to this plugin called either amavis_cache, amavis_time or amavis_content to be able to use it.\n";
exit 2;
}
if ($ARGV[0] and $ARGV[0] eq "config") {
if ($stats_type eq "cache") {
print "graph_title Amavis cache hit / miss ratio\n";
print "graph_args --lower-limit 0 --upper-limit 100 --rigid\n";
print "graph_category antivirus\n";
print "graph_info The ratio of cache hits and misses for AMaViSd-new.\n";
print "graph_order hits misses\n";
print "graph_scale no\n";
print "graph_vlabel %\n";
print "hits.label Cache hits\n";
print "hits.draw AREA\n";
print "hits.max 100\n";
print "hits.min 0\n";
print "misses.label Cache misses\n";
print "misses.draw STACK\n";
print "misses.max 100\n";
print "misses.min 0\n";
} elsif ($stats_type eq "content") {
print "graph_title Amavis scanned mails\n";
print "graph_category antivirus\n";
print "graph_period minute\n";
print "graph_vlabel msgs / \${graph_period}\n";
foreach my $type (qw(total clean spam spammy virus)) {
print "$type.label " . ucfirst($type) . " mails \n";
print "$type.type DERIVE\n";
print "$type.min 0\n";
}
print "clean.info Legitimate mail.\n";
print "spammy.info Mails with a spam score above the tag2 level.\n";
print "spam.info Mails with a spam score above the kill level for spam.\n";
print "virus.info Mails with a virus.\n";
print "total.info Total number of scanned mails.\n";
} elsif ($stats_type eq "time") {
print "graph_title Amavis average scan time\n";
print "graph_info Average time spent in each phase of the mail scanning process, per mail.\n";
print "graph_category antivirus\n";
print "graph_vlabel sec / mail\n";
print "graph_scale no\n";
print "msgs.label Total number of messages\n";
print "msgs.graph no\n";
print "msgs.type DERIVE\n";
print "msgs.min 0\n";
foreach my $type (qw(decoding receiving sending spamcheck viruscheck total)) {
print "${type}.label " . ucfirst($type) . "\n";
print "${type}.type DERIVE\n";
print "${type}.min 0\n";
print "${type}.cdef ${type},1000,/,msgs,/\n";
}
}
exit 0;
}
my ($env, $db, @dbstat, $cursor);
@dbstat = stat("$db_home/$dbfile");
my $errn = @dbstat ? 0 : 0+$!;
$errn == 0 or die "stat $db_home/$dbfile: $!";
$env = BerkeleyDB::Env->new(
-Home => $db_home,
-Flags => DB_INIT_CDB | DB_INIT_MPOOL,
-ErrFile => \*STDOUT,
-Verbose => 1,
);
defined $env or die "BDB no env: $BerkeleyDB::Error $!";
$db = BerkeleyDB::Hash->new(-Filename => $dbfile, -Env => $env);
defined $db or die "BDB no db: $BerkeleyDB::Error $!";
my %values = ();
my ($eval_stat, $stat, $key, $val);
$cursor = $db->db_cursor; # obtain read lock
defined $cursor or die "db_cursor error: $BerkeleyDB::Error";
while (($stat = $cursor->c_get($key, $val, DB_NEXT)) == 0) {
$values{$key} = $val;
}
$stat == DB_NOTFOUND or die "c_get: $BerkeleyDB::Error $!";
$cursor->c_close == 0 or die "c_close error: $BerkeleyDB::Error";
$cursor = undef;
$eval_stat = $@;
if ($eval_stat ne '') { chomp($eval_stat); die "BDB $eval_stat\n"; }
for my $k (sort keys %values) {
if ($values{$k} =~ /^(?:C32|C64) (.*)\z/) {
$values{$k} = $1;
}
}
if ($stats_type eq "cache") {
my $hits = $values{'CacheHits'};
my $misses = $values{'CacheMisses'};
my $misses_ratio = $misses * 100.00 / ($hits + $misses);
my $hits_ratio = $hits * 100.00 / ($hits + $misses);
printf("hits.value %.1f\n", $hits_ratio);
printf("misses.value %.1f\n", $misses_ratio);
} elsif ($stats_type eq "content") {
printf("total.value %d\n", $values{'InMsgs'});
my $clean = $values{'ContentCleanMsgs'};
if (defined($values{'ContentCleanTagMsgs'})) {
$clean += $values{'ContentCleanTagMsgs'};
}
printf("clean.value %d\n", $clean);
printf("spam.value %d\n", $values{'ContentSpamMsgs'});
printf("spammy.value %d\n", $values{'ContentSpammyMsgs'});
printf("virus.value %d\n", $values{'ContentVirusMsgs'});
} elsif ($stats_type eq "time") {
printf("decoding.value %d\n", $values{'TimeElapsedDecoding'});
printf("receiving.value %d\n", $values{'TimeElapsedReceiving'});
printf("sending.value %d\n", $values{'TimeElapsedSending'});
printf("spamcheck.value %d\n", $values{'TimeElapsedSpamCheck'});
printf("viruscheck.value %d\n", $values{'TimeElapsedVirusCheck'});
printf("total.value %d\n", $values{'TimeElapsedTotal'});
printf("msgs.value %d\n", $values{'InMsgs'});
}
$db->db_close == 0 or die "BDB db_close error: $BerkeleyDB::Error $!";

84
plugins/amavis/amavis_awk Executable file
View file

@ -0,0 +1,84 @@
#!/bin/bash
#
# Plugin to monitor Amavis virus and spam statistics.
#
#
# Based on a routine by William Towle
# Uncomment the cdef lines to convert the graph to mails/minute
# Comment out the line "total.graph no" to show the total on the graph. This may not be aesthetically pleasing.
#
# Parameters understood:
#
# config (required)
# autoconf (optional)
#
# requires logtail
LOGDIR=${logdir:-/var/log/amavis}
MAIL_LOG=$LOGDIR/${logfile:-amavisd.log}
LOGTAIL=${logtail:-`which logtail`}
STATEFILE=/var/lib/munin/plugin-state/amavis.offset
if [ "$1" = "autoconf" ]; then
if [ -f "${MAIL_LOG}" -a -n "${LOGTAIL}" -a -x "${LOGTAIL}" ] ; then
echo yes
exit 0
else
echo no
exit 1
fi
fi
if [ "$1" = "config" ]; then
echo 'graph_title Amavis message filtering'
echo 'graph_category antivirus'
echo 'graph_vlabel Mails per minute'
echo 'graph_args --base 1000 -l 0'
echo 'graph_order clean p_spam b_spam virus total'
echo 'clean.min 0'
echo 'clean.type ABSOLUTE'
#echo 'clean.cdef clean,60,*'
echo 'clean.draw AREA'
for i in p_spam b_spam virus;
do
echo "$i.min 0"
echo "$i.type ABSOLUTE";
#echo "$i.cdef $i,60,*";
echo "$i.draw STACK";
done
echo 'clean.label Passed CLEAN'
echo 'p_spam.label Passed SPAMMY'
echo 'b_spam.label Blocked SPAMMY'
echo 'virus.label Blocked INFECTED'
echo 'total.label Total'
echo 'total.graph no'
echo 'clean.colour 00ff00'
echo 'p_spam.colour ff4000'
echo 'b_spam.colour ff0000'
echo 'virus.colour 000000'
exit 0
fi
$LOGTAIL ${MAIL_LOG} $STATEFILE | \
awk 'BEGIN { na= 0; nb= 0; nc= 0; nd= 0; total= 0 }
{
if (index($0, "Passed CLEAN")) { na++ ; total++ }
else if (index($0, "Passed SPAMMY")) { nb++ ; total++ }
else if (index($0, "Blocked SPAMMY")) { nc++ ; total++ }
else if (index($0, "INFECTED")) { nd++ ; total++ }
}
END { print "clean.value " na"\np_spam.value " nb"\nb_spam.value " nc"\nvirus.value " nd"\ntotal.value " total }'