Evolution #3958
Gestion de plusieurs VirtualCenter git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@37 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
parent
ccca4470ea
commit
619751031e
|
@ -6,7 +6,7 @@ use IO::Socket;
|
|||
use Getopt::Long;
|
||||
|
||||
my $PROGNAME = $0;
|
||||
my $VERSION = "1.2";
|
||||
my $VERSION = "1.0";
|
||||
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
|
||||
my $socket;
|
||||
|
||||
|
@ -17,6 +17,7 @@ sub print_revision($$);
|
|||
my %OPTION = (
|
||||
"help" => undef, "version" => undef,
|
||||
"esxd-host" => undef, "esxd-port" => 5700,
|
||||
"vsphere" => '',
|
||||
"usage" => undef,
|
||||
"esx-host" => undef,
|
||||
"datastore" => undef,
|
||||
|
@ -32,6 +33,8 @@ GetOptions(
|
|||
"H|centreon-esxd-host=s" => \$OPTION{'esxd-host'},
|
||||
"P|centreon-esxd-port=i" => \$OPTION{'esxd-port'},
|
||||
|
||||
"vsphere=s" => \$OPTION{'vsphere'},
|
||||
|
||||
"u|usage=s" => \$OPTION{'usage'},
|
||||
"e|esx-host=s" => \$OPTION{'esx-host'},
|
||||
"vm=s" => \$OPTION{'vm'},
|
||||
|
@ -68,6 +71,7 @@ sub print_usage () {
|
|||
print " -h (--help) usage help\n";
|
||||
print " -H centreon-esxd Host (required)\n";
|
||||
print " -P centreon-esxd Port (default 5700)\n";
|
||||
print " --vsphere vsphere name (default: none)\n";
|
||||
print " -u (--usage) What to check. The list and args (required)\n";
|
||||
print "\n";
|
||||
print "'healthhost':\n";
|
||||
|
@ -197,7 +201,7 @@ sub maintenancehost_check_arg {
|
|||
}
|
||||
|
||||
sub maintenancehost_get_str {
|
||||
return "maintenancehost|" . $OPTION{'esx-host'};
|
||||
return "maintenancehost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
||||
}
|
||||
|
||||
sub statushost_check_arg {
|
||||
|
@ -210,7 +214,7 @@ sub statushost_check_arg {
|
|||
}
|
||||
|
||||
sub statushost_get_str {
|
||||
return "statushost|" . $OPTION{'esx-host'};
|
||||
return "statushost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
||||
}
|
||||
|
||||
sub healthhost_check_arg {
|
||||
|
@ -223,7 +227,7 @@ sub healthhost_check_arg {
|
|||
}
|
||||
|
||||
sub healthhost_get_str {
|
||||
return "healthhost|" . $OPTION{'esx-host'};
|
||||
return "healthhost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
||||
}
|
||||
|
||||
sub datastoreusage_check_arg {
|
||||
|
@ -242,7 +246,7 @@ sub datastoreusage_check_arg {
|
|||
}
|
||||
|
||||
sub datastoreusage_get_str {
|
||||
return "datastoreusage|" . $OPTION{'datastore'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
return "datastoreusage|" . $OPTION{'vsphere'} . "|" . $OPTION{'datastore'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
sub datastoreio_check_arg {
|
||||
|
@ -261,7 +265,7 @@ sub datastoreio_check_arg {
|
|||
}
|
||||
|
||||
sub datastoreio_get_str {
|
||||
return "datastoreio|" . $OPTION{'datastore'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
return "datastoreio|" . $OPTION{'vsphere'} . "|" . $OPTION{'datastore'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
sub cpuhost_check_arg {
|
||||
|
@ -280,7 +284,7 @@ sub cpuhost_check_arg {
|
|||
}
|
||||
|
||||
sub cpuhost_get_str {
|
||||
return "cpuhost|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
return "cpuhost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
sub datastoreshost_check_arg {
|
||||
|
@ -299,7 +303,7 @@ sub datastoreshost_check_arg {
|
|||
}
|
||||
|
||||
sub datastoreshost_get_str {
|
||||
return "datastoreshost|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
return "datastoreshost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
sub memhost_check_arg {
|
||||
|
@ -318,7 +322,7 @@ sub memhost_check_arg {
|
|||
}
|
||||
|
||||
sub memhost_get_str {
|
||||
return "memhost|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
return "memhost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
sub swaphost_check_arg {
|
||||
|
@ -337,7 +341,7 @@ sub swaphost_check_arg {
|
|||
}
|
||||
|
||||
sub swaphost_get_str {
|
||||
return "swaphost|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
return "swaphost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
sub nethost_check_arg {
|
||||
|
@ -361,7 +365,7 @@ sub nethost_check_arg {
|
|||
}
|
||||
|
||||
sub nethost_get_str {
|
||||
return "nethost|" . $OPTION{'esx-host'} . "|" . $OPTION{'nic'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
return "nethost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'nic'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
sub countvmhost_check_arg {
|
||||
|
@ -380,7 +384,7 @@ sub countvmhost_check_arg {
|
|||
}
|
||||
|
||||
sub countvmhost_get_str {
|
||||
return "countvmhost|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
return "countvmhost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
sub cpuvm_check_arg {
|
||||
|
@ -399,7 +403,7 @@ sub cpuvm_check_arg {
|
|||
}
|
||||
|
||||
sub cpuvm_get_str {
|
||||
return "cpuvm|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
return "cpuvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
sub toolsvm_check_arg {
|
||||
|
@ -412,7 +416,7 @@ sub toolsvm_check_arg {
|
|||
}
|
||||
|
||||
sub toolsvm_get_str {
|
||||
return "toolsvm|" . $OPTION{'vm'};
|
||||
return "toolsvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'};
|
||||
}
|
||||
|
||||
sub snapshotvm_check_arg {
|
||||
|
@ -438,7 +442,7 @@ sub snapshotvm_check_arg {
|
|||
}
|
||||
|
||||
sub snapshotvm_get_str {
|
||||
return "snapshotvm|" . $OPTION{'vm'} . "|" . $OPTION{'older'} . "|" . $OPTION{'warn'} . "|" . $OPTION{'crit'};
|
||||
return "snapshotvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'older'} . "|" . $OPTION{'warn'} . "|" . $OPTION{'crit'};
|
||||
}
|
||||
|
||||
sub datastoresvm_check_arg {
|
||||
|
@ -457,7 +461,7 @@ sub datastoresvm_check_arg {
|
|||
}
|
||||
|
||||
sub datastoresvm_get_str {
|
||||
return "datastoresvm|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
return "datastoresvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
sub memvm_check_arg {
|
||||
|
@ -476,7 +480,7 @@ sub memvm_check_arg {
|
|||
}
|
||||
|
||||
sub memvm_get_str {
|
||||
return "memvm|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
return "memvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
|
||||
|
@ -485,7 +489,7 @@ sub listhost_check_arg {
|
|||
}
|
||||
|
||||
sub listhost_get_str {
|
||||
return "listhost";
|
||||
return "listhost|" . $OPTION{'vsphere'};
|
||||
}
|
||||
|
||||
sub listdatastore_check_arg {
|
||||
|
@ -493,7 +497,7 @@ sub listdatastore_check_arg {
|
|||
}
|
||||
|
||||
sub listdatastore_get_str {
|
||||
return "listdatastore";
|
||||
return "listdatastore|" . $OPTION{'vsphere'};
|
||||
}
|
||||
|
||||
sub listnichost_check_arg {
|
||||
|
@ -506,7 +510,7 @@ sub listnichost_check_arg {
|
|||
}
|
||||
|
||||
sub listnichost_get_str {
|
||||
return "listnichost|" . $OPTION{'esx-host'};
|
||||
return "listnichost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
||||
}
|
||||
|
||||
sub getmap_check_arg {
|
||||
|
@ -517,7 +521,7 @@ sub getmap_check_arg {
|
|||
}
|
||||
|
||||
sub getmap_get_str {
|
||||
return "getmap|" . $OPTION{'esx-host'};
|
||||
return "getmap|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
||||
}
|
||||
|
||||
#################
|
||||
|
@ -561,11 +565,11 @@ if ($status_return == -1) {
|
|||
}
|
||||
exit $status_return;
|
||||
|
||||
#print $remote "healthhost|srvi-esx-dev-1.merethis.net\n";
|
||||
#print $remote "datastores|LUN-VMFS-QGARNIER|80|90\n";
|
||||
#print $remote "maintenancehost|srvi-esx-dev-1.merethis.net\n";
|
||||
#print $remote "statushost|srvi-esx-dev-1.merethis.net\n";
|
||||
#print $remote "cpuhost|srvi-esx-dev-1.merethis.net|60\n";
|
||||
#print $remote "nethost|srvi-esx-dev-1.merethis.net|vmnic1|60\n";
|
||||
#print $remote "memhost|srvi-esx-dev-1.merethis.net|80\n";
|
||||
#print $remote "swaphost|srvi-esx-dev-1.merethis.net|80\n";
|
||||
#print $remote "healthhost||srvi-esx-dev-1.merethis.net\n";
|
||||
#print $remote "datastores||LUN-VMFS-QGARNIER|80|90\n";
|
||||
#print $remote "maintenancehost||srvi-esx-dev-1.merethis.net\n";
|
||||
#print $remote "statushost||srvi-esx-dev-1.merethis.net\n";
|
||||
#print $remote "cpuhost||srvi-esx-dev-1.merethis.net|60\n";
|
||||
#print $remote "nethost||srvi-esx-dev-1.merethis.net|vmnic1|60\n";
|
||||
#print $remote "memhost||srvi-esx-dev-1.merethis.net|80\n";
|
||||
#print $remote "swaphost||srvi-esx-dev-1.merethis.net|80\n";
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
|
||||
BEGIN {
|
||||
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
|
||||
$ENV{ESX_SYSLOGD_LOAD} = 0;
|
||||
|
@ -16,6 +17,7 @@ use VMware::VIRuntime;
|
|||
use VMware::VILib;
|
||||
use IO::Socket;
|
||||
use File::Basename;
|
||||
use Net::hostent; # for OOish version of gethostbyaddr
|
||||
use IO::Select;
|
||||
use POSIX ":sys_wait_h";
|
||||
use Data::Dumper;
|
||||
|
@ -27,7 +29,7 @@ if (!$@) {
|
|||
require DateTime::Format::ISO8601;
|
||||
}
|
||||
|
||||
use vars qw($libpath $port $service_url $username $password $TIMEOUT_VSPHERE $TIMEOUT $TIMEOUT_KILL $REFRESH_KEEPER_SESSION);
|
||||
use vars qw($libpath $port %vsphere_server $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);
|
||||
|
||||
|
@ -59,7 +61,6 @@ require $libpath . '/command-statushost.pm';
|
|||
require $libpath . '/command-swaphost.pm';
|
||||
require $libpath . '/command-toolsvm.pm';
|
||||
|
||||
our $VERSION = "1.2";
|
||||
our $session_id;
|
||||
our %sockets = ();
|
||||
our %child_proc;
|
||||
|
@ -77,13 +78,11 @@ our $stop = 0;
|
|||
our $counter_request_id = 0;
|
||||
our $child_vpshere_pid;
|
||||
our $read_select;
|
||||
our $reader_pipe_one;
|
||||
our $writer_pipe_one;
|
||||
our $reader_pipe_two;
|
||||
our $writer_pipe_two;
|
||||
our $session1;
|
||||
our $counter = 0;
|
||||
our $global_id;
|
||||
our $whoaim; # to know which vsphere to connect
|
||||
our %filenos;
|
||||
|
||||
our $openlog_option;
|
||||
our $syslog_err_priority;
|
||||
|
@ -135,13 +134,14 @@ sub REAPER {
|
|||
|
||||
sub verify_child {
|
||||
my $progress = 0;
|
||||
my $handle_writer_pipe = ${$vsphere_server{$whoaim}->{'writer_one'}};
|
||||
|
||||
# Verify process
|
||||
foreach (keys %child_proc) {
|
||||
# Check ctime
|
||||
if (time() - $child_proc{$_}->{'ctime'} > $TIMEOUT) {
|
||||
my $handle = ${$child_proc{$_}->{'reading'}};
|
||||
print $writer_pipe_one "$_|-1|Timeout Process.\n";
|
||||
print $handle_writer_pipe "$_|-1|Timeout Process.\n";
|
||||
kill('INT', $child_proc{$_}->{'pid'});
|
||||
$read_select->remove($handle);
|
||||
close $handle;
|
||||
|
@ -163,8 +163,12 @@ sub verify_child {
|
|||
|
||||
sub vsphere_handler {
|
||||
my $timeout_process;
|
||||
|
||||
my $handle_reader_pipe = ${$vsphere_server{$whoaim}->{'reader_two'}};
|
||||
my $fileno_reader = fileno($handle_reader_pipe);
|
||||
my $handle_writer_pipe = ${$vsphere_server{$whoaim}->{'writer_one'}};
|
||||
$read_select = new IO::Select();
|
||||
$read_select->add($reader_pipe_two);
|
||||
$read_select->add($handle_reader_pipe);
|
||||
while (1) {
|
||||
my $progress = verify_child();
|
||||
|
||||
|
@ -184,7 +188,7 @@ sub vsphere_handler {
|
|||
$session1->logout();
|
||||
};
|
||||
}
|
||||
print $writer_pipe_one "STOPPED\n";
|
||||
print $handle_writer_pipe "STOPPED|$whoaim\n";
|
||||
exit (0);
|
||||
}
|
||||
|
||||
|
@ -199,7 +203,7 @@ sub vsphere_handler {
|
|||
};
|
||||
}
|
||||
if ($vsphere_connected == 0) {
|
||||
if (!connect_vsphere()) {
|
||||
if (!connect_vsphere($vsphere_server{$whoaim}->{'url'}, $vsphere_server{$whoaim}->{'username'}, $vsphere_server{$whoaim}->{'password'})) {
|
||||
writeLogFile(LOG_ESXD_INFO, "Vsphere connection ok\n");
|
||||
writeLogFile(LOG_ESXD_INFO, "Create perf counters cache in progress\n");
|
||||
if (!cache_perf_counters()) {
|
||||
|
@ -223,7 +227,7 @@ sub vsphere_handler {
|
|||
};
|
||||
if ($@) {
|
||||
writeLogFile(LOG_ESXD_ERROR, "$@");
|
||||
writeLogFile(LOG_ESXD_ERROR, "Ask a new connection");
|
||||
writeLogFile(LOG_ESXD_ERROR, "Ask a new connection\n");
|
||||
# Ask a new connection
|
||||
$last_time_check = time();
|
||||
} else {
|
||||
|
@ -244,7 +248,7 @@ sub vsphere_handler {
|
|||
@rh_set = $read_select->can_read(0);
|
||||
}
|
||||
foreach my $rh (@rh_set) {
|
||||
if ($rh == $reader_pipe_two && !$stop) {
|
||||
if (fileno($rh) == $fileno_reader && !$stop) {
|
||||
$data_element = <$rh>;
|
||||
chomp $data_element;
|
||||
if ($data_element =~ /^STOP$/) {
|
||||
|
@ -281,7 +285,7 @@ sub vsphere_handler {
|
|||
close $writer;
|
||||
}
|
||||
} else {
|
||||
print $writer_pipe_one "$id|-1|Vsphere connection error.\n";
|
||||
print $handle_writer_pipe "$id|-1|Vsphere connection error.\n";
|
||||
}
|
||||
} else {
|
||||
# Read pipe
|
||||
|
@ -294,7 +298,7 @@ sub vsphere_handler {
|
|||
$last_time_check = $child_proc{$lid}->{'ctime'};
|
||||
}
|
||||
chomp $output;
|
||||
print $writer_pipe_one "$lid|$output\n";
|
||||
print $handle_writer_pipe "$lid|$output\n";
|
||||
delete $return_child{$child_proc{$lid}->{'pid'}};
|
||||
delete $child_proc{$lid};
|
||||
}
|
||||
|
@ -314,10 +318,6 @@ if ($log_mode == 2) {
|
|||
openlog($0, $openlog_option, $log_facility);
|
||||
}
|
||||
|
||||
pipe($reader_pipe_one, $writer_pipe_one);
|
||||
pipe($reader_pipe_two, $writer_pipe_two);
|
||||
$writer_pipe_one->autoflush(1);
|
||||
$writer_pipe_two->autoflush(1);
|
||||
|
||||
my $server = IO::Socket::INET->new( Proto => "tcp",
|
||||
LocalPort => $port,
|
||||
|
@ -328,32 +328,58 @@ if (!$server) {
|
|||
exit(1);
|
||||
}
|
||||
|
||||
$child_vpshere_pid = fork();
|
||||
if (!$child_vpshere_pid) {
|
||||
close $reader_pipe_one;
|
||||
close $writer_pipe_two;
|
||||
vsphere_handler();
|
||||
exit(0);
|
||||
|
||||
##
|
||||
# Create childs
|
||||
##
|
||||
foreach (keys %vsphere_server) {
|
||||
my ($reader_pipe_one, $writer_pipe_one);
|
||||
my ($reader_pipe_two, $writer_pipe_two);
|
||||
$whoaim = $_;
|
||||
|
||||
pipe($reader_pipe_one, $writer_pipe_one);
|
||||
pipe($reader_pipe_two, $writer_pipe_two);
|
||||
$writer_pipe_one->autoflush(1);
|
||||
$writer_pipe_two->autoflush(1);
|
||||
|
||||
$vsphere_server{$whoaim}->{'reader_one'} = \*$reader_pipe_one;
|
||||
$vsphere_server{$whoaim}->{'writer_one'} = \*$writer_pipe_one;
|
||||
$vsphere_server{$whoaim}->{'reader_two'} = \*$reader_pipe_two;
|
||||
$vsphere_server{$whoaim}->{'writer_two'} = \*$writer_pipe_two;
|
||||
$child_vpshere_pid = fork();
|
||||
if (!$child_vpshere_pid) {
|
||||
close $vsphere_server{$whoaim}->{'reader_one'};
|
||||
close $vsphere_server{$whoaim}->{'writer_two'};
|
||||
vsphere_handler();
|
||||
exit(0);
|
||||
}
|
||||
$vsphere_server{$whoaim}->{'running'} = 1;
|
||||
close $vsphere_server{$whoaim}->{'writer_one'};
|
||||
close $vsphere_server{$whoaim}->{'reader_two'};
|
||||
}
|
||||
close $writer_pipe_one;
|
||||
close $reader_pipe_two;
|
||||
|
||||
$read_select = new IO::Select();
|
||||
$read_select->add($server);
|
||||
$read_select->add($reader_pipe_one);
|
||||
foreach (keys %vsphere_server) {
|
||||
$filenos{fileno(${$vsphere_server{$_}->{'reader_one'}})} = 1;
|
||||
$read_select->add(${$vsphere_server{$_}->{'reader_one'}});
|
||||
}
|
||||
my $socket_fileno = fileno($server);
|
||||
writeLogFile(LOG_ESXD_INFO, "[Server accepting clients]\n");
|
||||
while (1) {
|
||||
|
||||
my @rh_set = $read_select->can_read(30);
|
||||
if ($stop == 1) {
|
||||
writeLogFile(LOG_ESXD_INFO, "Send STOP command to thread.\n");
|
||||
print $writer_pipe_two "STOP\n";
|
||||
foreach (keys %vsphere_server) {
|
||||
my $writer_handle = $vsphere_server{$_}->{'writer_two'};
|
||||
print $writer_handle "STOP\n";
|
||||
}
|
||||
$stop = 2;
|
||||
}
|
||||
foreach my $rh (@rh_set) {
|
||||
if (!$stop && $rh == $server) {
|
||||
my $current_fileno = fileno($rh);
|
||||
if (!$stop && $current_fileno == $socket_fileno) {
|
||||
my $client;
|
||||
|
||||
# Connect to accept
|
||||
$client = $rh->accept();
|
||||
$client->autoflush(1);
|
||||
|
@ -361,16 +387,26 @@ while (1) {
|
|||
$sockets{fileno($client)} = {"obj" => \$client, "ctime" => time(), "counter" => $counter};
|
||||
$read_select->add($client);
|
||||
next;
|
||||
} elsif ($rh == $reader_pipe_one) {
|
||||
} elsif (defined($filenos{$current_fileno})) {
|
||||
# Return to read
|
||||
my $data_element = <$rh>;
|
||||
chomp $data_element;
|
||||
if ($data_element =~ /^STOPPED$/) {
|
||||
writeLogFile(LOG_ESXD_INFO, "Thread has stopped\n");
|
||||
exit(0);
|
||||
if ($data_element =~ /^STOPPED/) {
|
||||
# We have to wait all childs
|
||||
my ($name, $which_one) = split(/\|/, $data_element);
|
||||
writeLogFile(LOG_ESXD_INFO, "Thread vsphere '$which_one' has stopped\n");
|
||||
$vsphere_server{$which_one}->{'running'} = 0;
|
||||
my $to_stop_or_not = 1;
|
||||
foreach (keys %vsphere_server) {
|
||||
$to_stop_or_not = 0 if ($vsphere_server{$_}->{'running'} == 1);
|
||||
}
|
||||
if ($to_stop_or_not == 1) {
|
||||
# We quit
|
||||
writeLogFile(LOG_ESXD_INFO, "Quit main process\n");
|
||||
exit(0);
|
||||
}
|
||||
next;
|
||||
}
|
||||
# Verify responde queue
|
||||
#print "Response queue = $data_element\n";
|
||||
my @results = split(/\|/, $data_element);
|
||||
my ($id, $counter) = split(/\./, $results[0]);
|
||||
if (!defined($sockets{$id}) || $counter != $sockets{$id}->{'counter'}) {
|
||||
|
@ -389,25 +425,35 @@ while (1) {
|
|||
my $line = <$rh>;
|
||||
if (defined($line) && $line ne "") {
|
||||
chomp $line;
|
||||
my ($name, @args) = split /\|/, $line;
|
||||
my ($name, $vsphere_name, @args) = split /\|/, $line;
|
||||
if (!defined($checks_descr{$name})) {
|
||||
$rh->send("3|Unknown method name '$name'\n");
|
||||
delete $sockets{fileno($rh)};
|
||||
delete $sockets{$current_fileno};
|
||||
$read_select->remove($rh);
|
||||
close $rh;
|
||||
next;
|
||||
}
|
||||
if ($checks_descr{$name}->{'arg'}(@args)) {
|
||||
$rh->send("3|Params error '$name'\n");
|
||||
delete $sockets{fileno($rh)};
|
||||
delete $sockets{$current_fileno};
|
||||
$read_select->remove($rh);
|
||||
close $rh;
|
||||
next;
|
||||
}
|
||||
|
||||
print $writer_pipe_two fileno($rh) . "." . $sockets{fileno($rh)}->{'counter'} . "|$line\n";
|
||||
$vsphere_name = 'default' if (!defined($vsphere_name) || $vsphere_name eq '');
|
||||
if (!defined($vsphere_server{$vsphere_name})) {
|
||||
$rh->send("3|Vsphere name unknown\n");
|
||||
delete $sockets{$current_fileno};
|
||||
$read_select->remove($rh);
|
||||
close $rh;
|
||||
next;
|
||||
}
|
||||
|
||||
my $tmp_handle = ${$vsphere_server{$vsphere_name}->{'writer_two'}};
|
||||
print $tmp_handle $current_fileno . "." . $sockets{$current_fileno}->{'counter'} . "|$name|@args\n";
|
||||
} else {
|
||||
delete $sockets{fileno($rh)};
|
||||
delete $sockets{$current_fileno};
|
||||
$rh->send("3|Need arguments\n");
|
||||
$read_select->remove($rh);
|
||||
close $rh;
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
|
||||
our $libpath = '/usr/share/centreon/lib/centreon-esxd';
|
||||
our $port = 5700;
|
||||
our $service_url = "https://XXXX.XXXX.XXX/sdk";
|
||||
our $username = "xxxxx";
|
||||
our $password = 'xxxxx';
|
||||
our %vsphere_server = ('default' => {'url' => 'https://XXXXXX/sdk',
|
||||
'username' => 'XXXXX',
|
||||
'password' => 'XXXXX'},
|
||||
'testvc' => {'url' => 'https://XXXXXX/sdk',
|
||||
'username' => 'XXXXX',
|
||||
'password' => 'XXXXXX'}
|
||||
);
|
||||
our $TIMEOUT_VSPHERE = 60;
|
||||
our $TIMEOUT = 60;
|
||||
our $TIMEOUT_KILL = 30;
|
||||
|
|
|
@ -23,7 +23,7 @@ sub snapshotvm_compute_args {
|
|||
sub snapshotvm_do {
|
||||
my ($lvm, $older, $warn, $crit) = @_;
|
||||
|
||||
if ($older != -1 && $module_date_parse_loaded == 0) {
|
||||
if ($module_date_parse_loaded == 0) {
|
||||
my $status |= $MYERRORS_MASK{'UNKNOWN'};
|
||||
print_response($ERRORS{$MYERRORS{$status}} . "|Need to install DateTime::Format::ISO8601 CPAN Module.\n");
|
||||
return ;
|
||||
|
@ -45,10 +45,10 @@ sub snapshotvm_do {
|
|||
return ;
|
||||
}
|
||||
|
||||
# 2012-09-21T14:16:17.540469Z
|
||||
foreach my $snapshot (@{$$result[0]->{'snapshot.rootSnapshotList'}}) {
|
||||
my $create_time = DateTime::Format::ISO8601->parse_datetime($snapshot->createTime);
|
||||
if ($older != -1 && time() - $create_time->epoch > $older) {
|
||||
# 2012-09-21T14:16:17.540469Z
|
||||
my $create_time = DateTime::Format::ISO8601->parse_datetime($snapshot->createTime);
|
||||
if ($warn == 1) {
|
||||
$output = 'Older snapshot problem (' . $snapshot->createTime . ').';
|
||||
$status |= $MYERRORS_MASK{'WARNING'};
|
||||
|
@ -59,11 +59,11 @@ sub snapshotvm_do {
|
|||
}
|
||||
} elsif ($older == -1) {
|
||||
if ($warn == 1) {
|
||||
$output = 'There is at least one snapshot.';
|
||||
$output = 'There is at least one snapshot (' . $snapshot->createTime . ').';
|
||||
$status |= $MYERRORS_MASK{'WARNING'};
|
||||
}
|
||||
if ($crit == 1) {
|
||||
$output = 'There is at least one snapshot.';
|
||||
$output = 'There is at least one snapshot (' . $snapshot->createTime . ').';
|
||||
$status |= $MYERRORS_MASK{'CRITICAL'};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ sub writeLogFile($$) {
|
|||
}
|
||||
|
||||
sub connect_vsphere {
|
||||
my ($service_url, $username, $password) = @_;
|
||||
writeLogFile(LOG_ESXD_INFO, "Vsphere connection in progress\n");
|
||||
eval {
|
||||
$SIG{ALRM} = sub { die('TIMEOUT'); };
|
||||
|
@ -160,7 +161,7 @@ sub get_entities_host {
|
|||
eval {
|
||||
$entity_views = $session1->find_entity_views(view_type => $view_type, properties => $properties, filter => $filters);
|
||||
};
|
||||
if ($@) {
|
||||
if ($@ =~ /decryption failed or bad record mac/) {
|
||||
writeLogFile(LOG_ESXD_ERROR, "$@");
|
||||
eval {
|
||||
$entity_views = $session1->find_entity_views(view_type => $view_type, properties => $properties, filter => $filters);
|
||||
|
@ -172,6 +173,12 @@ sub get_entities_host {
|
|||
print_response("-1|Error: " . Data::Dumper::Dumper($lerror) . "\n");
|
||||
return undef;
|
||||
}
|
||||
} elsif ($@) {
|
||||
writeLogFile(LOG_ESXD_ERROR, "$@");
|
||||
my $lerror = $@;
|
||||
$lerror =~ s/\n/ /g;
|
||||
print_response("-1|Error: " . $lerror . "\n");
|
||||
return undef;
|
||||
}
|
||||
if (!@$entity_views) {
|
||||
my $status |= $MYERRORS_MASK{'UNKNOWN'};
|
||||
|
|
Loading…
Reference in New Issue