From 1a7c914784d0e53ef25dd93a450805d1cf914e66 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Fri, 21 Sep 2012 09:40:06 +0000 Subject: [PATCH] Fix when syslog not installed git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@18 a5eaa968-4c79-4d68-970d-af6011b5b055 --- connectors/vmware/centreon_esxd | 14 +++++++++++++- connectors/vmware/lib/esxd-common.pm | 4 ++-- connectors/vmware/lib/esxd-syslog.pm | 6 ++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 connectors/vmware/lib/esxd-syslog.pm diff --git a/connectors/vmware/centreon_esxd b/connectors/vmware/centreon_esxd index 95e60f9a8..c186944e0 100644 --- a/connectors/vmware/centreon_esxd +++ b/connectors/vmware/centreon_esxd @@ -3,8 +3,10 @@ BEGIN { $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; + $ENV{ESX_SYSLOGD_LOAD} = 0; eval 'require Unix::Syslog;'; if (!$@) { + $ENV{ESX_SYSLOGD_LOAD} = 1; require Unix::Syslog; Unix::Syslog->import(qw(:subs :macros)); } @@ -22,6 +24,8 @@ use Data::Dumper; use vars qw($libpath $port $service_url $username $password $TIMEOUT_VSPHERE $TIMEOUT $TIMEOUT_KILL $REFRESH_KEEPER_SESSION); use vars qw($LOG $log_mode $log_crit $log_facility); +use vars qw($openlog_option $syslog_err_priority $syslog_info_priority); + use constant { LOG_ESXD_ERROR => 1, LOG_ESXD_INFO => 2 @@ -70,6 +74,14 @@ our $session1; our $counter = 0; our $global_id; +our $openlog_option; +our $syslog_err_priority; +our $syslog_info_priority; + +if ($ENV{ESX_SYSLOGD_LOAD} == 1) { + require $libpath . '/esxd-syslog.pm'; +} + our %ERRORS = ( "OK" => 0, "WARNING" => 1, "CRITICAL" => 2, "UNKNOWN" => 3, "PENDING" => 4); our %MYERRORS = (0 => "OK", 1 => "WARNING", 3 => "CRITICAL", 7 => "UNKNOWN"); our %MYERRORS_MASK = ("CRITICAL" => 3, "WARNING" => 1, "UNKNOWN" => 7, "OK" => 0); @@ -283,7 +295,7 @@ if ($log_mode == 1) { open STDERR, '>&', $centesx_fh; } if ($log_mode == 2) { - openlog $0, LOG_PID, $log_facility; + openlog($0, $openlog_option, $log_facility); } pipe($reader_pipe_one, $writer_pipe_one); diff --git a/connectors/vmware/lib/esxd-common.pm b/connectors/vmware/lib/esxd-common.pm index 8d9a23c0b..8c392c0d4 100644 --- a/connectors/vmware/lib/esxd-common.pm +++ b/connectors/vmware/lib/esxd-common.pm @@ -11,8 +11,8 @@ sub writeLogFile($$) { printf LOG "%04d-%02d-%02d %02d:%02d:%02d - %s", $year+1900, $mon+1, $mday, $hour, $min, $sec, $_[1]; close LOG; } elsif ($log_mode == 2) { - syslog LOG_ERR, $_[1] if ($_[0] == LOG_ESXD_ERROR); - syslog LOG_INFO, $_[1] if ($_[0] == LOG_ESXD_INFO); + syslog($syslog_err_priority, $_[1]) if ($_[0] == LOG_ESXD_ERROR); + syslog($syslog_info_priority, $_[1]) if ($_[0] == LOG_ESXD_INFO); } } diff --git a/connectors/vmware/lib/esxd-syslog.pm b/connectors/vmware/lib/esxd-syslog.pm new file mode 100644 index 000000000..29960b217 --- /dev/null +++ b/connectors/vmware/lib/esxd-syslog.pm @@ -0,0 +1,6 @@ + +$openlog_option = LOG_PID; +$syslog_err_priority = LOG_ERR; +$syslog_info_priority = LOG_INFO; + +1;