fix(cloud::aws::cloudwatch): fix zeroed option in getmetrics mode (#5619)

Co-authored-by: omercier <32134301+omercier@users.noreply.github.com>
Refs: CTOR-1706
This commit is contained in:
itoussies 2025-06-30 09:57:55 +02:00 committed by GitHub
parent 1357f4708f
commit d0d4f0ce95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -172,18 +172,24 @@ sub manage_selection {
$self->{metrics} = {}; $self->{metrics} = {};
foreach my $label (keys %{$metric_results}) { foreach my $label (keys %{$metric_results}) {
foreach my $stat (('minimum', 'maximum', 'average', 'sum')) { foreach my $statistic (@{$self->{aws_statistics}}) {
next if (!defined($metric_results->{$label}->{$stat})); next if (!defined($metric_results->{$label}->{lc($statistic)}) &&
!defined($self->{option_results}->{zeroed}));
my $name = $label . '_' . $stat; my $name = $label . '_' . $statistic;
$name = $self->{dimension_name} . '_' . $name if ($self->{dimension_name} ne ''); $name = $self->{dimension_name} . '_' . $name if ($self->{dimension_name} ne '');
$self->{metrics}->{$name} = { $self->{metrics}->{$name} = {
display => $name, display => $name,
value => $metric_results->{$label}->{$stat}, value => $metric_results->{$label}->{lc($statistic)} // 0,
perf_label => $label . '_' . $stat, perf_label => $label . '_' . $statistic,
}; };
} }
} }
if (scalar(keys %{$self->{metrics}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values');
$self->{output}->option_exit();
}
} }
1; 1;
@ -192,7 +198,7 @@ __END__
=head1 MODE =head1 MODE
Check cloudwatch metrics (same dimension and namespace). Check CloudWatch metrics (same dimension and namespace).
Example: Example:
perl centreon_plugins.pl --plugin=cloud::aws::plugin --custommode=paws --mode=cloudwatch-get-metrics --region=eu-west-1 perl centreon_plugins.pl --plugin=cloud::aws::plugin --custommode=paws --mode=cloudwatch-get-metrics --region=eu-west-1
@ -203,15 +209,15 @@ perl centreon_plugins.pl --plugin=cloud::aws::plugin --custommode=paws --mode=cl
=item B<--namespace> =item B<--namespace>
Set cloudwatch namespace (required). Set CloudWatch namespace (required).
=item B<--dimension> =item B<--dimension>
Set cloudwatch dimensions. Set CloudWatch dimensions.
=item B<--metric> =item B<--metric>
Set cloudwatch metrics (required). Set CloudWatch metrics (required).
=item B<--warning-metric> =item B<--warning-metric>