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:
parent
be31c5e400
commit
844b5b93a2
|
@ -270,6 +270,9 @@ sub pandora_server_tasks ($) {
|
||||||
|
|
||||||
# Update forced alerts
|
# Update forced alerts
|
||||||
pandora_exec_forced_alerts ($pa_config, $dbh);
|
pandora_exec_forced_alerts ($pa_config, $dbh);
|
||||||
|
|
||||||
|
# Rotate Log File
|
||||||
|
pandora_rotate_logfile($pa_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
# TASKS EXECUTED EVERY 30 SECONDS (Mid latency tasks)
|
# TASKS EXECUTED EVERY 30 SECONDS (Mid latency tasks)
|
||||||
|
|
|
@ -62,6 +62,7 @@ our @EXPORT = qw(
|
||||||
cron_next_execution_date
|
cron_next_execution_date
|
||||||
pandora_daemonize
|
pandora_daemonize
|
||||||
logger
|
logger
|
||||||
|
pandora_rotate_logfile
|
||||||
limpia_cadena
|
limpia_cadena
|
||||||
md5check
|
md5check
|
||||||
float_equal
|
float_equal
|
||||||
|
@ -465,17 +466,30 @@ sub logger ($$;$) {
|
||||||
syslog($security_level, $message);
|
syslog($security_level, $message);
|
||||||
closelog();
|
closelog();
|
||||||
} else {
|
} else {
|
||||||
# Log rotation
|
open (FILE, ">> $file") or die "[FATAL] Could not open logfile '$file'";
|
||||||
if (-e $file && (stat($file))[7] > $pa_config->{'max_log_size'}) {
|
# 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'}) {
|
foreach my $i (reverse 1..$pa_config->{'max_log_generation'}) {
|
||||||
rename ($file . "." . ($i - 1), $file . "." . $i);
|
rename ($file . "." . ($i - 1), $file . "." . $i);
|
||||||
}
|
}
|
||||||
rename ($file, "$file.0");
|
rename ($file, "$file.0");
|
||||||
}
|
|
||||||
|
|
||||||
open (FILE, ">> $file") or die "[FATAL] Could not open logfile '$file'";
|
|
||||||
print FILE strftime ("%Y-%m-%d %H:%M:%S", localtime()) . " " . $pa_config->{'servername'} . $pa_config->{'servermode'} . " [V". $level ."] " . $message . "\n";
|
|
||||||
close (FILE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue