2014-09-03 Ramon Novoa <rnovoa@artica.es>

* lib/PandoraFMS/Tools.pm: Added basic support to log to syslog.
This commit is contained in:
Ramon Novoa 2014-09-03 18:28:51 +02:00
parent e4b4a43245
commit 5c2a8134cf
2 changed files with 27 additions and 7 deletions

View File

@ -1,3 +1,7 @@
2014-09-03 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/Tools.pm: Added basic support to log to syslog.
2014-09-03 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/Core.pm: Added dynamic macros for agent custom fields.

View File

@ -25,6 +25,7 @@ use PandoraFMS::Sendmail;
use HTML::Entities;
use Encode;
use Socket qw(inet_ntoa inet_aton);
use Sys::Syslog;
# New in 3.2. Used to sendmail internally, without external scripts
# use Module::Loaded;
@ -418,16 +419,31 @@ sub logger ($$;$) {
return;
}
# Get the log file (can be a regular file or 'syslog')
my $file = $pa_config->{'logfile'};
# Syslog
if ($file eq 'syslog') {
# Set the security level
my $security_level = 'info';
if ($level < 2) {
$security = 'crit';
} elsif ($level < 5) {
$security = 'warn';
}
openlog('pandora_server', 'ndelay', 'daemon');
syslog($security_level, $message);
closelog();
} else {
# Log rotation
rename ($file, $file.'.old') if (-e $file && (stat($file))[7] > $pa_config->{'max_log_size'});
# Log rotation
if (-e $file && (stat($file))[7] > $pa_config->{'max_log_size'}) {
rename ($file, $file.'.old');
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);
}
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);
}
########################################################################