From b23970c6ae7ad40311d837d2351038d52e5c41b4 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 21 Sep 2022 13:48:26 +0200 Subject: [PATCH] (plugin) cloud::docker::restapi - mode container-usage add option --no-stats (#3908) --- .../cloud/docker/restapi/custom/api.pm | 24 +++++++++---------- .../docker/restapi/mode/containerusage.pm | 10 ++++++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/centreon-plugins/cloud/docker/restapi/custom/api.pm b/centreon-plugins/cloud/docker/restapi/custom/api.pm index 0b65f2725..4e82e5907 100644 --- a/centreon-plugins/cloud/docker/restapi/custom/api.pm +++ b/centreon-plugins/cloud/docker/restapi/custom/api.pm @@ -463,10 +463,10 @@ sub api_get_containers { my $content_total = $self->cache_containers(statefile => $options{statefile}); if (defined($options{container_id}) && $options{container_id} ne '') { if (defined($content_total->{$options{container_id}})) { - $content_total->{ $options{container_id} }->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{ $options{container_id} }->{NodeName}, container_id => $options{container_id}); - if (defined($options{add_health})) { - $content_total->{ $options{container_id} }->{Inspector} = $self->internal_api_get_container_inspector(node_name => $content_total->{ $options{container_id} }->{NodeName}, container_id => $options{container_id}); - } + $content_total->{ $options{container_id} }->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{ $options{container_id} }->{NodeName}, container_id => $options{container_id}) + if (!defined($options{no_stats})); + $content_total->{ $options{container_id} }->{Inspector} = $self->internal_api_get_container_inspector(node_name => $content_total->{ $options{container_id} }->{NodeName}, container_id => $options{container_id}) + if (defined($options{add_health})); } } elsif (defined($options{container_name}) && $options{container_name} ne '') { my $container_id; @@ -479,17 +479,17 @@ sub api_get_containers { } if (defined($container_id)) { - $content_total->{$container_id}->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{$container_id}->{NodeName}, container_id => $container_id); - if (defined($options{add_health})) { - $content_total->{$container_id}->{Inspector} = $self->internal_api_get_container_inspector(node_name => $content_total->{$container_id}->{NodeName}, container_id => $container_id); - } + $content_total->{$container_id}->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{$container_id}->{NodeName}, container_id => $container_id) + if (!defined($options{no_stats})); + $content_total->{$container_id}->{Inspector} = $self->internal_api_get_container_inspector(node_name => $content_total->{$container_id}->{NodeName}, container_id => $container_id) + if (defined($options{add_health})); } } else { foreach my $container_id (keys %{$content_total}) { - $content_total->{$container_id}->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{$container_id}->{NodeName}, container_id => $container_id); - if (defined($options{add_health})) { - $content_total->{$container_id}->{Inspector} = $self->internal_api_get_container_inspector(node_name => $content_total->{$container_id}->{NodeName}, container_id => $container_id); - } + $content_total->{$container_id}->{Stats} = $self->internal_api_get_container_stats(node_name => $content_total->{$container_id}->{NodeName}, container_id => $container_id) + if (!defined($options{no_stats})); + $content_total->{$container_id}->{Inspector} = $self->internal_api_get_container_inspector(node_name => $content_total->{$container_id}->{NodeName}, container_id => $container_id) + if (defined($options{add_health})); } } diff --git a/centreon-plugins/cloud/docker/restapi/mode/containerusage.pm b/centreon-plugins/cloud/docker/restapi/mode/containerusage.pm index a26f0303f..a85a1fc15 100644 --- a/centreon-plugins/cloud/docker/restapi/mode/containerusage.pm +++ b/centreon-plugins/cloud/docker/restapi/mode/containerusage.pm @@ -214,7 +214,8 @@ sub new { 'container-name:s' => { name => 'container_name' }, 'filter-name:s' => { name => 'filter_name' }, 'use-name' => { name => 'use_name' }, - 'add-health' => { name => 'add_health' } + 'add-health' => { name => 'add_health' }, + 'no-stats' => { name => 'no_stats' } }); $self->{statefile_cache_containers} = centreon::plugins::statefile->new(%options); @@ -235,7 +236,8 @@ sub manage_selection { container_id => $self->{option_results}->{container_id}, container_name => $self->{option_results}->{container_name}, statefile => $self->{statefile_cache_containers}, - add_health => $self->{option_results}->{add_health} + add_health => $self->{option_results}->{add_health}, + no_stats => $self->{option_results}->{no_stats} ); $self->{containers} = {}; @@ -319,6 +321,10 @@ Use docker name for perfdata and display. Get container health status (call inspector endpoint). +=item B<--no-stats> + +Don't get container statistics. + =item B<--filter-name> Filter by container name (can be a regexp).