mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 16:55:05 +02:00
2014-09-03 Ramon Novoa <rnovoa@artica.es>
* pandora_agent: Added basic support to log to syslog.
This commit is contained in:
parent
aa52dfdadc
commit
4e43a20909
@ -1,3 +1,7 @@
|
|||||||
|
2014-09-03 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
|
* pandora_agent: Added basic support to log to syslog.
|
||||||
|
|
||||||
2014-09-03 Ramon Novoa <rnovoa@artica.es>
|
2014-09-03 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
* pandora_agent: Added support for global macros.
|
* pandora_agent: Added support for global macros.
|
||||||
|
@ -29,7 +29,7 @@ use Sys::Hostname;
|
|||||||
use File::Basename;
|
use File::Basename;
|
||||||
use File::Copy;
|
use File::Copy;
|
||||||
use IO::Socket;
|
use IO::Socket;
|
||||||
|
use Sys::Syslog;
|
||||||
|
|
||||||
# Agent XML data
|
# Agent XML data
|
||||||
my $Xml;
|
my $Xml;
|
||||||
@ -286,13 +286,15 @@ sub start_log (;$) {
|
|||||||
my $quiet = shift;
|
my $quiet = shift;
|
||||||
|
|
||||||
# Get the logfile
|
# Get the logfile
|
||||||
my $log_file_name = read_config ('logfile');
|
$Conf{'logfile'} = read_config ('logfile');
|
||||||
$log_file_name = '/var/log/pandora/pandora_agent.log' unless defined ($log_file_name);
|
$Conf{'logfile'} = '/var/log/pandora/pandora_agent.log' unless defined ($Conf{'logfile'});
|
||||||
|
|
||||||
# Open it
|
# Open it
|
||||||
open ($LogFileFH, "> $log_file_name") or error ("Could not open log file '$log_file_name' for writing: $!.");
|
if ($Conf{'logfile'} eq 'syslog') {
|
||||||
if (! defined ($quiet)) {
|
openlog('pandora_agent', 'nowait', 'daemon');
|
||||||
print "Logging to $log_file_name\n";
|
} else {
|
||||||
|
open ($LogFileFH, "> $Conf{'logfile'}") or error ("Could not open log file $Conf{'logfile'} for writing: $!.");
|
||||||
|
print "Logging to $Conf{'logfile'}\n" if (!defined ($quiet));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +302,11 @@ sub start_log (;$) {
|
|||||||
# Close the agent logfile and stop logging.
|
# Close the agent logfile and stop logging.
|
||||||
################################################################################
|
################################################################################
|
||||||
sub stop_log () {
|
sub stop_log () {
|
||||||
close ($LogFileFH);
|
if ($Conf{'logfile'} eq 'syslog') {
|
||||||
|
closelog();
|
||||||
|
} else {
|
||||||
|
close ($LogFileFH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -311,6 +317,8 @@ 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') {
|
||||||
|
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
|
||||||
syswrite ($LogFileFH, "");
|
syswrite ($LogFileFH, "");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user