Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: amavis logfile/viruspart parser

by Limbic~Region (Chancellor)
on Mar 08, 2004 at 15:49 UTC ( [id://334845]=note: print w/replies, xml ) Need Help??


in reply to amavis logfile/viruspart parser

teabag,
I know people have their own preference on coding style, but I find the following much more readable:
#!/usr/bin/perl use strict; use warnings; my $logfile = $ARGV[0] || "/var/amavis/amavis.log"; my $fprotdir = $ARGV[1] || "/var/virusmails"; my $virprog = $ARGV[2] || "f-prot"; my ($loc, $vir); open(LOGFILE, '<', $logfile) or die "Unable to open $logfile for readi +ng: $!"; while ( my $line = <LOGFILE> ) { chomp $line; if ( $line =~ /Infection:/ ) { ($loc, $vir) = ( split( / /, $line ) )[0, 3]; } elsif ( $line =~ /quarantined/ ) { my ($file, $time, $month, $day) = ( split( / /, $line ) )[12, +3, 0, 2]; my $date = "$day $month $time"; print "At $date $virprog detected a virus\nfound in $loc\n"; print "Name virus: $vir\nMessage saved as: $fprotdir/$file\n"; Checkwhosi( $file ); } } close LOGFILE or die "Unable to close $logfile : $!"; print "no viri received\n" if ! $vir; sub Checkwhosi { my $file_name = shift; my $file_fqn = "$fprotdir/$file_name"; open(VIRFILE, '<', $file_fqn) or die "Unable to open $file_fqn for + reading : $!"; my ($senderserv, $sserv2, %header); while ( my $line = <VIRFILE> ) { chomp $line; if ( $line =~ /Received:/ ) { ($senderserv, $sserv2) = ( split( / /, $line ) )[2,3]; $sserv2 =~ s/[(\[\]]//g; } elsif ( $line =~ /(From|To|Subject):/ ) { $header{ $1 } = ( split( / /, $line ) )[1]; } } print map{defined $header{$_} ? "$_: $header{$_}\n" : () } qw(To F +rom Subject); print "Virus Mailserver: $senderserv\nipadres server: $sserv2\n"; print "-" x 23, "\n"; close(VIRFILE) || die "Error closing viral log file: $!"; }
Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://334845]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-19 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found