Fwd: New: scripts/services/spamassassin

"Kirk Bauer" <[email protected]>
Newsgroups gmane.comp.log.logwatch.devel
Message-ID <[email protected]>
---------- Forwarded message ----------
From: Win Bent <[email protected]>
Date: Nov 26, 2007 5:56 PM
Subject: New: scripts/services/spamassassin
To: [email protected]
Cc: Win Bent <[email protected]>


#!/usr/bin/perl
##########################################################################
# $Id: spamassassin,v 1.3 2007/10/10 16:41:27 whb Exp $
##########################################################################
# $Log: spamassassin,v $
# Revision 1.3  2007/10/10 16:41:27  whb
# Yes, Win does get over 10000 spam messages PER DAY
#
# Revision 1.2  2007/01/20 17:13:56  whb
# Lump together child-related errors
# - We're experiencing periods of high loads, causing many fork errors
#
# Revision 1.1  2006/09/16 20:02:01  whb
# Initial revision
#
#
##########################################################################
# This was written and is maintained by:
#    Win Bent <[email protected]>
#
# Please send all comments, suggestions, bug reports,
#    etc, to [email protected].
########################################################

use Logwatch ':sort';

my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
my $Debug = $ENV{'LOGWATCH_DEBUG'} || 0;

$StillRoot = 0;
$CleanTotal = 0;
$SpamTotal = 0;

my %Child;
my %Clean;
my %Spam;
my %Users;

while (defined($ThisLine = <STDIN>)) {
   $ThisLine =~ s/^[a-zA-Z0-9]+: //;
   if ( # We don't care about these
      # Note that we DO care about "connection from" non-localhost
      ( $ThisLine =~ m/connection from localhost / ) or
      ( $ThisLine =~ m/setuid to / ) or
      ( $ThisLine =~ m/processing message / ) or
      ( $ThisLine =~ m/^result: / ) or
      ( $ThisLine =~ m/^child states: / ) or
      ( $ThisLine =~ m/^alarm *$/ ) or
      ( $ThisLine =~ m/^handled cleanup of child / ) or
      ( $ThisLine =~ m/^server successfully spawned child process, / ) or
      0  # Always last in the list, so all above can say "or" at the end
   ) {
      ; # We don't care about these
   } elsif ( ($User) = ($ThisLine =~ m/clean message .* for (.+?):\d+ / )) {
      $Clean{ $User}++;
      $Users{ $User}++;
   } elsif ( ($User) = ($ThisLine =~ m/identified spam .* for (.+?):\d+ / )) {
      $Spam{ $User}++;
      $Users{ $User}++;
   } elsif ( $ThisLine =~ m/still running as root: / ) {
      $StillRoot++;
   } elsif ( $ThisLine =~ m/\bchild\b/ ) {
      chomp($ThisLine);
      # Many perl errors report pseudo-line-numbers, e.g.
      #   ... at /usr/bin/spamd line 1085, <GEN5490> line 212
      $ThisLine =~ s/\d+/___/g;  # Make all numbers "generic"
      $Child{ $ThisLine }++;        # ...and count generic error types

   # EVERYTHING ELSE, or, Incentive to identify all "We don't care" lines
   # We on-purpose allow warnings about --max-children to go here
   } else {
      chomp($ThisLine);
      # Report any unmatched entries...
      $OtherList{$ThisLine}++;
   }
}

#######################################################

#XX print "# Detail:${Detail}\n"; #XX debugging

if ( keys %Users ) {
   my ($u, $cl, $sp);
   print "\nMail Recipients:\n";
   # Some might want to limit this output based on $Detail, but we want it all!
   foreach $u (sort {$a cmp $b} keys %Users) {
      $cl = 0 + $Clean{$u};   # Avoid "undefined" error
      $sp = 0 + $Spam{$u};    # Avoid "undefined" error
      $CleanTotal += $cl;
      $SpamTotal += $sp;
      #OLD: If one user gets over 9999 messages, you have our sympathies
      #NOW: If one user gets over 99999 messages, you have our sympathies
      printf "   %-8s : %4d clean, %5d spam\n", $u, $cl, $sp;
   }
}

if ( $CleanTotal || $SpamTotal ) {
   my $ttotal = $CleanTotal + $SpamTotal;
   print "\nSummary:\n";
   printf "\tTotal Clean: %5d (%3d%%)\n", $CleanTotal,
      int ((100.0 * $CleanTotal / $ttotal) + 0.5);
   printf "\tTotal Spam:  %5d (%3d%%)\n", $SpamTotal,
      int ((100.0 * $SpamTotal / $ttotal) + 0.5);
}

if ( $StillRoot ) {
   print qq{\n"still running as root" error: $StillRoot time(s)\n};
}

if (keys %Child) {
   print "\nChild-related errors\nn";
   foreach $line (sort {$Child{$b}<=>$Child{$a} } keys %Child) {
      print "   $line: $Child{$line} Time(s)\n";
   }
}

if (keys %OtherList) {
   print "\n**Unmatched Entries**\n";
   foreach $line (sort {$OtherList{$b}<=>$OtherList{$a} } keys %OtherList) {
      print "   $line: $OtherList{$line} Time(s)\n";
   }
}

exit(0);

# vi: shiftwidth=3 tabstop=3 et




-- 
Kirk Bauer <[email protected]>
http://linux.kaybee.org | www.logwatch.org
Author, Automating UNIX & Linux Administration
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.