[Mimedefang] Statistics
Aaron Paetznick
aaronp at critd.com
Mon Jul 8 17:27:01 EDT 2002
Here's what I do to add logging to my mimdefang-filter. Of course this
isn't the most efficient method to do logging of this sort, but it works
just the same. Please don't try this on your heavily-loaded production
boxen.
I added some supporting subroutines at the top of the file:
======== CUT ==========
sub formatTime {
return sprintf("%02d",shift);
}
sub formatString {
my $string = shift;
$string = "NULL" unless $string =~ /\S/;
return $string;
}
sub formatAddress {
my $addy = shift;
$addy =~ tr/\<//d;
$addy =~ tr/\>//d;
return $addy;
}
sub logEvent {
my $class = lc(shift);
my $message = shift;
my @time = localtime;
my $time_string = $time[5] + 1900 . "-" . formatTime($time[4] + 1) .
"-" . formatTime($time[3]) . " " . formatTime($time[2]) . ":" .
formatTime($time[1]) . ":" . formatTime($time[0]);
my $Recipient;
if (scalar(@Recipients) == 1) {
$Recipient = "->Recipient:" . formatAddress(shift(@Recipients));
} else {
$Recipient = "->Recipient:" . scalar(@Recipients) . " addresses";
}
open LOGFILE, ">>/var/log/email_filter_" . $class . ".log";
print LOGFILE "[" . $time_string . "]->MsgID:" . formatString($MsgID)
. "->Sender:" . formatString(formatAddress($Sender)) . $Recipient .
"->Subject:" . formatString($Subject) . "->Log:" . $message . "\n";
close LOGFILE;
}
======== CUT ==========
...and then I peppered the filter with logging statements wherever I
needed them, i.e.:
======== CUT ==========
if ($category eq "virus") {
logEvent("attachment","positive virus scan for " . $fname . ":" .
$VirusScannerMessages);
return action_quarantine($entity, "A known virus was discovered
and deleted. Virus-scanner messages follow:\n$VirusScannerMessages\n\n");
}
======== CUT ==========
I hope that my email client doesn't mangle the code with line breaks too
much...
--Aaron
David F. Skoll wrote:
> [Posted on behalf of Craig Smith]
>
> I cannot find any docs on MIMEDefang stats. I need to be able to tell
> the number of attachments stripped off, an a daily and monthly basis.
> Does anyone know of a good link or way to do this. You answers will
> be greatly appriciated. Or any HOWTO or ideas on stats at all.
>
> Thanks,
>
> Craig
>
> _______________________________________________
> MIMEDefang mailing list
> MIMEDefang at lists.roaringpenguin.com
> http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
More information about the MIMEDefang
mailing list