diff --git a/cloud/docker/restapi/custom/api.pm b/cloud/docker/restapi/custom/api.pm index 9ebdedf92..a84867136 100644 --- a/cloud/docker/restapi/custom/api.pm +++ b/cloud/docker/restapi/custom/api.pm @@ -337,6 +337,19 @@ sub api_get_containers { 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}); } + } elsif (defined($options{container_name}) && $options{container_name} ne '') { + my $container_id; + + foreach (keys %$content_total) { + if ($content_total->{$_}->{Name} eq $options{container_name}) { + $container_id = $_; + last; + } + } + + 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); + } } 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); diff --git a/cloud/docker/restapi/mode/containerusage.pm b/cloud/docker/restapi/mode/containerusage.pm index 8d4cd57d4..3ec13cb61 100644 --- a/cloud/docker/restapi/mode/containerusage.pm +++ b/cloud/docker/restapi/mode/containerusage.pm @@ -217,6 +217,7 @@ sub new { $options{options}->add_options(arguments => { "container-id:s" => { name => 'container_id' }, + "container-name:s" => { name => 'container_name' }, "filter-name:s" => { name => 'filter_name' }, "use-name" => { name => 'use_name' }, "warning-container-status:s" => { name => 'warning_container_status', default => '' }, @@ -263,7 +264,8 @@ sub manage_selection { $self->{containers} = {}; $self->{containers_traffic} = {}; - my $result = $options{custom}->api_get_containers(container_id => $self->{option_results}->{container_id}, statefile => $self->{statefile_cache_containers}); + my $result = $options{custom}->api_get_containers(container_id => $self->{option_results}->{container_id}, + container_name => $self->{option_results}->{container_name}, statefile => $self->{statefile_cache_containers}); foreach my $container_id (keys %{$result}) { next if (!defined($result->{$container_id}->{Stats})); @@ -309,7 +311,8 @@ sub manage_selection { $self->{cache_name} = "docker_" . $self->{mode} . '_' . join('_', @$hostnames) . '_' . $options{custom}->get_port() . '_' . (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . - (defined($self->{option_results}->{container_id}) ? md5_hex($self->{option_results}->{container_id}) : md5_hex('all')); + (defined($self->{option_results}->{container_id}) ? md5_hex($self->{option_results}->{container_id}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{container_name}) ? md5_hex($self->{option_results}->{container_name}) : md5_hex('all')); } 1; @@ -326,6 +329,10 @@ Check container usage. Exact container ID. +=item B<--container-name> + +Exact container name (if multiple names: names separated by ':'). + =item B<--use-name> Use docker name for perfdata and display.