File: exim

package info (click to toggle)
logwatch 5.2.2-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,112 kB
  • ctags: 42
  • sloc: perl: 9,032; sh: 65; makefile: 54
file content (158 lines) | stat: -rwxr-xr-x 4,881 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/perl -w
##########################################################################
# $Id: exim,v 1.9 2003/12/15 18:09:23 kirk Exp $
##########################################################################

########################################################
# This module requires Date::Calc and Tie::IxHash!!
# To install, run this as root:
# root> perl -MCPAN -eshell
# cpan> install Date::Calc
# cpan> install Tie::IxHash
########################################################

########################################################
# This was written and is maintained by:
#    Dariusz Nierada <dnierada@kat.supermedia.pl>
########################################################

# aby hashe wychodzily w tej kolejnosci co wchodza
eval "use Tie::IxHash";
if( $@) {exit 0 };
eval "use Date::Calc qw(Delta_Days)";
if ($@) { exit 0 };
use Time::localtime; # czas dla wyswietlania tylko wczorajszych logow

my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'} || 0;

# procedura sortujaca tak jak ja chce (bo tamta sotrowala po ASCII)
sub wedlug_liczb {
    ($aa) = ($a =~ /^(\d+).+/);
    ($bb) = ($b =~ /^(\d+).+/);
    $aa <=> $bb;
}

# START

tie(%mmsg, Tie::IxHash); # dla normalnego (w kolejnosci wpisywania) wypisywania haszy

# jaki dzis dzien?
$tm = localtime;
($day2, $month2, $year2) = ($tm->mday, $tm->mon, $tm->year);
$month2++; $year2 += 1900;

while (defined($ThisLine = <STDIN>)) {
   chomp($ThisLine);
    # pobierz dzisiejsza date z 2002-03-31 22:13:48 ...
   do {
      #$BadFormat{$ThisLine}++; # don't do that, will just cause headache for some admins
      next;
   } unless ($year1,$month1,$day1) = ($ThisLine =~ /^(\d+)\-(\d+)\-(\d+)\s.+/);
    # a jaka jest roznica czasu?
   $days = Delta_Days( $year1, $month1, $day1, $year2, $month2, $day2);

  if ($days == 1) { # TYLKO Z WCZORAJ
        		#   if ( $ThisLine =~ s/^modprobe: Can\'t locate module (\w+)\s*$/$1/ ) {
   if ( $ThisLine =~ /End queue run\:/ ) {
      $EndQueue++;
   }
   elsif ( $ThisLine =~ /Start queue run\:/ ) {
      $StartQueue++;
   }
   elsif ( $ThisLine =~ /refused relay/ || $ThisLine =~ /rejected RCPT/ ) {
      $Relay++;
      @RelayH = (@RelayH, $ThisLine);
   }
   elsif ( $ThisLine =~ /^\d+\-\d+\-\d+\s\d+\:\d+\:\d+\s\w+\-\w+\-\w+\s/ ) { # inne wiadomosci przesylane przez EXIMA
    ($mdate,$mtime,$mid,$mrest) = ($ThisLine =~ /^(\d+\-\d+\-\d+)\s(\d+\:\d+\:\d+)\s(\w+\-\w+\-\w+)(.+)/);
    $licze++;         # Dodaje taki licznik aby potem przy wypisaniu posortowac po nim, bo wypisywal nie po kolei
    $mmsg{$mid}{$licze.$mrest} = "$mdate $mtime";

   }
   else 
   {
      $OtherList{$ThisLine}++;
   }
 } #end tylko z wczoraj
} #end while

if (%BadFormat) {
   print "\n***** BAD FORMAT (Possible data corruption or Exim bug) *****\n";
   foreach $ThisOne (keys %BadFormat) {
      print "$ThisOne\n";
   }
}

if ($Detail >= 5) {
   # Start Queue
   $StartQueue and print "\nStart queue run: $StartQueue Time(s)\n";
   # End Queue
   $EndQueue and print "End queue run: $EndQueue Time(s)\n";

   # Relaye!
   if (@RelayH) {
      print "\n--- Refused Relays \n";
      print "--- \(eg. spam try\): $Relay  Time(s)\n\n";
   
      foreach $ThisOne (@RelayH) {
         print "$ThisOne\n";
      }
   }
}

# Messages by ID
if (keys %mmsg and ($Detail >= 10)) {
   my $tmsgcount=0;
   my $tmsgrcpts=0;
   print "\n--- Messages history ---\n\n";
   foreach $tmsg (keys %mmsg) {
     my @tmsgkeys = sort {wedlug_liczb} keys %{$mmsg{$tmsg}};
     my $immed_deliv = 1;
     $immed_deliv = 0 unless $tmsgkeys[0] =~ /^\d+ <=/;
     foreach my $key (@tmsgkeys[1..$#tmsgkeys-1]) {
     	$immed_deliv = 0 unless $key =~ /^\d+ [-=]>/;
     }
     $immed_deliv = 0 unless $tmsgkeys[$#tmsgkeys] =~ /^\d+ Completed/;
     my $qttmsgcount = 0;
     my $oldqttmsg = '';
     if (!$immed_deliv) {
      print "\-MsgID: $tmsg\: \n";
      foreach $ttmsg (@tmsgkeys) {
          $qttmsg = $ttmsg;
          $qttmsg =~ s/^\d+//; # wywal licznik na poczatku (te od sortowania)
          $qttmsg =~ s/P\=e*smtp S.+//; # wywal koncowki typu:  P=smtp S=372023 id=
          if ($oldqttmsg eq $qttmsg) {
     	$qttmsgcount++;
          } else {
     	$oldqttmsg = $qttmsg;
     	if ($qttmsgcount > 0) {
     	   print "\tlast message repeated $qttmsgcount times\n";
     	   $qttmsgcount = 0;
     	}
     	print "\t$mmsg{$tmsg}{$ttmsg}$qttmsg\n";
          }
      }
      if ($qttmsgcount > 0) {
         print "\tlast message repeated $qttmsgcount times\n";
      }
     } else {
      $tmsgcount++;
      $tmsgrcpts+=$#tmsgkeys-1;
     }
   }
   print "$tmsgcount messages delivered immediately ";
   print "to $tmsgrcpts total recipients\n";
}

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

exit(0);

# vi: shiftwidth=3 tabstop=3 et