]> git.pld-linux.org Git - packages/amavis-stats.git/blame - amavis-stats-gzip.patch
- support for gzipped logs and /var/log/archiv subdir
[packages/amavis-stats.git] / amavis-stats-gzip.patch
CommitLineData
044cbf7c
JR
1diff -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-09 19:57:31.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,62 @@
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/;
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+ }
124 }
125
126 if (defined($rotlogfile)) {
127- parseFile ($rotlogfile, $spos, (stat $rotlogfile)[7]);
128+ if ( $rotlogfile =~ /\.gz$/ ) {
129+ parseFilegz ($rotlogfile, $spos);
130+ } else {
131+ parseFile ($rotlogfile, $spos, (stat $rotlogfile)[7]);
132+ }
133 } else {
134 err("Could not open rotated logfile.");
135 err(" Tried extentions .0, .1, .01, -$today, -$yesterday");
136@@ -703,7 +801,11 @@
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.090357 seconds and 4 git commands to generate.