]> git.pld-linux.org Git - packages/amavis-stats.git/blob - amavis-stats-gzip.patch
- fix problems with roteted logs
[packages/amavis-stats.git] / amavis-stats-gzip.patch
1 diff -ur amavis-stats-0.1.10.orig/amavis-stats amavis-stats-0.1.10/amavis-stats
2 --- amavis-stats-0.1.10.orig/amavis-stats       2004-02-08 19:43:59.000000000 +0100
3 +++ amavis-stats-0.1.10/amavis-stats    2004-03-15 15:41:44.000000000 +0100
4 @@ -35,6 +35,7 @@
5  use Fcntl ':flock';
6  use POSIX qw(strftime);
7  use POSIX qw(locale_h);
8 +use Compress::Zlib;
9  
10  
11  # ########################################################################
12 @@ -556,6 +557,59 @@
13  
14  
15  #
16 +#
17 +#
18 +sub parseFilegz {
19 +
20 +    my ($fname, $start) = @_;
21 +    dbg("parseFilegz ($fname, $start)");
22 +
23 +    #
24 +    # Open up the file we need to parse
25 +    #
26 +    my $gz = gzopen ($fname, "rb");
27 +    if (!defined($gz))
28 +    {
29 +       err("Couldn't open logfile $fname"); 
30 +        exit 2; 
31 +    }
32 +
33 +    #
34 +    # Loop each line until the current end of file
35 +    #
36 +    $pos = 0;
37 +    while ($pos < $start) {
38 +       $pos += $gz->gzreadline($line);
39 +    }
40 +    my $lineid = 0;
41 +    my $p = 0;
42 +    do {
43 +       $p = $gz->gzreadline($line);
44 +       $pos += $p;
45 +
46 +       if ($p > 0) {
47 +               $lineid++;
48 +               $lastepoch = $epoch;
49 +
50 +               if ($line =~ /amavis.*?\[\d+\]:/) {
51 +                   classify();
52 +               }
53 +               #
54 +               # Save the current statistics every 1000 lines. This way
55 +               # if the program dies we don't have to start again from the 
56 +               # beginning each time. Also good for monitoring the graphs
57 +               # to see where we are up to.
58 +               #
59 +               if (!($lineid % 1000)) {
60 +                   saveState();;
61 +               }
62 +       }
63 +    } while $p > 0;
64 +    $gz->gzclose();
65 +}
66 +
67 +
68 +#
69  # Find the previous (rotated) log file and parse that according to
70  # our last position
71  #
72 @@ -578,18 +632,63 @@
73  
74      if (-f "$logfile.0") {
75          $rotlogfile = $logfile . ".0";
76 +    } elsif (-f "$logfile.0.gz") {
77 +        $rotlogfile = $logfile . ".0.gz";
78      } elsif (-f "$logfile.1") {
79          $rotlogfile = $logfile . ".1";
80 +    } elsif (-f "$logfile.1.gz") {
81 +        $rotlogfile = $logfile . ".1.gz";
82      } elsif (-f "$logfile.01") {
83          $rotlogfile = $logfile . ".01";
84 +    } elsif (-f "$logfile.01.gz") {
85 +        $rotlogfile = $logfile . ".01.gz";
86      } elsif (-f "$logfile-$today") {
87          $rotlogfile = $logfile . "-$today";
88 +    } elsif (-f "$logfile-$today.gz") {
89 +        $rotlogfile = $logfile . "-$today.gz";
90      } elsif (-f "$logfile-$yesterday") {
91          $rotlogfile = $logfile . "-$yesterday";
92 +    } elsif (-f "$logfile-$yesterday.gz") {
93 +        $rotlogfile = $logfile . "-$yesterday.gz";
94 +    } else {
95 +           $rotlogfile = $logfile;
96 +#          $rotlogfile =~ s/(.*)\/([a-z]*)/$1\/archiv\/$2/g;
97 +           $rotlogfile =~ s/\/var\/log\/(.*)/\/var\/log\/archiv\/$1/g;
98 +           if ($rotlogfile eq $logfile) {
99 +                   $rotlogfile = "archiv/$logfile";
100 +           }
101 +           if (-f "$rotlogfile.0") {
102 +                   $rotlogfile = $rotlogfile . ".0";
103 +           } elsif (-f "$rotlogfile.0.gz") {
104 +                   $rotlogfile = $rotlogfile . ".0.gz";
105 +           } elsif (-f "$rotlogfile.1") {
106 +                   $rotlogfile = $rotlogfile . ".1";
107 +           } elsif (-f "$rotlogfile.1.gz") {
108 +                   $rotlogfile = $rotlogfile . ".1.gz";
109 +           } elsif (-f "$rotlogfile.01") {
110 +                   $rotlogfile = $rotlogfile . ".01";
111 +           } elsif (-f "$rotlogfile.01.gz") {
112 +                   $rotlogfile = $rotlogfile . ".01.gz";
113 +           } elsif (-f "$rotlogfile-$today") {
114 +                   $rotlogfile = $rotlogfile . "-$today";
115 +           } elsif (-f "$rotlogfile-$today.gz") {
116 +                   $rotlogfile = $rotlogfile . "-$today.gz";
117 +           } elsif (-f "$rotlogfile-$yesterday") {
118 +                   $rotlogfile = $rotlogfile . "-$yesterday";
119 +           } elsif (-f "$rotlogfile-$yesterday.gz") {
120 +                   $rotlogfile = $rotlogfile . "-$yesterday.gz";
121 +           }
122 +           if (! -f $rotlogfile) {
123 +                   $rotlogfile = undef;
124 +           }
125      }
126  
127      if (defined($rotlogfile)) {
128 -        parseFile ($rotlogfile, $spos, (stat $rotlogfile)[7]);
129 +       if ( $rotlogfile =~ /\.gz$/ ) {
130 +               parseFilegz ($rotlogfile, $spos);
131 +       } else {
132 +               parseFile ($rotlogfile, $spos, (stat $rotlogfile)[7]);
133 +       }
134      } else {
135          err("Could not open rotated logfile.");
136          err("  Tried extentions .0, .1, .01, -$today, -$yesterday");
137 @@ -703,7 +802,11 @@
138      $spos = 0; # reset to the start of the file
139  }
140  
141 +if ( $logfile =~ /\.gz$/ ) {
142 +parseFilegz ($logfile, $spos);
143 +} else {
144  parseFile ($logfile, $spos, $eof);
145 +}
146  saveState();
147  semunlock();
148  
This page took 0.091633 seconds and 4 git commands to generate.