Merge branch 'ent-11339-hacer-opcional-la-dependencia-perl-syslog-en-el-agente-linux' into 'develop'

Ent 11339 hacer opcional la dependencia perl syslog en el agente linux

See merge request artica/pandorafms!6027
This commit is contained in:
Daniel Rodriguez 2023-06-26 07:59:50 +00:00
commit cb13b47bc9
1 changed files with 15 additions and 10 deletions

View File

@ -1008,9 +1008,17 @@ use Sys::Hostname;
use File::Basename;
use File::Copy;
use IO::Socket;
use Sys::Syslog;
use Time::Local;
eval {
require Sys::Syslog;
Sys::Syslog->import();
};
if ($@) {
print ("[INFO] Could not import Sys::Syslog module\n\n");
}
BEGIN { push @INC, '/usr/lib/perl5'; }
# Agent XML data
@ -1413,7 +1421,7 @@ sub start_log (;$) {
$Conf{'logfile'} = '/var/log/pandora/pandora_agent.log' unless defined ($Conf{'logfile'});
# Open it
if ($Conf{'logfile'} eq 'syslog') {
if ($Conf{'logfile'} eq 'syslog' && eval { Sys::Syslog->can('openlog') }) {
openlog('pandora_agent', 'nowait', 'daemon');
} else {
open ($LogFileFH, "> $Conf{'logfile'}") or error ("Could not open log file $Conf{'logfile'} for writing: $!.");
@ -1425,16 +1433,13 @@ sub start_log (;$) {
# Rotates the agent logfile.
################################################################################
sub rotate_log () {
if ($Conf{'logfile'} eq 'syslog') {
# No action needed
if ($Conf{'logfile'} eq 'syslog' && eval { Sys::Syslog->can('syslog') }) {
# No action needed.
return;
}else {
if ($Conf{'logrotate'} < 0){
$Conf{'logrotate'} = DEFAULT_LOG_ROTATE;
}
if ($Conf{'logfile'} eq 'syslog') {
return;
}
# Rotate file
$LogFileIdx = ($LogFileIdx+1) % $Conf{'logrotate'};
@ -1451,7 +1456,7 @@ sub rotate_log () {
# Close the agent logfile and stop logging.
################################################################################
sub stop_log () {
if ($Conf{'logfile'} eq 'syslog') {
if ($Conf{'logfile'} eq 'syslog' && eval { Sys::Syslog->can('closelog') }) {
closelog();
} else {
close ($LogFileFH);
@ -1466,7 +1471,7 @@ sub log_message ($$;$) {
if (defined ($dest)) {
print $dest strftime ('%Y/%m/%d %H:%M:%S', localtime ()) . " - [$source] - $msg\n";
} elsif ($Conf{'logfile'} eq 'syslog') {
} elsif ($Conf{'logfile'} eq 'syslog' && eval { Sys::Syslog->can('syslog') }) {
syslog('info', $msg);
} else {
#Trying to write into log file to test its writable