Add -v functionality to exigrep.
[exim.git] / src / src / eximstats.src
index 7cd1978c6032575563d9d30efa1e912a9f2d7bc2..4791c77f588b0712b2c64d2de7f997a6f3d924ce 100644 (file)
@@ -1,5 +1,5 @@
 #!PERL_COMMAND -w
-# $Cambridge: exim/src/src/eximstats.src,v 1.11 2006/11/16 16:16:30 steve Exp $
+# $Cambridge: exim/src/src/eximstats.src,v 1.14 2007/02/14 12:20:43 steve Exp $
 
 # Copyright (c) 2001 University of Cambridge.
 # See the file NOTICE for conditions of use and distribution.
 # 2006-11-16  V1.50 Steve Campbell
 #             Fixes for obtaining the IP address from reject messages.
 #
+# 2006-11-27  V1.51 Steve Campbell
+#             Another update for obtaining the IP address from reject messages.
+#
+# 2006-11-27  V1.52 Steve Campbell
+#             Tally any reject message containing SpamAssassin.
+#
+# 2007-01-31  V1.53 Philip Hazel
+#             Allow for [pid] after date in log lines
+#
+# 2007-02-14  V1.54 Daniel Tiefnig
+#             Improved the '($parent) =' pattern match.
+#
 #
 #
 # For documentation on the logfile format, see
@@ -552,7 +564,7 @@ use vars qw($WEEK $DAY $HOUR $MINUTE);
 
 @days_per_month = (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
 $gig     = 1024 * 1024 * 1024;
-$VERSION = '1.50';
+$VERSION = '1.54';
 
 # How much space do we allow for the Hosts/Domains/Emails/Edomains column headers?
 $COLUMN_WIDTHS = 8;
@@ -1815,7 +1827,7 @@ sub generate_parser {
 
     $length = length($_);
     next if ($length < 38);
-    next unless /^(\\d{4}\\-\\d\\d-\\d\\d\\s(\\d\\d):(\\d\\d):\\d\\d( [-+]\\d\\d\\d\\d)?)/o;
+    next unless /^(\\d{4}\\-\\d\\d-\\d\\d\\s(\\d\\d):(\\d\\d):\\d\\d( [-+]\\d\\d\\d\\d)?)( \\[\\d+\\])?/o;
 
     ($tod,$m_hour,$m_min) = ($1,$2,$3);
 
@@ -1828,6 +1840,12 @@ sub generate_parser {
       $extra = 0;
     }
 
+    # PH - watch for PID added after the timestamp.
+    if (defined($5)) {
+      $extra += length($5);
+      next if ($length < 38 + $extra);
+    }
+
     $id   = substr($_, 20 + $extra, 16);
     $flag = substr($_, 37 + $extra, 2);
 
@@ -2061,7 +2079,8 @@ sub generate_parser {
             #IFNDEF ($include_original_destination)
             if ($user =~ /^[\\/|]/) {
             #ENDIF ($include_original_destination)
-              my($parent) = $_ =~ /(<[^@]+@?[^>]*>)/;
+              #my($parent) = $_ =~ /(<[^@]+@?[^>]*>)/;
+              my($parent) = $_ =~ / (<.+?>) /;              #DT 1.54
               $user = "$user $parent" if defined $parent;
             }
             ++$delivered_messages_user{$user};
@@ -2149,7 +2168,8 @@ sub generate_parser {
             #IFNDEF ($include_original_destination)
             if ($user =~ /^[\\/|]/) {
             #ENDIF ($include_original_destination)
-              my($parent) = $_ =~ /(<[^@]+@?[^>]*>)/;
+              #my($parent) = $_ =~ /(<[^@]+@?[^>]*>)/;
+              my($parent) = $_ =~ / (<.+?>) /;              #DT 1.54
               $user = "$user $parent" if defined $parent;
             }
             ++$delivered_addresses_user{$user};
@@ -2268,9 +2288,13 @@ sub generate_parser {
     if ($flag eq "Re" || ($flag eq "=>" && ! /\\sT=\\S+/)) {
       # Correct the IP address for rejects:
       # rejected EHLO from my.test.net [10.0.0.5]: syntactically invalid argument(s):
-      $ip = $1 if ($ip eq "local" && /^rejected [HE][HE]LO from .*? (\[.+?\]):/);
+      # rejected EHLO from [10.0.0.6]: syntactically invalid argument(s):
+      $ip = $1 if ($ip eq "local" && /^rejected [HE][HE]LO from .*?(\[.+?\]):/);
       ++$rejected_count_by_ip{$ip};
-      if (
+      if (/SpamAssassin/) {
+        ++$rejected_count_by_reason{"Rejected by SpamAssassin"};
+      }
+      elsif (
         /(listed at [^ ]+)/ ||
         /(Forged IP detected in HELO)/ ||
         /(Invalid domain or IP given in HELO\/EHLO)/ ||