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