From 045042e2c8bc56479435a75f487f282a1d7b0dc1 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 15 Dec 2021 15:26:27 +0100 Subject: [PATCH 1/9] wip --- .../src/centreon/script/centreon_vmware.pm | 4 +- .../vmware/src/centreon/vmware/cmdlicenses.pm | 59 ++++++++ .../src/centreon/vmware/cmdstoragehost.pm | 134 ++++++++++++++++++ 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 connectors/vmware/src/centreon/vmware/cmdlicenses.pm create mode 100644 connectors/vmware/src/centreon/vmware/cmdstoragehost.pm diff --git a/connectors/vmware/src/centreon/script/centreon_vmware.pm b/connectors/vmware/src/centreon/script/centreon_vmware.pm index 3d35f26ed..70e2a6ed9 100644 --- a/connectors/vmware/src/centreon/script/centreon_vmware.pm +++ b/connectors/vmware/src/centreon/script/centreon_vmware.pm @@ -54,7 +54,7 @@ BEGIN { use base qw(centreon::vmware::script); use vars qw(%centreon_vmware_config); -my $VERSION = '3.2.1'; +my $VERSION = '3.2.2'; my %handlers = (TERM => {}, HUP => {}, CHLD => {}); my @load_modules = ( @@ -74,6 +74,7 @@ my @load_modules = ( 'centreon::vmware::cmddiscovery', 'centreon::vmware::cmdgetmap', 'centreon::vmware::cmdhealthhost', + 'centreon::vmware::cmdlicenses', 'centreon::vmware::cmdlimitvm', 'centreon::vmware::cmdlistclusters', 'centreon::vmware::cmdlistdatacenters', @@ -89,6 +90,7 @@ my @load_modules = ( 'centreon::vmware::cmdstatuscluster', 'centreon::vmware::cmdstatushost', 'centreon::vmware::cmdstatusvm', + 'centreon::vmware::cmdstoragehost', 'centreon::vmware::cmdswaphost', 'centreon::vmware::cmdswapvm', 'centreon::vmware::cmdthinprovisioningvm', diff --git a/connectors/vmware/src/centreon/vmware/cmdlicenses.pm b/connectors/vmware/src/centreon/vmware/cmdlicenses.pm new file mode 100644 index 000000000..acab59985 --- /dev/null +++ b/connectors/vmware/src/centreon/vmware/cmdlicenses.pm @@ -0,0 +1,59 @@ +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package centreon::vmware::cmdlicenses; + +use base qw(centreon::vmware::cmdbase); + +use strict; +use warnings; +use centreon::vmware::common; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(%options); + bless $self, $class; + + $self->{commandName} = 'licenses'; + + return $self; +} + +sub checkArgs { + my ($self, %options) = @_; + + return 0; +} + +sub run { + my $self = shift; + + my $entries = centreon::vmware::common::get_view($self->{connector}, $self->{connector}->{session1}->get_service_content()->licenseManager); + + my $data = {}; + if (defined($entries->licenses)) { + foreach my $license (@{$entries->licenses}) { + use Data::Dumper; + print Data::Dumper::Dumper($license); + } + } + + centreon::vmware::common::set_response(data => $data); +} + +1; diff --git a/connectors/vmware/src/centreon/vmware/cmdstoragehost.pm b/connectors/vmware/src/centreon/vmware/cmdstoragehost.pm new file mode 100644 index 000000000..137441001 --- /dev/null +++ b/connectors/vmware/src/centreon/vmware/cmdstoragehost.pm @@ -0,0 +1,134 @@ +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package centreon::vmware::cmdstoragehost; + +use base qw(centreon::vmware::cmdbase); + +use strict; +use warnings; +use centreon::vmware::common; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(%options); + bless $self, $class; + + $self->{commandName} = 'storagehost'; + + return $self; +} + +sub checkArgs { + my ($self, %options) = @_; + + if (defined($options{arguments}->{esx_hostname}) && $options{arguments}->{esx_hostname} eq "") { + centreon::vmware::common::set_response(code => 100, short_message => "Argument error: esx hostname cannot be null"); + return 1; + } + + return 0; +} + +sub run { + my $self = shift; + + my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter'); + my @properties = ('name', 'runtime.connectionState', 'runtime.inMaintenanceMode', 'configManager.storageSystem'); + my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters); + return if (!defined($result)); + + my %host_names = (); + my @host_array = (); + my $data = {}; + foreach my $entity_view (@$result) { + my $entity_value = $entity_view->{mo_ref}->{value}; + + $data->{$entity_value} = { + name => $entity_view->{name}, + state => $entity_view->{'runtime.connectionState'}->val, + inMaintenanceMode => $entity_view->{'runtime.inMaintenanceMode'}, + }; + + next if (centreon::vmware::common::is_connected(state => $entity_view->{'runtime.connectionState'}->val) == 0); + next if (centreon::vmware::common::is_maintenance(maintenance => $entity_view->{'runtime.inMaintenanceMode'}) == 0); + + if (defined($entity_view->{'configManager.storageSystem'})) { + push @host_array, $entity_view->{'configManager.storageSystem'}; + $host_names{ $entity_view->{'configManager.storageSystem'}->{value} } = $entity_value; + } + } + + if (scalar(@host_array) == 0) { + centreon::vmware::common::set_response(data => $data); + return ; + } + + @properties = ('storageDeviceInfo'); + my $result2 = centreon::vmware::common::get_views($self->{connector}, \@host_array, \@properties); + return if (!defined($result2)); + + foreach my $entity (@$result2) { + my $host_id = $host_names{ $entity->{mo_ref}->{value} }; + + if (defined($entity->storageDeviceInfo->hostBusAdapter)) { + $data->{$host_id}->{adapters} = []; + foreach my $dev (@{$entity->storageDeviceInfo->hostBusAdapter}) { + push @{$data->{$host_id}->{adapters}}, { + name => $dev->device, + status => lc($dev->status) + }; + } + } + + if (defined($entity->storageDeviceInfo->scsiLun)) { + $data->{$host_id}->{luns} = []; + foreach my $scsi (@{$entity->storageDeviceInfo->scsiLun}) { + my $name = $scsi->deviceName; + if (defined($scsi->{displayName})) { + $name = $scsi->displayName; + } elsif (defined($scsi->{canonicalName})) { + $name = $scsi->canonicalName; + } + + push @{$data->{$host_id}->{luns}}, { + name => $name, + operational_states => $scsi->operationalState + }; + } + } + + if (defined($entity->storageDeviceInfo->{multipathInfo})) { + $data->{$host_id}->{paths} = []; + foreach my $lun (@{$entity->storageDeviceInfo->multipathInfo->lun}) { + foreach my $path (@{$lun->path}) { + my $state = $path->pathState; + $state = $path->state if (defined($path->{state})); + push @{$data->{$host_id}->{paths}}, { + name => $path->name, + state => lc($state) + }; + } + } + } + } + + centreon::vmware::common::set_response(data => $data); +} + +1; From 48e8de1efc871439027e7c5724ad5d0eb7bc1c48 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 16 Dec 2021 09:33:59 +0100 Subject: [PATCH 2/9] manage case insensitive --- .../src/centreon/script/centreon_vmware.pm | 71 ++++++++++++------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/connectors/vmware/src/centreon/script/centreon_vmware.pm b/connectors/vmware/src/centreon/script/centreon_vmware.pm index 70e2a6ed9..c1063cb99 100644 --- a/connectors/vmware/src/centreon/script/centreon_vmware.pm +++ b/connectors/vmware/src/centreon/script/centreon_vmware.pm @@ -162,6 +162,11 @@ sub init { $self->{centreon_vmware_config} = {%{$self->{centreon_vmware_default_config}}, %centreon_vmware_config}; + foreach my $name (keys %{$self->{centreon_vmware_config}->{vsphere_server}}) { + my $iname = lc($name); + $self->{centreon_vmware_config}->{vsphere_server}->{$iname} = delete $self->{centreon_vmware_config}->{vsphere_server}->{$name}; + } + ##### Load modules $self->load_module(@load_modules); @@ -354,20 +359,27 @@ sub request_dynamic { my $container = md5_hex($options{result}->{vsphere_address} . $options{result}->{vsphere_username} . $options{result}->{vsphere_password}); # Need to create fork if (!defined($self->{centreon_vmware_config}->{vsphere_server}->{$container})) { - $self->{centreon_vmware_config}->{vsphere_server}->{$container} = { url => 'https://' . $options{result}->{vsphere_address} . '/sdk', - username => $options{result}->{vsphere_username}, - password => $options{result}->{vsphere_password}, - last_request => time() }; - $self->{logger}->writeLogError(sprintf("Dynamic creation: identity = %s [address: %s] [username: %s] [password: %s]", - $container, $options{result}->{vsphere_address}, $options{result}->{vsphere_username}, $options{result}->{vsphere_password})); + $self->{centreon_vmware_config}->{vsphere_server}->{$container} = { + url => 'https://' . $options{result}->{vsphere_address} . '/sdk', + username => $options{result}->{vsphere_username}, + password => $options{result}->{vsphere_password}, + last_request => time() + }; + $self->{logger}->writeLogError( + sprintf( + "Dynamic creation: identity = %s [address: %s] [username: %s] [password: %s]", + $container, $options{result}->{vsphere_address}, $options{result}->{vsphere_username}, $options{result}->{vsphere_password} + ) + ); $centreon_vmware->create_vsphere_child(vsphere_name => $container, dynamic => 1); } - return if ($self->waiting_ready(container => $container, manager => $options{manager}, - identity => $options{identity}) == 0); - + return if ($self->waiting_ready( + container => $container, manager => $options{manager}, + identity => $options{identity}) == 0); + $self->{centreon_vmware_config}->{vsphere_server}->{$container}->{last_request} = time(); - + my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE; my $msg = zmq_msg_init_data("server-" . $container); zmq_msg_send($msg, $frontend, $flag); @@ -395,36 +407,39 @@ sub request { centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity}); return ; } - if (!defined($self->{modules_registry}->{$result->{command}})) { + if (!defined($self->{modules_registry}->{ $result->{command} })) { centreon::vmware::common::set_response(code => 1, short_message => "Unknown method name '$result->{command}'"); centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity}); return ; } - if ($self->{modules_registry}->{$result->{command}}->checkArgs(manager => $options{manager}, - arguments => $result)) { + if ($self->{modules_registry}->{ $result->{command} }->checkArgs( + manager => $options{manager}, + arguments => $result)) { centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity}); return ; } - + # Mode dynamic if (defined($result->{vsphere_address}) && $result->{vsphere_address} ne '') { $self->request_dynamic(result => $result, %options); return ; } - - if (!defined($self->{centreon_vmware_config}->{vsphere_server}->{$result->{container}})) { + + $result->{container} = lc($result->{container}); + if (!defined($self->{centreon_vmware_config}->{vsphere_server}->{ $result->{container} })) { centreon::vmware::common::set_response(code => 1, short_message => "Unknown container name '$result->{container}'"); centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, identity => $options{identity}); return ; } - return if ($self->waiting_ready(container => $result->{container}, manager => $options{manager}, - identity => $options{identity}) == 0); - - $self->{counter_stats}->{$result->{container}}++; + return if ($self->waiting_ready( + container => $result->{container}, manager => $options{manager}, + identity => $options{identity}) == 0); + $self->{counter_stats}->{ $result->{container} }++; + my $flag = ZMQ_NOBLOCK | ZMQ_SNDMORE; - my $msg = zmq_msg_init_data("server-" . $result->{container}); + my $msg = zmq_msg_init_data('server-' . $result->{container}); zmq_msg_send($msg, $frontend, $flag); zmq_msg_close($msg); $msg = zmq_msg_init_data('REQCLIENT ' . $options{data}); @@ -447,9 +462,11 @@ sub repserver { $result->{identity} =~ /^client-(.*)$/; my $identity = 'client-' . pack('H*', $1); - - centreon::vmware::common::response(token => 'RESPSERVER', endpoint => $frontend, - identity => $identity, force_response => $options{data}); + + centreon::vmware::common::response( + token => 'RESPSERVER', endpoint => $frontend, + identity => $identity, force_response => $options{data} + ); } sub router_event { @@ -459,12 +476,12 @@ sub router_event { zmq_msg_recv($msg, $frontend, ZMQ_DONTWAIT); my $identity = zmq_msg_data($msg); zmq_msg_close($msg); - + $msg = zmq_msg_init(); zmq_msg_recv($msg, $frontend, ZMQ_DONTWAIT); my $data = zmq_msg_data($msg); zmq_msg_close($msg); - + centreon::vmware::common::init_response(); if ($centreon_vmware->{stop} != 0) { # We quit so we say we're leaving ;) @@ -518,7 +535,7 @@ sub create_vsphere_child { modules_registry => $self->{modules_registry}, config => $self->{centreon_vmware_config}, logger => $self->{logger}, - vsan_enabled => $self->{vsan_enabled}, + vsan_enabled => $self->{vsan_enabled} ); $connector->run(); exit(0); From 819835640d25eb931efbe1932921bfb76802c592 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 16 Dec 2021 10:55:40 +0100 Subject: [PATCH 3/9] wip --- .../src/centreon/script/centreon_vmware.pm | 1 + .../vmware/src/centreon/vmware/cmdbase.pm | 8 +- .../src/centreon/vmware/cmdcpucluster.pm | 98 +++++++++++++++++++ .../vmware/src/centreon/vmware/cmdcpuhost.pm | 27 +++-- .../src/centreon/vmware/cmddatastoreusage.pm | 4 + .../vmware/src/centreon/vmware/common.pm | 1 + 6 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 connectors/vmware/src/centreon/vmware/cmdcpucluster.pm diff --git a/connectors/vmware/src/centreon/script/centreon_vmware.pm b/connectors/vmware/src/centreon/script/centreon_vmware.pm index c1063cb99..15a1599c5 100644 --- a/connectors/vmware/src/centreon/script/centreon_vmware.pm +++ b/connectors/vmware/src/centreon/script/centreon_vmware.pm @@ -61,6 +61,7 @@ my @load_modules = ( 'centreon::vmware::cmdalarmdatacenter', 'centreon::vmware::cmdalarmhost', 'centreon::vmware::cmdcountvmhost', + 'centreon::vmware::cmdcpucluster', 'centreon::vmware::cmdcpuhost', 'centreon::vmware::cmdcpuvm', 'centreon::vmware::cmddatastorecountvm', diff --git a/connectors/vmware/src/centreon/vmware/cmdbase.pm b/connectors/vmware/src/centreon/vmware/cmdbase.pm index 9cbf1659e..5aea8144e 100644 --- a/connectors/vmware/src/centreon/vmware/cmdbase.pm +++ b/connectors/vmware/src/centreon/vmware/cmdbase.pm @@ -31,7 +31,7 @@ sub new { $self->{logger} = $options{logger}; $self->{global_case_insensitive} = defined($options{case_insensitive}) ? $options{case_insensitive} : 0; - + return $self; } @@ -55,7 +55,7 @@ sub class_handle_ALRM { sub handle_ALRM { my $self = shift; - + $self->{logger}->writeLogError('Child process autokill!!'); exit(0); } @@ -80,12 +80,12 @@ sub set_connector { sub initArgs { my ($self, %options) = @_; - + foreach (keys %{$options{arguments}}) { $self->{$_} = $options{arguments}->{$_}; } centreon::vmware::common::init_response(identity => $options{arguments}->{identity}); - + if ($self->{global_case_insensitive} == 0 && defined($self->{case_insensitive})) { $self->{global_case_insensitive} = 1; } diff --git a/connectors/vmware/src/centreon/vmware/cmdcpucluster.pm b/connectors/vmware/src/centreon/vmware/cmdcpucluster.pm new file mode 100644 index 000000000..05f4e5742 --- /dev/null +++ b/connectors/vmware/src/centreon/vmware/cmdcpucluster.pm @@ -0,0 +1,98 @@ +# Copyright 2015 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package centreon::vmware::cmdcpucluster; + +use base qw(centreon::vmware::cmdbase); + +use strict; +use warnings; +use centreon::vmware::common; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(%options); + bless $self, $class; + + $self->{commandName} = 'cpucluster'; + + return $self; +} + +sub checkArgs { + my ($self, %options) = @_; + + if (defined($options{arguments}->{cluster_name}) && $options{arguments}->{cluster_name} eq '') { + centreon::vmware::common::set_response(code => 100, short_message => 'Argument error: cluster name cannot be null'); + return 1; + } + + return 0; +} + +sub run { + my $self = shift; + + if (!($self->{connector}->{perfcounter_speriod} > 0)) { + centreon::vmware::common::set_response(code => -1, short_message => "Can't retrieve perf counters"); + return ; + } + + my $filters = $self->build_filter(label => 'name', search_option => 'cluster_name', is_regexp => 'filter'); + my @properties = ('name'); + my $views = centreon::vmware::common::search_entities(command => $self, view_type => 'ClusterComputeResource', properties => \@properties, filter => $filters); + return if (!defined($views)); + + my @instances = ('*'); + my $values = centreon::vmware::common::generic_performance_values_historic( + $self->{connector}, + $views, + [ + { label => 'cpu.usage.average', 'instances' => \@instances}, + { label => 'cpu.usagemhz.average', 'instances' => \@instances} + ], + $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, + time_shift => $self->{time_shift}, + skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1 + ); + return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); + + my $interval_min = centreon::vmware::common::get_interval_min( + speriod => $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, + time_shift => $self->{time_shift} + ); + + my $data = {}; + foreach my $view (@$views) { + my $entity_value = $view->{mo_ref}->{value}; + $data->{$entity_value} = { name => $view->{name} }; + + my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"} * 0.01)); + my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"})); + + $data->{$entity_value}->{'interval_min'} = $interval_min; + $data->{$entity_value}->{'cpu.usage.average'} = $total_cpu_average; + $data->{$entity_value}->{'cpu.usagemhz.average'} = $total_cpu_mhz_average; + } + + centreon::vmware::common::set_response(data => $data); +} + +1; diff --git a/connectors/vmware/src/centreon/vmware/cmdcpuhost.pm b/connectors/vmware/src/centreon/vmware/cmdcpuhost.pm index 31c60739f..508289e34 100644 --- a/connectors/vmware/src/centreon/vmware/cmdcpuhost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdcpuhost.pm @@ -59,18 +59,25 @@ sub run { return if (!defined($result)); my @instances = ('*'); - my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector}, - $result, - [{'label' => 'cpu.usage.average', 'instances' => \@instances}, - {'label' => 'cpu.usagemhz.average', 'instances' => \@instances}], - $self->{connector}->{perfcounter_speriod}, - sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, - skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); + my $values = centreon::vmware::common::generic_performance_values_historic( + $self->{connector}, + $result, + [ + { label => 'cpu.usage.average', 'instances' => \@instances}, + { label => 'cpu.usagemhz.average', 'instances' => \@instances} + ], + $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, + time_shift => $self->{time_shift}, + skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1 + ); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); - my $interval_min = centreon::vmware::common::get_interval_min(speriod => $self->{connector}->{perfcounter_speriod}, - sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}); - + my $interval_min = centreon::vmware::common::get_interval_min( + speriod => $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift} + ); + my $data = {}; foreach my $entity_view (@$result) { my $entity_value = $entity_view->{mo_ref}->{value}; diff --git a/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm b/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm index 6faf56d62..1c38e06f0 100644 --- a/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm +++ b/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm @@ -88,6 +88,10 @@ sub run { next if (centreon::vmware::common::is_accessible(accessible => $entity_view->summary->accessible) == 0); + if (defined($self->{refresh})) { + $entity_view->RefreshDatastore(); + } + # capacity 0... if ($entity_view->summary->capacity <= 0) { $data->{$entity_value}->{size} = 0; diff --git a/connectors/vmware/src/centreon/vmware/common.pm b/connectors/vmware/src/centreon/vmware/common.pm index 0773e1d87..f67468962 100644 --- a/connectors/vmware/src/centreon/vmware/common.pm +++ b/connectors/vmware/src/centreon/vmware/common.pm @@ -486,6 +486,7 @@ sub cache_perf_counters { $obj_vmware->{perfcounter_speriod} = 20; } }; + if ($@) { $obj_vmware->{logger}->writeLogError("'" . $obj_vmware->{whoaim} . "' $@"); return 1; From b699e5e064aab1da832aabf574f1821327675e07 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 16 Dec 2021 11:37:29 +0100 Subject: [PATCH 4/9] wip --- connectors/vmware/src/centreon/vmware/common.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/connectors/vmware/src/centreon/vmware/common.pm b/connectors/vmware/src/centreon/vmware/common.pm index f67468962..c26195743 100644 --- a/connectors/vmware/src/centreon/vmware/common.pm +++ b/connectors/vmware/src/centreon/vmware/common.pm @@ -553,7 +553,13 @@ sub search_entities { } return $results; } else { - my ($status, $views) = find_entity_views(connector => $options{command}->{connector}, view_type => $options{view_type}, properties => $options{properties}, filter => $options{filter}); + my ($status, $views) = find_entity_views( + connector => $options{command}->{connector}, + view_type => $options{view_type}, + properties => $options{properties}, + filter => $options{filter}, + empty_continue => $options{command}->{empty_continue} + ); return $views; } } @@ -585,6 +591,9 @@ sub find_entity_views { } if (!defined($entity_views) || scalar(@$entity_views) == 0) { my $status = 0; + if (defined($options{empty_continue})) { + return (1, []); + } if (!defined($options{output_message}) || $options{output_message} != 0) { set_response(code => 1, short_message => "Cannot find '$options{view_type}' object"); } From 095a34431a66333430c9cfe3c612b0deac8e1088 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 16 Dec 2021 14:06:48 +0100 Subject: [PATCH 5/9] wip --- connectors/vmware/changelog | 7 +++++++ .../vmware/src/centreon/vmware/cmdhealthhost.pm | 11 +++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/connectors/vmware/changelog b/connectors/vmware/changelog index 5b6843718..dd350aa84 100644 --- a/connectors/vmware/changelog +++ b/connectors/vmware/changelog @@ -1,3 +1,10 @@ +2021-12-XX Quentin Garnier - 3.2.2 + * Enhancement: add 'storage-host' + * Enhancement: add 'cpu-cluster' (issue #90) + * Enhancement: add refresh capability for datastore-usage (issue #96) + * Enhancement: container label in configuration is case-insensitive (issue #83) + * Enhancement: add capability to use empty-continue option (issue #77) + 2020-11-03 Quentin Garnier - 3.2.1 * Fix: daemon cannot start (issue #92) diff --git a/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm b/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm index b47868de1..3b0771232 100644 --- a/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdhealthhost.pm @@ -49,8 +49,10 @@ sub run { my $self = shift; my $filters = $self->build_filter(label => 'name', search_option => 'esx_hostname', is_regexp => 'filter'); - my @properties = ('name', 'runtime.healthSystemRuntime.hardwareStatusInfo', 'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo', - 'runtime.connectionState'); + my @properties = ( + 'name', 'runtime.healthSystemRuntime.hardwareStatusInfo', 'runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo', + 'runtime.connectionState' + ); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'HostSystem', properties => \@properties, filter => $filters); return if (!defined($result)); @@ -95,7 +97,8 @@ sub run { foreach (@$numericSensorInfo) { push @{$data->{$entity_value}->{sensor_info}}, { status => $_->healthState->key, - type => $_->sensorType, name => $_->name, summary => $_->healthState->summary, + type => $_->sensorType, name => $_->name, + summary => $_->healthState->summary, current_reading => $_->currentReading, power10 => $_->unitModifier, unit => $_->baseUnits @@ -103,7 +106,7 @@ sub run { } } } - + centreon::vmware::common::set_response(data => $data); } From 74a7bfef88fab67a9d93ee916bd144f24add95cd Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 17 Dec 2021 15:52:40 +0100 Subject: [PATCH 6/9] wip --- .../src/centreon/vmware/cmdcpucluster.pm | 11 ++++---- .../vmware/src/centreon/vmware/cmdcpuvm.pm | 28 +++++++++++-------- .../src/centreon/vmware/cmddiscovery.pm | 8 ++++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/connectors/vmware/src/centreon/vmware/cmdcpucluster.pm b/connectors/vmware/src/centreon/vmware/cmdcpucluster.pm index 05f4e5742..ed4127e10 100644 --- a/connectors/vmware/src/centreon/vmware/cmdcpucluster.pm +++ b/connectors/vmware/src/centreon/vmware/cmdcpucluster.pm @@ -58,13 +58,12 @@ sub run { my $views = centreon::vmware::common::search_entities(command => $self, view_type => 'ClusterComputeResource', properties => \@properties, filter => $filters); return if (!defined($views)); - my @instances = ('*'); my $values = centreon::vmware::common::generic_performance_values_historic( $self->{connector}, - $views, + $views, [ - { label => 'cpu.usage.average', 'instances' => \@instances}, - { label => 'cpu.usagemhz.average', 'instances' => \@instances} + { label => 'cpu.usage.average', instances => [''] }, + { label => 'cpu.usagemhz.average', instances => [''] } ], $self->{connector}->{perfcounter_speriod}, sampling_period => $self->{sampling_period}, @@ -84,8 +83,8 @@ sub run { my $entity_value = $view->{mo_ref}->{value}; $data->{$entity_value} = { name => $view->{name} }; - my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"} * 0.01)); - my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"})); + my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{ $self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{key} . ':' } * 0.01)); + my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{ $self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{key} . ':' })); $data->{$entity_value}->{'interval_min'} = $interval_min; $data->{$entity_value}->{'cpu.usage.average'} = $total_cpu_average; diff --git a/connectors/vmware/src/centreon/vmware/cmdcpuvm.pm b/connectors/vmware/src/centreon/vmware/cmdcpuvm.pm index cb7ef2d65..a8de65599 100644 --- a/connectors/vmware/src/centreon/vmware/cmdcpuvm.pm +++ b/connectors/vmware/src/centreon/vmware/cmdcpuvm.pm @@ -66,23 +66,29 @@ sub run { return if (!defined($result)); my @instances = ('*'); - my $values = centreon::vmware::common::generic_performance_values_historic($self->{connector}, - $result, - [{'label' => 'cpu.usage.average', 'instances' => \@instances}, - {'label' => 'cpu.usagemhz.average', 'instances' => \@instances}, - {'label' => 'cpu.ready.summation', 'instances' => \@instances}], - $self->{connector}->{perfcounter_speriod}, - sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, - skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); + my $values = centreon::vmware::common::generic_performance_values_historic( + $self->{connector}, + $result, + [ + {'label' => 'cpu.usage.average', 'instances' => \@instances}, + {'label' => 'cpu.usagemhz.average', 'instances' => \@instances}, + {'label' => 'cpu.ready.summation', 'instances' => \@instances} + ], + $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, + skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1 + ); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); my $interval_sec = $self->{connector}->{perfcounter_speriod}; if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') { $interval_sec = $self->{sampling_period}; } - my $interval_min = centreon::vmware::common::get_interval_min(speriod => $self->{connector}->{perfcounter_speriod}, - sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}); - + my $interval_min = centreon::vmware::common::get_interval_min( + speriod => $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift} + ); + my $data = {}; foreach my $entity_view (@$result) { my $entity_value = $entity_view->{mo_ref}->{value}; diff --git a/connectors/vmware/src/centreon/vmware/cmddiscovery.pm b/connectors/vmware/src/centreon/vmware/cmddiscovery.pm index 91d71880d..19ce44e64 100644 --- a/connectors/vmware/src/centreon/vmware/cmddiscovery.pm +++ b/connectors/vmware/src/centreon/vmware/cmddiscovery.pm @@ -112,9 +112,11 @@ sub run { foreach my $cluster (@$clusters) { next if (!$cluster->{'host'}); - my @properties = ('name', 'vm', 'config.virtualNicManagerInfo.netConfig', 'config.product.version', + my @properties = ( + 'name', 'vm', 'config.virtualNicManagerInfo.netConfig', 'config.product.version', 'config.product.productLineId', 'hardware.systemInfo.vendor', 'hardware.systemInfo.model', - 'hardware.systemInfo.uuid', 'runtime.powerState', 'runtime.inMaintenanceMode', 'runtime.connectionState'); + 'hardware.systemInfo.uuid', 'runtime.powerState', 'runtime.inMaintenanceMode', 'runtime.connectionState' + ); my $esxs = centreon::vmware::common::get_views($self->{connector}, \@{$cluster->host}, \@properties); next if (!defined($esxs)); @@ -122,7 +124,7 @@ sub run { foreach my $esx (@$esxs) { my %esx; - $esx{type} = "esx"; + $esx{type} = 'esx'; $esx{name} = $esx->name; $esx{os} = $esx->{'config.product.productLineId'} . ' ' . $esx->{'config.product.version'}; $esx{hardware} = $esx->{'hardware.systemInfo.vendor'} . ' ' . $esx->{'hardware.systemInfo.model'}; From c7f220e86fb7b83a8c1bc8bb7f6544ec8e6316a2 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 21 Dec 2021 11:01:29 +0100 Subject: [PATCH 7/9] wip --- connectors/vmware/src/centreon/vmware/cmdlicenses.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/connectors/vmware/src/centreon/vmware/cmdlicenses.pm b/connectors/vmware/src/centreon/vmware/cmdlicenses.pm index acab59985..5d0c7db14 100644 --- a/connectors/vmware/src/centreon/vmware/cmdlicenses.pm +++ b/connectors/vmware/src/centreon/vmware/cmdlicenses.pm @@ -48,8 +48,16 @@ sub run { my $data = {}; if (defined($entries->licenses)) { foreach my $license (@{$entries->licenses}) { - use Data::Dumper; - print Data::Dumper::Dumper($license); + $data->{ $license->{name} } = { + total => $license->{total}, + used => $license->{used}, + edition => $license->{editionKey} + }; + foreach my $prop (@{$license->{properties}}) { + if ($prop->{key} eq 'expirationMinutes') { + $data->{ $license->{name} }->{expiration_minutes} = $prop->{value}; + } + } } } From da2825eaefc725242ee804f5277917e73cefbfcf Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 21 Dec 2021 11:43:31 +0100 Subject: [PATCH 8/9] wip --- connectors/vmware/changelog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/connectors/vmware/changelog b/connectors/vmware/changelog index dd350aa84..40d5c56eb 100644 --- a/connectors/vmware/changelog +++ b/connectors/vmware/changelog @@ -1,6 +1,7 @@ -2021-12-XX Quentin Garnier - 3.2.2 +2021-12-21 Quentin Garnier - 3.2.2 * Enhancement: add 'storage-host' * Enhancement: add 'cpu-cluster' (issue #90) + * Enhancement: add 'licenses' * Enhancement: add refresh capability for datastore-usage (issue #96) * Enhancement: container label in configuration is case-insensitive (issue #83) * Enhancement: add capability to use empty-continue option (issue #77) From 7921799bdb0305a6e82d598f9c757e296d8ea6b0 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 21 Dec 2021 11:44:16 +0100 Subject: [PATCH 9/9] wip --- connectors/vmware/src/centreon/vmware/common.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/vmware/src/centreon/vmware/common.pm b/connectors/vmware/src/centreon/vmware/common.pm index c26195743..8462aa3ca 100644 --- a/connectors/vmware/src/centreon/vmware/common.pm +++ b/connectors/vmware/src/centreon/vmware/common.pm @@ -45,7 +45,7 @@ sub init_response { my (%options) = @_; $manager_response->{code} = 0; - $manager_response->{vmware_connector_version} = '3.2.1'; + $manager_response->{vmware_connector_version} = '3.2.2'; $manager_response->{short_message} = 'OK'; $manager_response->{extra_message} = ''; $manager_response->{identity} = $options{identity} if (defined($options{identity}));