#!/usr/bin/perl -w
##########################################################################
# $Id: amavis,v 1.3 2002/10/12 02:08:18 kirk Exp $
##########################################################################

########################################################
# This was written and is maintained by:
#    Jim O'Halloran <jim@kendle.com.au>
#
# Please send all comments, suggestions, bug reports,
#    etc, to jim@kendle.com.au.
########################################################

$Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'};
$CleanMsgs = 0;
$InfectedMsgs = 0;

# Parse logfile
while (defined($ThisLine = <STDIN>)) {
   $ThisLine =~ s/^\([\d]+\) //;
   
   if ( ($ThisLine =~ /^do_ascii/) 
        or ($ThisLine =~ /^Found av scanner/) 
        or ($ThisLine =~ /^Found \$[\S]+[\s]+at/)  
        or ($ThisLine =~ /^No \$[\S]+,[\s]+not using it/) 
        or ($ThisLine =~ /^starting.  amavisd at/) ) {
       # We don't care about these
   } elsif ($ThisLine =~ /^Passed, /) {
      $CleanMsgs++;
   } elsif (($Virus) = ( $ThisLine =~ /^INFECTED \(([^\)]+)\)/ )) { 
      $InfectedMsgs++;

      if ($Detail >= 10) {
        $Viruses{$Virus}++;
      }; # if
   } # elsif
   else {
      # Report any unmatched entries...
      chomp($ThisLine);
      $OtherList{$ThisLine}++;        
   } # else
} # while


# Output report
if ($CleanMsgs > 0) {
   print "\n$CleanMsgs messages checked and passed.\n";
}; # if 

if ($InfectedMsgs > 0) {
   print "$InfectedMsgs virus infected messages were found.\n";
}; # if

if ((keys %Viruses) and ($Detail >= 10)) {
   print "\n\nViruses Detected:\n";
   foreach $Virus (sort {$Viruses{$b}<=>$Viruses{$a} } keys %Viruses) {
      print "   $Virus: $Viruses{$Virus} Times(s)\n";
   }; # foreach
}; # if

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

exit(0);

