diff -urN amavis-stats-0.1.22.orig/configure.in amavis-stats-0.1.22/configure.in --- amavis-stats-0.1.22.orig/configure.in 2006-12-04 13:59:29.000000000 +0100 +++ amavis-stats-0.1.22/configure.in 2008-05-12 18:28:44.000000000 +0200 @@ -66,7 +66,6 @@ AC_PATH_PROG(CP, cp, cp) AC_PATH_PROG(CHMOD, chmod, chmod) AC_PATH_PROG(CHOWN, chown, chown) -AC_PATH_PROGS(GZCAT, gzcat, no) AC_PATH_PROGS(NROFF, gnroff nroff) AC_PATH_PROGS(TROFF, groff troff) AC_PROG_LIBTOOL @@ -101,14 +100,6 @@ PERL_VERSION=`$PERL -MConfig -e 'print $Config{version}'` -if test "$GZCAT" = no; then - AC_MSG_ERROR([ - -gzcat not found!!! - -]) -fi - if test "$PATCH" = no; then AC_MSG_ERROR([ diff -urN amavis-stats-0.1.22.orig/doc/Makefile.in amavis-stats-0.1.22/doc/Makefile.in --- amavis-stats-0.1.22.orig/doc/Makefile.in 2006-12-04 14:00:42.000000000 +0100 +++ amavis-stats-0.1.22/doc/Makefile.in 2008-05-12 18:28:44.000000000 +0200 @@ -108,7 +108,6 @@ GCJ = @GCJ@ GCJFLAGS = @GCJFLAGS@ GETENT = @GETENT@ -GZCAT = @GZCAT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LIBTOOL = @LIBTOOL@ LINK_CMD = @LINK_CMD@ diff -urN amavis-stats-0.1.22.orig/etc/Makefile.in amavis-stats-0.1.22/etc/Makefile.in --- amavis-stats-0.1.22.orig/etc/Makefile.in 2006-12-04 14:00:44.000000000 +0100 +++ amavis-stats-0.1.22/etc/Makefile.in 2008-05-12 18:28:44.000000000 +0200 @@ -108,7 +108,6 @@ GCJ = @GCJ@ GCJFLAGS = @GCJFLAGS@ GETENT = @GETENT@ -GZCAT = @GZCAT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LIBTOOL = @LIBTOOL@ LINK_CMD = @LINK_CMD@ diff -urN amavis-stats-0.1.22.orig/Makefile.in amavis-stats-0.1.22/Makefile.in --- amavis-stats-0.1.22.orig/Makefile.in 2006-12-04 13:59:40.000000000 +0100 +++ amavis-stats-0.1.22/Makefile.in 2008-05-12 18:28:44.000000000 +0200 @@ -108,7 +108,6 @@ GCJ = @GCJ@ GCJFLAGS = @GCJFLAGS@ GETENT = @GETENT@ -GZCAT = @GZCAT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LIBTOOL = @LIBTOOL@ LINK_CMD = @LINK_CMD@ diff -urN amavis-stats-0.1.22.orig/php/Makefile.in amavis-stats-0.1.22/php/Makefile.in --- amavis-stats-0.1.22.orig/php/Makefile.in 2006-12-04 14:00:39.000000000 +0100 +++ amavis-stats-0.1.22/php/Makefile.in 2008-05-12 18:28:44.000000000 +0200 @@ -124,7 +124,6 @@ GCJ = @GCJ@ GCJFLAGS = @GCJFLAGS@ GETENT = @GETENT@ -GZCAT = @GZCAT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LIBTOOL = @LIBTOOL@ LINK_CMD = @LINK_CMD@ diff -urN amavis-stats-0.1.22.orig/sbin/amavis-stats.in amavis-stats-0.1.22/sbin/amavis-stats.in --- amavis-stats-0.1.22.orig/sbin/amavis-stats.in 2006-01-21 02:25:01.000000000 +0100 +++ amavis-stats-0.1.22/sbin/amavis-stats.in 2008-05-12 18:36:55.000000000 +0200 @@ -59,6 +59,7 @@ Exporter POSIX Fcntl Errno Carp Time::HiRes Unix::Syslog RRDp RRDs IO::File warnings Time::localtime Time::Local + Compress::Zlib )); } @@ -843,6 +844,7 @@ use Unix::Syslog qw(:macros :subs); use IO::File (); use File::Basename; +use Compress::Zlib; BEGIN { import AmavisStats::Conf qw(:platform $myversion $myhostname $daemon_user); @@ -1596,6 +1598,56 @@ } + sub parseFilegz { + + my ($fname, $start) = @_; + do_log(2, "parseFilegz($fname, $start)"); + + # + # Open up the file we need to parse + # + my $gz; + unless ($gz = gzopen ($fname, "rb")) { + do_log(1, "ERROR : Could not open file $fname: $!"); + } + + # + # Loop each line until the current end of file + # + $pos = 0; + while ($pos < $start) { + $pos += $gz->gzreadline($line); + } + + my $lineid = 0; + my $p = 0; + + do { + $p = $gz->gzreadline($line); + $pos += $p; + + if ($p > 0) { + $lineid++; + $lastepoch = $epoch; + + if ($line =~ /amavis.*?\[\d+\]:/) { + classify(); + } + + # + # Save the current statistics every 1000 lines. This way + # if the program dies we don't have to start again from the + # beginning each time. Also good for monitoring the graphs + # to see where we are up to. + # + if (!($lineid % 1000)) { + saveState();; + } + } + } while $p > 0; + $gz->gzclose(); + } + sub parseRotFile { do_log(5, "DEBUG : parseRotFile()"); my ($scan_logfile, $spos) = @_; @@ -1614,25 +1666,65 @@ my $rotlogfile = undef; - if (! -f "$scan_logfile.0" && -f "$scan_logfile.0.gz" ) { - do_log(2 , "copying $scan_logfile.0.gz -> $scan_logfile.0"); - `gzcat "$scan_logfile.0.gz" > "$scan_logfile.0"`; - } - if (-f "$scan_logfile.0") { $rotlogfile = $scan_logfile . ".0"; + } elsif (-f "$scan_logfile.0.gz") { + $rotlogfile = $scan_logfile . ".0.gz"; } elsif (-f "$scan_logfile.1") { $rotlogfile = $scan_logfile . ".1"; + } elsif (-f "$scan_logfile.1.gz") { + $rotlogfile = $scan_logfile . ".1.gz"; } elsif (-f "$scan_logfile.01") { $rotlogfile = $scan_logfile . ".01"; + } elsif (-f "$scan_logfile.01.gz") { + $rotlogfile = $scan_logfile . ".01.gz"; } elsif (-f "$scan_logfile-$today") { $rotlogfile = $scan_logfile . "-$today"; + } elsif (-f "$scan_logfile-$today.gz") { + $rotlogfile = $scan_logfile . "-$today.gz"; } elsif (-f "$scan_logfile-$yesterday") { $rotlogfile = $scan_logfile . "-$yesterday"; + } elsif (-f "$scan_logfile-$yesterday.gz") { + $rotlogfile = $scan_logfile . "-$yesterday.gz"; + } else { + $rotlogfile = $scan_logfile; + # $rotlogfile =~ s/(.*)\/([a-z]*)/$1\/archiv\/$2/g; + $rotlogfile =~ s/\/var\/log\/(.*)/\/var\/log\/archive\/$1/g; + if ($rotlogfile eq $scan_logfile) { + $rotlogfile = "archiv/$scan_logfile"; + } + if (-f "$rotlogfile.0") { + $rotlogfile = $rotlogfile . ".0"; + } elsif (-f "$rotlogfile.0.gz") { + $rotlogfile = $rotlogfile . ".0.gz"; + } elsif (-f "$rotlogfile.1") { + $rotlogfile = $rotlogfile . ".1"; + } elsif (-f "$rotlogfile.1.gz") { + $rotlogfile = $rotlogfile . ".1.gz"; + } elsif (-f "$rotlogfile.01") { + $rotlogfile = $rotlogfile . ".01"; + } elsif (-f "$rotlogfile.01.gz") { + $rotlogfile = $rotlogfile . ".01.gz"; + } elsif (-f "$rotlogfile-$today") { + $rotlogfile = $rotlogfile . "-$today"; + } elsif (-f "$rotlogfile-$today.gz") { + $rotlogfile = $rotlogfile . "-$today.gz"; + } elsif (-f "$rotlogfile-$yesterday") { + $rotlogfile = $rotlogfile . "-$yesterday"; + } elsif (-f "$rotlogfile-$yesterday.gz") { + $rotlogfile = $rotlogfile . "-$yesterday.gz"; + } + if (! -f $rotlogfile) { + $rotlogfile = undef; + } } if (defined $rotlogfile) { - parseFile ($rotlogfile, $spos, (stat $rotlogfile)[7]); + if ($rotlogfile =~ /\.gz$/) { + parseFilegz ($rotlogfile, $spos); + } else { + parseFile ($rotlogfile, $spos, (stat $rotlogfile)[7]); + } } else { do_log(1, "ERROR : Could not open rotated logfile."); do_log(1, "ERROR : Tried extentions .0.gz, .0, .1, .01, -$today, -$yesterday"); @@ -1803,7 +1895,11 @@ } do_log(5, "DEBUG : $scan_logfile, $spos, $eof"); - parseFile ($scan_logfile, $spos, $eof); + if ($scan_logfile =~ /\.gz$/) { + parseFilegz ($scan_logfile, $spos); + } else { + parseFile ($scan_logfile, $spos, $eof); + } saveState(); do_log(1, sprintf("Finished -> %s", $scan_domains eq '.*' ? 'localhost' : $scan_domains)); diff -urN amavis-stats-0.1.22.orig/sbin/Makefile.in amavis-stats-0.1.22/sbin/Makefile.in --- amavis-stats-0.1.22.orig/sbin/Makefile.in 2006-12-04 14:00:49.000000000 +0100 +++ amavis-stats-0.1.22/sbin/Makefile.in 2008-05-12 18:28:44.000000000 +0200 @@ -108,7 +108,6 @@ GCJ = @GCJ@ GCJFLAGS = @GCJFLAGS@ GETENT = @GETENT@ -GZCAT = @GZCAT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LIBTOOL = @LIBTOOL@ LINK_CMD = @LINK_CMD@ diff -urN amavis-stats-0.1.22.orig/share/Makefile.in amavis-stats-0.1.22/share/Makefile.in --- amavis-stats-0.1.22.orig/share/Makefile.in 2006-12-04 14:00:47.000000000 +0100 +++ amavis-stats-0.1.22/share/Makefile.in 2008-05-12 18:28:44.000000000 +0200 @@ -108,7 +108,6 @@ GCJ = @GCJ@ GCJFLAGS = @GCJFLAGS@ GETENT = @GETENT@ -GZCAT = @GZCAT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LIBTOOL = @LIBTOOL@ LINK_CMD = @LINK_CMD@ diff -urN amavis-stats-0.1.22.orig/startup/Makefile.in amavis-stats-0.1.22/startup/Makefile.in --- amavis-stats-0.1.22.orig/startup/Makefile.in 2006-12-04 14:02:26.000000000 +0100 +++ amavis-stats-0.1.22/startup/Makefile.in 2008-05-12 18:28:44.000000000 +0200 @@ -108,7 +108,6 @@ GCJ = @GCJ@ GCJFLAGS = @GCJFLAGS@ GETENT = @GETENT@ -GZCAT = @GZCAT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LIBTOOL = @LIBTOOL@ LINK_CMD = @LINK_CMD@