Moved log rotation from inside of logger() to pandora_server's periodic tasks,

preventing warnings below at pandora_server.error;

> Use of uninitialized value in numeric gt (>) at /usr/lib/perl5/PandoraFMS/Tools.pm line 415.

MERGED FROM pandora_5.0.
This commit is contained in:
Hirofumi Kosaka 2014-09-29 19:31:24 +09:00
parent be31c5e400
commit 844b5b93a2
2 changed files with 26 additions and 9 deletions

View File

@ -270,6 +270,9 @@ sub pandora_server_tasks ($) {
# Update forced alerts
pandora_exec_forced_alerts ($pa_config, $dbh);
# Rotate Log File
pandora_rotate_logfile($pa_config);
}
# TASKS EXECUTED EVERY 30 SECONDS (Mid latency tasks)

View File

@ -62,6 +62,7 @@ our @EXPORT = qw(
cron_next_execution_date
pandora_daemonize
logger
pandora_rotate_logfile
limpia_cadena
md5check
float_equal
@ -441,7 +442,7 @@ sub logger ($$;$) {
$level = 1 unless defined ($level);
return if ($level > $pa_config->{'verbosity'});
if (!defined($pa_config->{'logfile'})) {
print strftime ("%Y-%m-%d %H:%M:%S", localtime()) . " [V". $level ."] " . $message . "\n";
return;
@ -465,20 +466,33 @@ sub logger ($$;$) {
syslog($security_level, $message);
closelog();
} else {
# Log rotation
if (-e $file && (stat($file))[7] > $pa_config->{'max_log_size'}) {
foreach my $i (reverse 1..$pa_config->{'max_log_generation'}) {
rename ($file . "." . ($i - 1), $file . "." . $i);
}
rename ($file, "$file.0");
}
open (FILE, ">> $file") or die "[FATAL] Could not open logfile '$file'";
# Get an exclusive lock on the file (LOCK_EX)
flock (FILE, 2);
print FILE strftime ("%Y-%m-%d %H:%M:%S", localtime()) . " " . $pa_config->{'servername'} . $pa_config->{'servermode'} . " [V". $level ."] " . $message . "\n";
close (FILE);
}
}
########################################################################
# SUB pandora_rotate_log (pa_config)
# Log to file
########################################################################
sub pandora_rotate_logfile ($) {
my ($pa_config) = @_;
my $file = $pa_config->{'logfile'};
# Log File Rotation
if ($file ne 'syslog' && -e $file && (stat($file))[7] > $pa_config->{'max_log_size'}) {
foreach my $i (reverse 1..$pa_config->{'max_log_generation'}) {
rename ($file . "." . ($i - 1), $file . "." . $i);
}
rename ($file, "$file.0");
}
}
########################################################################
# limpia_cadena (string) - Purge a string for any forbidden characters (esc, etc)
########################################################################