Apache-Logmonster
view release on metacpan or search on metacpan
lib/Apache/Logmonster.pm view on Meta::CPAN
package Apache::Logmonster;
use strict;
use warnings;
our $VERSION = '5.36';
use Carp;
use Compress::Zlib;
use Cwd;
#use Data::Dumper;
use Date::Parse;
use FileHandle;
use File::Basename;
use File::Copy;
use Regexp::Log;
use lib 'lib';
use Apache::Logmonster::Utility;
use Regexp::Log::Monster;
my ( $util, $err, %fhs, $debug );
sub new {
my $class = shift;
$debug = shift || 0;
my $self = {
conf => undef,
debug => $debug ? 1 : 0,
};
bless( $self, $class );
$self->get_util();
return $self;
};
sub check_awstats_file {
my $self = shift;
my $domain = shift;
my $conf = $self->{'conf'};
my $confdir = $conf->{confdir} || '/etc/awstats';
my $statsdir = $conf->{statsdir} || '/var/db/awstats';
my $adc = "$confdir/awstats.$domain.conf";
return if -f $adc;
$util->file_write( $adc,
lines => [
<<"EO_AWSTATS_VHOST"
Include "$confdir/awstats.model.conf"
SiteDomain = $domain
DirData = $statsdir/$domain
HostAliases = $domain localhost 127.0.0.1
EO_AWSTATS_VHOST
],
debug => 0,
);
};
sub check_config {
my $self = shift;
my $conf = $self->{'conf'};
$err = "performing sanity tests";
$self->_progress_begin($err) if $debug;
print "\n\t verbose mode $debug\n" if $debug > 1;
if ( $debug > 1 ) {
print "\t clean mode ";
print $conf->{'clean'} ? "enabled.\n" : "disabled.\n";
}
my $tmpdir = $conf->{tmpdir};
lib/Apache/Logmonster.pm view on Meta::CPAN
);
}
else {
( $dd, $mm, $yy, $lm, $hh, $mn ) = $util->get_the_date(
bump => $how_far_back,
debug => $debug > 1 ? 1 : 0,
);
}
my $logdir
= $interval eq "hour" ? "$logbase/$yy/$mm/$dd/$hh"
: $interval eq "day" ? "$logbase/$yy/$mm/$dd"
: $interval eq "month" ? "$logbase/$yy/$mm"
: "$logbase";
print "get_log_dir: using $logdir\n" if $debug > 1;
return $logdir;
};
sub get_log_files {
my $self = shift;
my $dir = shift or die "missing dir argument";
my @logs = glob("$dir/*.gz");
my $debug = $self->{debug};
my $REPORT = $self->{report};
# make sure we have logs to process
if ( !$logs[0] or $logs[0] eq '' ) {
$err = "WARNING: No web server log files found!\n";
print $err if $debug;
print $REPORT $err;
return;
}
if ( $debug > 1 ) {
print "found logfiles \n\t" . join( "\n\t", @logs ) . "\n";
};
return @logs;
};
sub get_config {
my ($self, $file, $config) = @_;
if ( $config && ref $config eq 'HASH' ) {
$self->{conf} = $config;
return $config;
}
return $self->{conf} if (defined $self->{conf} && ref $self->{conf});
$self->{conf} = $util->parse_config( $file || 'logmonster.conf' );
return $self->{conf};
};
sub get_util {
my $self = shift;
return $util if ref $util;
use lib 'lib';
require Apache::Logmonster::Utility;
$self->{util} = $util = Apache::Logmonster::Utility->new( debug => $self->{debug} );
return $util;
};
sub report_hits {
my $self = shift;
my $logdir = shift;
my $debug = $self->{'debug'};
$self->{'debug'} = 0; # hush get_log_dir
$logdir ||= $self->get_log_dir();
my $vhost_count_summary = $logdir . "/HitsPerVhost.txt";
# fail if $vhost_count_summary is not present
unless ( $vhost_count_summary
&& -e $vhost_count_summary
&& -f $vhost_count_summary )
{
print
"report_hits: ERROR: hit summary file is missing. It should have"
. " been at: $vhost_count_summary. Report FAILURE.\n";
return;
}
print "report_hits: reporting summary from file $vhost_count_summary\n"
if $debug;
my @lines = $util->file_read( $vhost_count_summary,
debug => $debug,
fatal => 0,
);
my $lines_in_array = @lines;
if ( $lines_in_array > 0 ) {
print join( ':', @lines ) . "\n";
return 1;
}
print "report_hits: no entries found!\n" if $debug;
return;
};
sub report_close {
my $self = shift;
my $fh = shift;
if ($fh) {
close($fh);
return 1;
}
carp "report_close: was not passed a valid filehandle!";
return;
};
sub report_open {
( run in 2.881 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )