Apache-Logmonster
view release on metacpan or search on metacpan
lib/Apache/Logmonster.pm view on Meta::CPAN
$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};
print "\t temporary working directory is $tmpdir.\n" if $debug > 1;
if ( ! -d $tmpdir ) {
print "\t temp dir does not existing, creating..." if $debug > 1;
if ( !mkdir $tmpdir, oct('0755') ) {
die "FATAL: The directory $tmpdir does not exist and I could not "
. "create it. Edit logmonster.conf or create it.\n";
}
print "done.\n" if $debug > 1;
# this will fail unless we're root, but that should not matter much
print "\t setting permissions on temp dir..." if $debug > 1;
$util->chown( $tmpdir,
uid => $conf->{'log_user'} || 'www',
gid => $conf->{'log_group'} || 'www',
debug => $debug > 1 ? 1 : 0,
fatal => 0,
);
print "done.\n" if $debug > 1;
}
if ( !-w $tmpdir || !-r $tmpdir ) {
croak "FATAL: \$tmpdir ($tmpdir) must be read and writable!";
}
if ( $conf->{'clean'} ) {
if ( !$util->clean_tmp_dir( $tmpdir, debug => 1, fatal=>0 ) ) {
croak "\nfailed to clean out $tmpdir";
}
}
die "\nFATAL: you must edit logmonster.conf and set default_vhost!\n"
if ! defined $conf->{'default_vhost'};
if ( $conf->{'time_offset'} ) {
my ( $dd, $mm, $yy, $lm, $hh, $mn ) = $util->get_the_date( debug=>0 );
my $interval = $self->{rotation_interval} || 'day';
my $bump = $conf->{time_offset};
my $logbase = $conf->{logbase};
my $how_far_back = $interval eq "hour" ? .04 # back 1 hour
: $interval eq "month" ? $dd + 1 # last month
: 1; # 1 day
( $dd, $mm, $yy, $lm, $hh, $mn )
= $util->get_the_date( bump => $bump + $how_far_back, debug => 0 );
die "OK then, try again.\n"
if ! $util->yes_or_no(
"\nDoes the date $yy/$mm/$dd look correct? ");
}
$self->_progress_end('passed') if $debug == 1;
return 1;
};
sub compress_log_file {
my $self = shift;
my $host = shift;
my $logfile = shift;
my $debug = $self->{'debug'};
unless ( $host && $logfile ) {
croak "compress_log_file: called incorrectly!";
}
my $REPORT = $self->{'report'};
if ( $host eq "localhost" ) {
my $gzip = $util->find_bin( 'gzip', debug => 0 );
if ( !-e $logfile ) {
print $REPORT "compress_log_file: $logfile does not exist!\n";
if ( -e "$logfile.gz" ) {
print $REPORT " already compressed as $logfile.gz!\n";
return 1;
}
return;
}
my $cmd = "$gzip $logfile";
$self->_progress("gzipping localhost:$logfile") if $debug;
print $REPORT "syscmd: $cmd\n";
my $r = $util->syscmd( $cmd, debug => 0 );
print $REPORT "syscmd: error result: $r\n" if ( $r != 0 );
return 1;
}
( run in 0.577 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )