mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 01:05:39 +02:00
2014-09-03 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/Tools.pm: Added basic support to log to syslog.
This commit is contained in:
parent
c07e6f14b1
commit
aa52dfdadc
@ -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>
|
2014-09-03 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
* lib/PandoraFMS/Core.pm: Added dynamic macros for agent custom fields.
|
* lib/PandoraFMS/Core.pm: Added dynamic macros for agent custom fields.
|
||||||
|
@ -25,6 +25,7 @@ use PandoraFMS::Sendmail;
|
|||||||
use HTML::Entities;
|
use HTML::Entities;
|
||||||
use Encode;
|
use Encode;
|
||||||
use Socket qw(inet_ntoa inet_aton);
|
use Socket qw(inet_ntoa inet_aton);
|
||||||
|
use Sys::Syslog;
|
||||||
|
|
||||||
# New in 3.2. Used to sendmail internally, without external scripts
|
# New in 3.2. Used to sendmail internally, without external scripts
|
||||||
# use Module::Loaded;
|
# use Module::Loaded;
|
||||||
@ -418,16 +419,31 @@ sub logger ($$;$) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Get the log file (can be a regular file or 'syslog')
|
||||||
my $file = $pa_config->{'logfile'};
|
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
|
open (FILE, ">> $file") or die "[FATAL] Could not open logfile '$file'";
|
||||||
if (-e $file && (stat($file))[7] > $pa_config->{'max_log_size'}) {
|
print FILE strftime ("%Y-%m-%d %H:%M:%S", localtime()) . " " . $pa_config->{'servername'} . $pa_config->{'servermode'} . " [V". $level ."] " . $message . "\n";
|
||||||
rename ($file, $file.'.old');
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user