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
|
||||||
|
@ -441,7 +442,7 @@ sub logger ($$;$) {
|
||||||
|
|
||||||
$level = 1 unless defined ($level);
|
$level = 1 unless defined ($level);
|
||||||
return if ($level > $pa_config->{'verbosity'});
|
return if ($level > $pa_config->{'verbosity'});
|
||||||
|
|
||||||
if (!defined($pa_config->{'logfile'})) {
|
if (!defined($pa_config->{'logfile'})) {
|
||||||
print strftime ("%Y-%m-%d %H:%M:%S", localtime()) . " [V". $level ."] " . $message . "\n";
|
print strftime ("%Y-%m-%d %H:%M:%S", localtime()) . " [V". $level ."] " . $message . "\n";
|
||||||
return;
|
return;
|
||||||
|
@ -465,20 +466,33 @@ sub logger ($$;$) {
|
||||||
syslog($security_level, $message);
|
syslog($security_level, $message);
|
||||||
closelog();
|
closelog();
|
||||||
} else {
|
} 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'";
|
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";
|
print FILE strftime ("%Y-%m-%d %H:%M:%S", localtime()) . " " . $pa_config->{'servername'} . $pa_config->{'servermode'} . " [V". $level ."] " . $message . "\n";
|
||||||
close (FILE);
|
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)
|
# limpia_cadena (string) - Purge a string for any forbidden characters (esc, etc)
|
||||||
########################################################################
|
########################################################################
|
||||||
|
|
Loading…
Reference in New Issue