(plugin) cloud::docker::restapi - mode container-usage add option --no-stats (#3908)

This commit is contained in:
qgarnier 2022-09-21 13:48:26 +02:00 committed by GitHub
parent f261d2a369
commit b23970c6ae
2 changed files with 20 additions and 14 deletions

View File

@ -463,10 +463,10 @@ sub api_get_containers {
my $content_total = $self->cache_containers(statefile => $options{statefile}); my $content_total = $self->cache_containers(statefile => $options{statefile});
if (defined($options{container_id}) && $options{container_id} ne '') { if (defined($options{container_id}) && $options{container_id} ne '') {
if (defined($content_total->{$options{container_id}})) { 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}); $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})) { 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}); $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 '') { } elsif (defined($options{container_name}) && $options{container_name} ne '') {
my $container_id; my $container_id;
@ -479,17 +479,17 @@ sub api_get_containers {
} }
if (defined($container_id)) { 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); $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})) { 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); $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 { } else {
foreach my $container_id (keys %{$content_total}) { 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); $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})) { 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); $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}));
} }
} }

View File

@ -214,7 +214,8 @@ sub new {
'container-name:s' => { name => 'container_name' }, 'container-name:s' => { name => 'container_name' },
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
'use-name' => { name => 'use_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); $self->{statefile_cache_containers} = centreon::plugins::statefile->new(%options);
@ -235,7 +236,8 @@ sub manage_selection {
container_id => $self->{option_results}->{container_id}, container_id => $self->{option_results}->{container_id},
container_name => $self->{option_results}->{container_name}, container_name => $self->{option_results}->{container_name},
statefile => $self->{statefile_cache_containers}, 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} = {}; $self->{containers} = {};
@ -319,6 +321,10 @@ Use docker name for perfdata and display.
Get container health status (call inspector endpoint). Get container health status (call inspector endpoint).
=item B<--no-stats>
Don't get container statistics.
=item B<--filter-name> =item B<--filter-name>
Filter by container name (can be a regexp). Filter by container name (can be a regexp).