From ef1eec0e5042723c4b585726d30dd80babda8acf Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 14 Apr 2022 09:05:00 +0200 Subject: [PATCH 1/2] enh(discovery) add custom attributes --- .../src/centreon/vmware/cmddiscovery.pm | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/connectors/vmware/src/centreon/vmware/cmddiscovery.pm b/connectors/vmware/src/centreon/vmware/cmddiscovery.pm index 19ce44e64..50200bdb4 100644 --- a/connectors/vmware/src/centreon/vmware/cmddiscovery.pm +++ b/connectors/vmware/src/centreon/vmware/cmddiscovery.pm @@ -77,6 +77,14 @@ sub run { my @disco_data; my $disco_stats; + my $customFields = {}; + my $entries = centreon::vmware::common::get_view($self->{connector}, $self->{connector}->{session1}->get_service_content()->customFieldsManager); + if (defined($entries->{field})) { + foreach (@{$entries->{field}}) { + $customFields->{ $_->{key} } = $_->{name}; + } + } + $disco_stats->{start_time} = time(); my $filters = $self->build_filter(label => 'name', search_option => 'datacenter', is_regexp => 'filter'); @@ -115,7 +123,8 @@ sub run { 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', + 'summary.customValue' ); my $esxs = centreon::vmware::common::get_views($self->{connector}, \@{$cluster->host}, \@properties); @@ -124,6 +133,12 @@ sub run { foreach my $esx (@$esxs) { my %esx; + my $customValuesEsx = []; + if (defined($esx->{'summary.customValue'})) { + foreach (@{$esx->{'summary.customValue'}}) { + push @$customValuesEsx, { key => $customFields->{ $_->{key}}, value => $_->{value}}; + } + } $esx{type} = 'esx'; $esx{name} = $esx->name; $esx{os} = $esx->{'config.product.productLineId'} . ' ' . $esx->{'config.product.version'}; @@ -133,6 +148,7 @@ sub run { $esx{maintenance} = $esx->{'runtime.inMaintenanceMode'}; $esx{datacenter} = $datacenter->name; $esx{cluster} = $cluster->name; + $esx{custom_attributes} = $customValuesEsx; foreach my $nic (@{$esx->{'config.virtualNicManagerInfo.netConfig'}}) { my %lookup = map { $_->{'key'} => $_->{'spec'}->{'ip'}->{'ipAddress'} } @{$nic->{'candidateVnic'}}; @@ -147,7 +163,8 @@ sub run { @properties = ( 'parent', 'config.name', 'config.annotation', 'config.template', 'config.uuid', 'config.version', - 'config.guestId', 'guest.guestState', 'guest.hostName', 'guest.ipAddress', 'runtime.powerState' + 'config.guestId', 'guest.guestState', 'guest.hostName', 'guest.ipAddress', 'runtime.powerState', + 'summary.customValue' ); my $vms = centreon::vmware::common::get_views($self->{connector}, \@{$esx->vm}, \@properties); @@ -158,6 +175,12 @@ sub run { next if (!defined($vm->{'config.uuid'}) || $vm->{'config.uuid'} eq ''); my $entry; + my $customValuesVm = []; + if (defined($vm->{'summary.customValue'})) { + foreach (@{$vm->{'summary.customValue'}}) { + push @$customValuesVm, { key => $customFields->{ $_->{key}}, value => $_->{value}}; + } + } $entry->{type} = 'vm'; $entry->{name} = $vm->{'config.name'}; $entry->{uuid} = $vm->{'config.uuid'}; @@ -172,6 +195,7 @@ sub run { $entry->{power_state} = $vm->{'runtime.powerState'}->val; $entry->{datacenter} = $datacenter->name; $entry->{cluster} = $cluster->name; + $entry->{custom_attributes} = $customValuesVm; $entry->{esx} = $esx->name; push @disco_data, $entry; From fe788ba890f8c8b2305b4772163aa246acbd4f43 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 14 Apr 2022 09:05:54 +0200 Subject: [PATCH 2/2] enh(discovery) add custom attributes --- connectors/vmware/src/centreon/vmware/cmddiscovery.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connectors/vmware/src/centreon/vmware/cmddiscovery.pm b/connectors/vmware/src/centreon/vmware/cmddiscovery.pm index 50200bdb4..101556f23 100644 --- a/connectors/vmware/src/centreon/vmware/cmddiscovery.pm +++ b/connectors/vmware/src/centreon/vmware/cmddiscovery.pm @@ -136,7 +136,7 @@ sub run { my $customValuesEsx = []; if (defined($esx->{'summary.customValue'})) { foreach (@{$esx->{'summary.customValue'}}) { - push @$customValuesEsx, { key => $customFields->{ $_->{key}}, value => $_->{value}}; + push @$customValuesEsx, { key => $customFields->{ $_->{key} }, value => $_->{value} }; } } $esx{type} = 'esx'; @@ -178,7 +178,7 @@ sub run { my $customValuesVm = []; if (defined($vm->{'summary.customValue'})) { foreach (@{$vm->{'summary.customValue'}}) { - push @$customValuesVm, { key => $customFields->{ $_->{key}}, value => $_->{value}}; + push @$customValuesVm, { key => $customFields->{ $_->{key} }, value => $_->{value} }; } } $entry->{type} = 'vm';