From c9afe47aa9f393e2b8052c74f67023d8a5ee96f9 Mon Sep 17 00:00:00 2001 From: lchrdn <89968908+lchrdn@users.noreply.github.com> Date: Tue, 2 Aug 2022 11:28:20 +0200 Subject: [PATCH] (plugin) cloud::prometheus::plugin - adding discovery mode (#3800) * adding prom discovery mode for targets * adding details to help in disco mode * indent * remove extra blank line * modif regex for ip addr + apply suggestion * adding labels attributes for targets discovery Co-authored-by: Simon Bomm --- .../cloud/prometheus/restapi/mode/discovery.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/centreon-plugins/cloud/prometheus/restapi/mode/discovery.pm b/centreon-plugins/cloud/prometheus/restapi/mode/discovery.pm index 504343e3a..d687d42ba 100644 --- a/centreon-plugins/cloud/prometheus/restapi/mode/discovery.pm +++ b/centreon-plugins/cloud/prometheus/restapi/mode/discovery.pm @@ -56,10 +56,18 @@ sub manage_selection { my %target; $target{instance} = $target_information->{labels}->{instance}; $target{filter_instance} = "instance," . $target_information->{labels}->{instance}; + + foreach my $entry (keys %{$target_information}) { + next if (ref($target_information->{$entry}) ne "HASH" || $entry ne "labels"); + my @array; + foreach my $key (keys %{$target_information->{$entry}}) { + push @array, { key => $key, value => $target_information->{$entry}->{$key} }; + } + $target{$entry} = \@array; + } $target_information->{labels}->{instance} =~ s/(.*):\d+$//; $target{instance_address} = $1; - $target{job} = $target_information->{labels}->{job}; - $target{group} = $target_information->{labels}->{group}; + push @disco_data, \%target; }