This little perl script is what I use to transform qmail log files into
something I can understand easily.  Face it, the format of the log files is
hard to track with your eyes, to tell when a message actually worked, with
its repeating message numbers and delivery numbers...

I run it under a 'watch -n 1 mailwatch' in the background to keep an eye on
things, but also put in options for retrieving from other files, and
retrieving an arbitrary number of deliveries (mailwatch /var/log/maillog.2
125) and all the entries (mailwatch /var/log/maillog.1 -) (default is
mailwatch /var/log/maillog 18)

I didn't bother transforming the tai times with the localtime function, just
clipping out the times in the log file already myself.  It would be trivial
to make the change though.

In its current incarnation, it prints out the messages that are recieved but
not delivered, and then prints out the specified number of entries (minus
the number of messages-in-delivery lines)

(it ignores everything with 'emon' in it, my little monitoring script, to
keep it from spamming my screen)

Its probably not complete, and not particularly efficient, but it sure
relaxes my mind when scanning current status.

David

--------------BEGIN PERL SCRIPT------------------
#!/usr/bin/perl

$| = 1;
my $logfile = $ARGV[0] ? $ARGV[0] : "/var/log/maillog";
if ($ARGV[1] eq "-") {
  $length = 0;
  @loglist = `cat $logfile`;
} elsif ($ARGV[1]) {
  $length = $ARGV[1];
  my $tail = $length * 50;
  @loglist = `/usr/bin/tail --lines $tail $logfile`;
} else {
  $length = "18";
  @loglist = `/usr/bin/tail --lines 1000 $logfile`;
}


foreach (@loglist) {
   if (/info msg (\d+): bytes (\d+) from \<(.*?)\>/) {
     $from{$1} = $3;
     $size{$1} = $2;
     unless ($from{$1} =~ /\@/) {
       $from{$1} = "BLANK-ADDRESS($from{$1})";
     }
   } elsif (/starting delivery (\d+): msg (\d+) to remote (.*?)$/) {
     $msg2del{$2} = $1;
     $del2msg{$1} = $2;
     $addressee{$2} = $3
   } elsif (/starting delivery (\d+): msg (\d+) to local (.*?)$/) {
     $msg2del{$2} = $1;
     $del2msg{$1} = $2;
     $addressee{$2} = $3
   } elsif (/(...............).+delivery (\d+): success: /) {
     if (exists $del2msg{$2}) {
#       printf "%s SUCCESS: %8.8s From %30.30s to %30.30s\n", $1, $2,
$from{$del2msg{$2}}, $addressee{$del2msg{$2}};
       $string = "$1 SUCCESS: From $from{$del2msg{$2}} delivered to
$addressee{$del2msg{$2}}";
       unless ($string =~ /emon/) { 
         push @through, $string;
       }
     } else {
       push @through, "orphan: no message info for delivery $2 ";
     }
   } elsif (/(...............).+delivery (\d+): failure: (.*)$/) {
     if (exists $del2msg{$2}) {
       push @through, "$1 FAILED: From $from{$del2msg{$2}} to
$addressee{$del2msg{$2}}";
       push @through, "$1 REASON: $3";
     }
   } elsif (/(...............).+delivery (\d+): deferral: /) {
     if (exists $del2msg{$2}) {
       push @through, "$1 DEFERRED: From $from{$del2msg{$2}} to
$addressee{$del2msg{$2}}";
     }
   } elsif (/status: /) {
   } elsif (/end msg (\d+)/) {
     delete $from{$1};
     delete $size{$1};
     delete $msg2del{$del2msg{$1}};
     delete $addressee{$del2msg{$1}};
     delete $del2msg{$1};
   } elsif (/new msg/) {
   } elsif (/(...............).*bounce msg (\d+)/) {
     push @through, "$1 BOUNCE: from $from{$2} to $addressee{$2}";
   } else {
     print "error: no match $_";
   }
}

open PIPE, "| cut -b -130";
$count = 0;

foreach (keys %from) {
  $count ++;
  unless (exists $msg2del{$_}) {
    print PIPE "message from $from{$_} recieved and waiting for delivery\n";
  } else {
    print PIPE "message from $from{$_} to $addressee{$_} delivery in
process\n"
  }
}

print PIPE "---OLDER---\n";

if ($length) {
  $lines = $length - $count ;
  $offset = $#through - ($lines);
} else {
  $lines = $#through;
  $offset = 0;
}
foreach (0..$lines) {
  print PIPE "$through[$offset + $_]\n";
}

print PIPE "---NEWER---\n";

-------END PERL SCRIPT-------------

-----Original Message-----
From: David Dyer-Bennet [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 31, 2000 10:54 AM
To: qmail list
Subject: Re: tai64n -- why?


[EMAIL PROTECTED] <[EMAIL PROTECTED]> writes on 31 July 2000 at 10:50:23
-0700
 > On Mon, Jul 31, 2000 at 12:23:38PM -0500, David Dyer-Bennet wrote:
 > > Charles Cazabon <[EMAIL PROTECTED]> writes on 31 July 2000 at
11:20:48 -0600
 > >  > David Dyer-Bennet <[EMAIL PROTECTED]> wrote:
 > >  > >  > 
 > >  > >  > Really? If I want to tail a log file, eg, I go like this:
 > >  > >  > 
 > >  > >  > tail ../someservice/current | tai64nlocal
 > >  > >  > 
 > >  > >  > and it all looks fine for humans.
 > >  >  
 > >  > > Yeah, it works fine for people who check log files by tailing
them.  I
 > >  > > check them by bringing them into an emacs buffer, so the funny
 > >  > > timestamps make them darned near useless.
 > >  > 
 > >  > So why not tail them to a temp file and use emacs to view the temp
file?
 > >  > Or write an emacs-lisp function to convert the timestamps.
 > > 
 > > If I'm going to go to effort to make it work the way I want, I think
 > > I'll just change multilog to use a sensible format.  It's silly having
 > > archival log files sitting there that don't mean anything without a
 > > conversion program; straight text is the appropriate format for log
 > > files. 
 > 
 > But it *is* straight text. The point about tai is that it's entirely
 > appropriate for log files that may live for a long time. Have you
 > read the rationale for tai at all?

Yes, when I first looked at it.  As is often the case with Dan, I just
disagree.  It's not straight text in the sense I mean; it's not human
readable.  Of all the strange choices Dan's made that I've encountered
in working with qmail, this is the first one that I fail completely to
understand.  All the others, I see the tradeoffs and I see why he
chose as he did, even if I might have chosen otherwise.  This one
makes zero sense.  It's non-functional.  It doesn't connect to the way
I work. 
-- 
Photos: http://dd-b.lighthunters.net/ Minicon: http://www.mnstf.org/minicon
Bookworms: http://ouroboros.demesne.com/ SF: http://www.dd-b.net/dd-b 
David Dyer-Bennet / Welcome to the future! / [EMAIL PROTECTED]

Reply via email to