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