[Logwatch] Re: [Logwatch-Devel] sendmail counts

Mike Tremaine mgt at stellarcore.net
Tue Jan 25 15:57:57 MST 2005


I still need to sit down and play with didn;t mean to ignore it for so
long.

Mike

On Sun, 2005-01-09 at 10:59, Bjorn L. wrote:
> Mike,
> 
> I traced back the use of relay delivery agent in the default setting
> of cf files.  When the feature(`msp') is used, it forwards the message
> using the relay mailer to itself ([127.0.0.1] or localhost).
> 
> So I've coded this particular scenario and extracted it from the counts,
> listing it separately, as it may not be of interest to most people.
> 
> Attached is the diff file from the original 1.42 version.
> 
> ______________________________________________________________________
> --- send1.42.orig	2004-12-24 14:49:38.000000000 -0800
> +++ sendmail.rcpts	2005-01-09 10:37:09.755556495 -0800
> @@ -76,11 +76,12 @@
>  my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;
>  my $Debug = $ENV{'LOGWATCH_DEBUG'} || 0;
>  
> -#Local domains, used for the per-domain analysis.
> -my %LocalDomains;
> +#Mailer names hash
> +my %Mailers;
>  
>  $MsgsSent = 0;
>  $BytesTransferred = 0;
> +$AddrRcpts = 0;
>  $HourReturns = 0;
>  $DaysReturns = 0;
>  $UserUnknown = 0;
> @@ -102,63 +103,7 @@
>  my %MailRejected;
>  my %SPFTotal;
>  
> -# Adds a new domain to the hash used for domain reporting.
> -sub InitDomainHash ($) {
> -   $Domain = $_[0];
> -   if ( ($Domain) = ($Domain =~ /^([\S]+)/) ) {
> -     $LocalDomains{$Domain}{"MsgsOut"} = 0;
> -     $LocalDomains{$Domain}{"MsgsIn"} = 0;
> -     $LocalDomains{$Domain}{"MsgsInternal"} = 0;
> -     $LocalDomains{$Domain}{"BytesOut"} = 0;
> -     $LocalDomains{$Domain}{"BytesIn"} = 0;
> -     $LocalDomains{$Domain}{"BytesInternal"} = 0;
> -   } # if
> -} # sub
> -
>  if ($Detail >= 10) {
> -   # Reads the sendmail configuration files and builds the %LocalDomains
> -   # hash containing all local and relayed domains.
> -   my ($ThisLine,$ThisName);
> -   my ($LocalHostNames, $SendmailAccess);
> -
> -   # Check for valid local-host-names file.
> -   if (defined($ENV{'sendmaillocalhostnames'})) {
> -      $LocalHostNames = $ENV{'sendmaillocalhostnames'};
> -   } else {
> -      $LocalHostNames = "/etc/mail/local-host-names";
> -   } # else
> -   if (-s $LocalHostNames) {
> -      # Read and process local-host-names
> -      open (READCONFFILE, $LocalHostNames) or die "Cannot open " . $LocalHostNames ."\n";
> -      while (defined($ThisLine = <READCONFFILE>)) {
> -         if ( ($ThisName) = ($ThisLine =~ /^([^#][^ ]+)/) ) {
> -            InitDomainHash($ThisName);
> -         } # if
> -      } # while
> -      close(READCONFFILE);
> -   } else {
> -     print "\nERROR: Could not open $LocalHostNames\n";
> -   } # if
> -
> -   # Check for valid access map file.
> -   if (defined($ENV{'sendmailaccess'})) {
> -      $SendmailAccess = $ENV{'sendmailaccess'};
> -   } else {
> -      $SendmailAccess = "/etc/mail/access";
> -   } # if
> -   if (-s $SendmailAccess) {
> -      # Read and interpret the access map.
> -      open (READCONFFILE, $SendmailAccess) or die "Cannot open " . $SendmailAccess ."\n";
> -      while (defined($ThisLine = <READCONFFILE>)) {
> -         if ( ($ThisName) = ($ThisLine =~ /^([^#0-9][\S]+)[\s]+RELAY/) ) {
> -            InitDomainHash($ThisName);
> -         } # if
> -      } # while
> -      close(READCONFFILE);
> -   } else {
> -     print "\nERROR: Could not open $SendmailAccess\n";
> -   } # if
> -
>     # Initialise the Size distribution array
>     my %SizeDist;
>     @SizeNames = ('0 - 10k', '10k - 20k', '20k - 50k', '50k - 100k',
> @@ -212,14 +157,13 @@
>        ( $ThisLine =~ m/^accepting connections again for daemon / )
>     ) {
>        # We don't care about these
> -   } elsif ( ($FromUser, $FromDomain, $Bytes, $NumRcpts, $RelayHost) = ($ThisLine =~ /^from=[\<]?([^@]+)[@]?([^\> ]+).*size=([0-9]+).*nrcpts=([0-9]+).*relay=(\[[0-9\.]+\]|[^ ]* \[[0-9\.]+\]|[^ ]+).*$/) ) {
> +   } elsif ( ($FromUser, $Bytes, $NumRcpts, $RelayHost) = ($ThisLine =~ /^from=([^,]*),.*size=([0-9]+).*nrcpts=([0-9]+).*relay=(\[[0-9\.]+\]|[^ ]* \[[0-9\.]+\]|[^ ]+).*$/) ) {
>        if ($NumRcpts > 0) {
>           $MsgsSent++;
> -         $TotalRcpts += $NumRcpts;
> +         $AddrRcpts += $NumRcpts;
>           $BytesTransferred += $Bytes;
>           $MailBomber{$RelayHost} += $NumRcpts;
>           $MailBomberConn{$RelayHost}++;
> -         
>           if ($Bytes <= 10240) {
>              $SizeDist[0]{'Num'}++;
>              $SizeDist[0]{'Bytes'} += $Bytes;
> @@ -256,48 +200,29 @@
>        # Add The message to a hash for later per-domain analysis.
>        $Msgs{$QueueID}{"Relay"} = $RelayHost;
>        if (($Detail >= 10)) {
> -         $Msgs{$QueueID}{"FromDomain"} = $FromDomain;
>           $Msgs{$QueueID}{"FromUser"} = $FromUser;
>           $Msgs{$QueueID}{"Size"} = $Bytes;
> -         $Msgs{$QueueID}{"Internal"} = 0;
> -         $Msgs{$QueueID}{"Outgoing"} = 0;
> -         $Msgs{$QueueID}{"Incomming"} = 0;
>        } # if
> -      
> -   } elsif ( ($ToUser, $ToDomain) = ($ThisLine =~ m/^to=[\<]?([^@]*)[@]?([^,\>]+).*stat=/ ) ) {
> -      #Determine whether the message is local, inbound or outbound and
> -      #update the domains hash appropriately.
> -      if (($Detail >= 10)) {
> -         $FromDomain = $Msgs{$QueueID}{"FromDomain"};
> -         if (defined($LocalDomains{$FromDomain})) {
> -            if (defined($LocalDomains{$ToDomain})) {
> -               if ($Msgs{$QueueID}{"Internal"} == 0) {
> -                  $Msgs{$QueueID}{"Internal"} = 1;
> -                  $LocalDomains{$FromDomain}{"MsgsInternal"}++;
> -                  $LocalDomains{$FromDomain}{"BytesInternal"} += $Msgs{$QueueID}{"Size"};
> -               } # if
> -            } else {
> -               if ($Msgs{$QueueID}{"Outgoing"} == 0) {
> -                  $Msgs{$QueueID}{"Outgoing"} = 1;
> -                  $LocalDomains{$FromDomain}{"MsgsOut"}++;
> -                  $LocalDomains{$FromDomain}{"BytesOut"} += $Msgs{$QueueID}{"Size"};
> -               } # if
> -            } # else
> +
> +   } elsif ( ($ToUser, $MailerString, $DeliverStat) = ($ThisLine =~ m/^to=([^,]*), (.*)stat=(.*)/ ) ) {
> +      if ( $DeliverStat =~ /^Sent/ ) {
> +     	   (($MailerType) = ( $MailerString =~ /mailer=(.*?),/));
> +     	   (($RelayName) = ( $MailerString =~ /relay=(.*?),/));
> +         $MailerType =~ s/^\s*$/\(unspecified\)/;
> +         # remove the entries from MSP (Mail Submission Program) relay to
> +         #    localhost
> +         if (($MailerType =~ /^relay$/) and
> +                  ($RelayName =~ /\[127\.0\.0\.1\]/)) {
> +            $RelayLocalhost++;
>           } else {
> -            if (defined($LocalDomains{$ToDomain})) {
> -               if ($Msgs{$QueueID}{"Incomming"} == 0) {
> -                  $Msgs{$QueueID}{"Incomming"} = 1;
> -                  $LocalDomains{$ToDomain}{"MsgsIn"}++;
> -                  $LocalDomains{$ToDomain}{"BytesIn"} += $Msgs{$QueueID}{"Size"};
> -               } # if
> -            } # if
> -         } # else
> -         
> -         if ($Msgs{$QueueID}{"Size"} > 5242880) {  #10485760
> -            $LargeMsgs{$Msgs{$QueueID}{"FromUser"} . "@" . $FromDomain . " \-\> " .$ToUser . "@" .$ToDomain}++;
> -         } # if
> -      } # if
> -      
> +            $Mailers{$MailerType}++;
> +         } # if $MailerType !~ /^relay$/ ...
> +      } # if $DeliverStat =~ /^Sent/
> +      # else [ do nothing if $DeliverStat != /^Sent/ ]
> +  
> +      if ($Msgs{$QueueID}{"Size"} > 5242880) {  #10485760
> +         $LargeMsgs{$Msgs{$QueueID}{"FromUser"} . " \-\> " .$ToUser}++;
> +      } # if size > 5242880
>     } elsif ( $ThisLine =~ m/X-Scanned-By: MIMEDefang/) {
>        $Defang++;
>     } elsif (($Size) = ($ThisLine =~ m/message size \(([0-9]+)\) exceeds maximum/)) {
> @@ -508,9 +433,38 @@
>  #######################################################
>  
>  if ($MsgsSent > 0) {
> -   print "\n\nBytes Transferred: $BytesTransferred\n";
> -   print "Messages Sent:     $MsgsSent\n";
> -   print "Total recipients:  $TotalRcpts";
> +   print "\n\nBytes Transferred:      $BytesTransferred";
> +   print "\nMessages Processed:     $MsgsSent";
> +# Each explicitely addressed recipient in an email is counted as an
> +# "Addressed Recipient"
> +   print "\nAddressed Recipients:   $AddrRcpts";
> +}
> +
> +# Message recipients are the actual recipients - one for each
> +# recipient to which to which a copy of email is sent
> +if (($Detail >= 10) and (keys %Mailers)) {
> +   @DefinedMailers = ('smtp', 'esmtp', 'smtp8', 'dsmtp', 'relay', 'procmail',
> +     'local', 'prog', '*file*');
> +   print "\n\nMessage recipients per delivery agent:";
> +   $TotalNum = 0;
> +   print "\n          Name   #Rcpts\n          ----   ------";
> +   # first we print the common mailers, to maintains some logical grouping
> +   foreach $MailerName (@DefinedMailers) {
> +     if ($Mailers{$MailerName}) {
> +        printf("\n  %13s:%7d", $MailerName, $Mailers{$MailerName});
> +        $TotalNum += $Mailers{$MailerName};
> +        delete($Mailers{$MailerName});
> +     }
> +   }
> +   # now we print all remaining mailers
> +   foreach $MailerName (keys %Mailers) {
> +     printf("\n  %13s:%7d", $MailerName, $Mailers{$MailerName});
> +     $TotalNum += $Mailers{$MailerName};
> +   }
> +   printf("\n          -------------\n          Total:%7d", $TotalNum);
> +   if ($RelayLocalhost > 0) {
> +      print " plus $RelayLocalhost relay submission(s) from MSP";
> +   }
>  }
>  
>  if ($Defang > 0) {
> @@ -586,35 +540,10 @@
>     }
>  }
>  
> -if (($Detail >= 10) and (keys %LocalDomains)) {
> -   print "\n\nMessage traffic by domain:\n";
> -   print "                         |   Inbound   |  Outbound   |  Internal   |    Total\n";
> -   print "Domain                   | Msgs Kbytes | Msgs Kbytes | Msgs Kbytes | Msgs Kbytes\n";
> -   print "-------------------------+-------------+-------------+-------------+------------\n";
> -   foreach $ThisOne (sort keys %LocalDomains) {
> -      if (($LocalDomains{$ThisOne}{"BytesIn"} + $LocalDomains{$ThisOne}{"BytesOut"} + $LocalDomains{$ThisOne}{"BytesInternal"}) > 0) {
> -         $LineMsgs = $LocalDomains{$ThisOne}{"MsgsIn"} + $LocalDomains{$ThisOne}{"MsgsOut"} + $LocalDomains{$ThisOne}{"MsgsInternal"};
> -         $LineBytes = $LocalDomains{$ThisOne}{"BytesIn"} + $LocalDomains{$ThisOne}{"BytesOut"} + $LocalDomains{$ThisOne}{"BytesInternal"};
> -         $PrintThisOne = $ThisOne;
> -         $PrintThisOne =~ s/^(.{25}).+$/$1/ if( length($PrintThisOne) > 25 );
> -         printf("%-25s|%5d %6d |%5d %6d |%5d %6d |%5d %6d\n", $PrintThisOne, $LocalDomains{$ThisOne}{"MsgsIn"}, $LocalDomains{$ThisOne}{"BytesIn"}/1024, $LocalDomains{$ThisOne}{"MsgsOut"}, $LocalDomains{$ThisOne}{"BytesOut"}/1024, $LocalDomains{$ThisOne}{"MsgsInternal"}, $LocalDomains{$ThisOne}{"BytesInternal"}/1024, $LineMsgs, $LineBytes/1024);
> -         $TotalMsgsIn += $LocalDomains{$ThisOne}{"MsgsIn"};
> -         $TotalMsgsOut += $LocalDomains{$ThisOne}{"MsgsOut"};
> -         $TotalMsgsInternal += $LocalDomains{$ThisOne}{"MsgsInternal"};
> -         $TotalBytesIn += $LocalDomains{$ThisOne}{"BytesIn"};
> -         $TotalBytesOut += $LocalDomains{$ThisOne}{"BytesOut"};
> -         $TotalBytesInternal += $LocalDomains{$ThisOne}{"BytesInternal"};
> -      } # if
> -   } # foreach
> -   print "-------------------------+-------------+-------------+-------------+------------\n";
> -   $LineMsgs = $TotalMsgsIn + $TotalMsgsOut + $TotalMsgsInternal;
> -   $LineBytes = $TotalBytesIn + $TotalBytesOut + $TotalBytesInternal;
> -   printf("TOTAL                    |%5d %6d |%5d %6d |%5d %6d |%5d %6d\n", $TotalMsgsIn, $TotalBytesIn/1024, $TotalMsgsOut, $TotalBytesOut/1024, $TotalMsgsInternal, $TotalBytesInternal/1024, $LineMsgs, $LineBytes/1024);
> -} # if
> -
>  if (($Detail >= 10)) {
>     print "\n\nMessage Size Distribution:\n";
>     print "Range          # Msgs       KBytes\n";
> +   $TotalNum = 0;
>     foreach $ThisOne (0..9) {
>        printf("%-12s   %6d   %10d\n", $SizeNames[$ThisOne], $SizeDist[$ThisOne]{'Num'}, $SizeDist[$ThisOne]{'Bytes'}/1024);
>        $TotalNum += $SizeDist[$ThisOne]{'Num'};
> 
> ______________________________________________________________________
> _______________________________________________
> Logwatch-Devel mailing list
> Logwatch-Devel at logwatch.org
> http://www2.list.logwatch.org:81/lists/listinfo/logwatch-devel
-- 
Mike Tremaine
mgt at stellarcore.net
http://www.stellarcore.net



More information about the Logwatch mailing list