From b16acdb8d2120a170681a2362d7fc0fff6b30ebe Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 31 Jul 2020 15:51:32 +0200 Subject: [PATCH] add linked hosts to datastore usage --- .../src/centreon/vmware/cmddatastoreusage.pm | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm b/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm index 4fe4598e9..6faf56d62 100644 --- a/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm +++ b/connectors/vmware/src/centreon/vmware/cmddatastoreusage.pm @@ -50,16 +50,42 @@ sub run { my $multiple = 0; my $filters = $self->build_filter(label => 'name', search_option => 'datastore_name', is_regexp => 'filter'); - my @properties = ('summary'); + my @properties = ('summary', 'host'); my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'Datastore', properties => \@properties, filter => $filters); return if (!defined($result)); + my $mapped_host = {}; + my $host_array = []; + foreach my $entity_view (@$result) { + if (defined($entity_view->host)) { + foreach (@{$entity_view->host}) { + if (!defined($mapped_host->{ $_->{key}->{value} } )) { + push @$host_array, $_->{key}; + $mapped_host->{ $_->{key}->{value} } = '-'; + } + } + } + } + + if (scalar(@$host_array) > 0) { + my $result_hosts = centreon::vmware::common::get_views($self->{connector}, $host_array, ['name']); + foreach (@$result_hosts) { + $mapped_host->{ $_->{mo_ref}->{value} } = $_->{name}; + } + } + my $data = {}; foreach my $entity_view (@$result) { my $entity_value = $entity_view->{mo_ref}->{value}; - $data->{$entity_value} = { name => $entity_view->summary->name, accessible => $entity_view->summary->accessible }; + $data->{$entity_value} = { name => $entity_view->summary->name, accessible => $entity_view->summary->accessible, hosts => [] }; + if (defined($entity_view->host)) { + foreach (@{$entity_view->host}) { + push @{$data->{$entity_value}->{hosts}}, $mapped_host->{ $_->{key}->{value} }; + } + } + next if (centreon::vmware::common::is_accessible(accessible => $entity_view->summary->accessible) == 0); # capacity 0...