From c19314dbb84ee0c1b35aa9b885270f6a0b20a17d Mon Sep 17 00:00:00 2001 From: qgarnier Date: Fri, 2 Jul 2021 11:43:48 +0200 Subject: [PATCH] fix(docker,cadvisor): output_add errors (#2932) --- .../cloud/cadvisor/restapi/custom/api.pm | 30 ++++++++++++------- .../cloud/docker/restapi/custom/api.pm | 6 ++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/centreon-plugins/cloud/cadvisor/restapi/custom/api.pm b/centreon-plugins/cloud/cadvisor/restapi/custom/api.pm index 8396e5e13..f922f4134 100644 --- a/centreon-plugins/cloud/cadvisor/restapi/custom/api.pm +++ b/centreon-plugins/cloud/cadvisor/restapi/custom/api.pm @@ -122,8 +122,10 @@ sub internal_api_list_nodes { }; if ($@) { $nodes = {}; - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Node '$options{node_name}': cannot decode json list nodes response: $@"); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Node '$options{node_name}': cannot decode json list nodes response: $@" + ); } else { $nodes = {} if (ref($nodes) eq 'ARRAY'); # nodes is not in a swarm } @@ -144,8 +146,10 @@ sub internal_api_info { }; if ($@) { $nodes = []; - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Node '$options{node_name}': cannot decode json info response: $@"); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Node '$options{node_name}': cannot decode json info response: $@" + ); } return $nodes; @@ -165,8 +169,10 @@ sub internal_api_list_containers { }; if ($@) { $containers = []; - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Node '$options{node_name}': cannot decode json get containers response: $@"); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Node '$options{node_name}': cannot decode json get containers response: $@" + ); } foreach my $container (@{$containers_ids->{subcontainers}}) { my $json_response = JSON::XS->new->utf8->decode( @@ -199,8 +205,10 @@ sub internal_api_get_machine_stats { }; if ($@) { $machine_stats = {}; - $self->output_add(severity => 'UNKNOWN', - short_msg => "Node '$options{node_name}': cannot decode json get container stats response: $@"); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Node '$options{node_name}': cannot decode json get container stats response: $@" + ); } else { $machine_stats->{num_cores} = $full_machine_stats->{num_cores}; $machine_stats->{memory_capacity} = $full_machine_stats->{memory_capacity}; @@ -221,8 +229,10 @@ sub internal_api_get_container_stats { }; if ($@) { $container_stats = []; - $self->output_add(severity => 'UNKNOWN', - short_msg => "Node '$options{node_name}': cannot decode json get container stats response: $@"); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Node '$options{node_name}': cannot decode json get container stats response: $@" + ); } else { $container_stats->[0] = $full_container_stats->{stats}[0]; $container_stats->[1] = $full_container_stats->{stats}[scalar(@{$full_container_stats->{stats}}) - 1]; diff --git a/centreon-plugins/cloud/docker/restapi/custom/api.pm b/centreon-plugins/cloud/docker/restapi/custom/api.pm index 1778fd34d..a497da4d9 100644 --- a/centreon-plugins/cloud/docker/restapi/custom/api.pm +++ b/centreon-plugins/cloud/docker/restapi/custom/api.pm @@ -116,7 +116,7 @@ sub api_display { } if (!open (FH, '>', $self->{option_results}->{api_write_file})) { - $self->output_add( + $self->{output}->output_add( severity => 'UNKNOWN', short_msg => "cannot open file '" . $self->{option_results}->{api_write_file} . "': $!" ); @@ -125,7 +125,7 @@ sub api_display { FH->autoflush(1); print FH $options{content}; close FH; - $self->output_add( + $self->{output}->output_add( severity => 'OK', short_msg => "Data written in file '" . $self->{option_results}->{api_write_file} . "': $!" ); @@ -300,7 +300,7 @@ sub internal_api_get_container_stats { }; if ($@) { $container_stats = {}; - $self->output_add( + $self->{output}->output_add( severity => 'UNKNOWN', short_msg => "Node '$options{node_name}': cannot decode json get container stats response: $@" );