From e6b77888b87c2d63b82012a6f8084d5911b86a12 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Wed, 11 Jan 2023 14:12:10 +0000 Subject: [PATCH] (plugin) cloud::talend::tmc - fix tasks id endpoint method (#4136) --- centreon-plugins/cloud/talend/tmc/custom/api.pm | 2 +- centreon-plugins/database/influxdb/custom/api.pm | 8 ++++---- centreon-plugins/database/influxdb/mode/query.pm | 15 ++++++++------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/centreon-plugins/cloud/talend/tmc/custom/api.pm b/centreon-plugins/cloud/talend/tmc/custom/api.pm index 0c449b9c6..506a653f6 100644 --- a/centreon-plugins/cloud/talend/tmc/custom/api.pm +++ b/centreon-plugins/cloud/talend/tmc/custom/api.pm @@ -324,7 +324,7 @@ sub get_tasks_execution { if (defined($self->{option_results}->{cache_use}) && !defined($options{disable_cache}) && !(defined($options{taskId}) && $options{taskId} ne '')); return $self->request_api( - method => 'POST', + method => (defined($options{taskId}) && $options{taskId} ne '') ? 'GET' : 'POST', endpoint => (defined($options{taskId}) && $options{taskId} ne '') ? '/processing/executables/tasks/' . $options{taskId} . '/executions' : '/processing/executables/tasks/executions', body => { diff --git a/centreon-plugins/database/influxdb/custom/api.pm b/centreon-plugins/database/influxdb/custom/api.pm index 035892627..83ae81da9 100644 --- a/centreon-plugins/database/influxdb/custom/api.pm +++ b/centreon-plugins/database/influxdb/custom/api.pm @@ -145,7 +145,7 @@ sub request { $self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); $self->{output}->option_exit(); } - + my $decoded; eval { $decoded = JSON::XS->new->utf8->decode($content); @@ -174,11 +174,11 @@ sub query { post_param => ['q=' . $query] ); - if (defined($results->{results}[0]->{error})) { - $self->{output}->add_option_msg(short_msg => "API returns error '" . $results->{results}[0]->{error} . "'"); + if (defined($results->{results}->[0]->{error})) { + $self->{output}->add_option_msg(short_msg => "API returns error '" . $results->{results}->[0]->{error} . "'"); $self->{output}->option_exit(); } - push @{$data}, @{$results->{results}[0]->{series}} if (defined($results->{results}[0]->{series})); + push @$data, @{$results->{results}->[0]->{series}} if (defined($results->{results}->[0]->{series})); } return $data; diff --git a/centreon-plugins/database/influxdb/mode/query.pm b/centreon-plugins/database/influxdb/mode/query.pm index d132b4c3a..dd36b5a1b 100644 --- a/centreon-plugins/database/influxdb/mode/query.pm +++ b/centreon-plugins/database/influxdb/mode/query.pm @@ -125,11 +125,11 @@ sub check_options { foreach my $query (@{$self->{option_results}->{query}}) { next if ($query !~ /^(.*?),(.*)$/); $self->{queries}->{$1} = $2; - push @{$self->{maps_counters}->{queries_results}[0]->{set}->{key_values}}, { name => $1 }; + push @{$self->{maps_counters}->{queries_results}->[0]->{set}->{key_values}}, { name => $1 }; push @{$self->{custom_keys}}, $1; } - $self->{maps_counters_type}[0]->{message_multiple} = $self->{option_results}->{multiple_output} if (defined($self->{option_results}->{multiple_output})); + $self->{maps_counters_type}->[0]->{message_multiple} = $self->{option_results}->{multiple_output} if (defined($self->{option_results}->{multiple_output})); } sub manage_selection { @@ -145,14 +145,15 @@ sub manage_selection { push @queries, $self->{queries}->{$label}; my $queries_results = $options{custom}->query(queries => \@queries); + + foreach my $result (@$queries_results) { + next if (!defined($result->{tags}->{ $self->{option_results}->{instance} })); - foreach my $result (@{$queries_results}) { - next if (!defined($result->{tags}->{$self->{option_results}->{instance}})); - my ($column_index) = grep { $result->{columns}[$_] eq $self->{custom_keys}[$query_index] } (0 .. @{$result->{columns}} - 1); + my ($column_index) = grep { $result->{columns}->[$_] eq $self->{custom_keys}->[$query_index] } (0 .. @{$result->{columns}} - 1); my $value; $value = $options{custom}->compute(aggregation => $self->{option_results}->{aggregation}, values => $result->{values}, column => $column_index) if (defined($result->{values})); - $self->{queries_results}->{$result->{tags}->{$self->{option_results}->{instance}}}->{instance} = $result->{tags}->{$self->{option_results}->{instance}}; - $self->{queries_results}->{$result->{tags}->{$self->{option_results}->{instance}}}->{$result->{columns}[$column_index]} = $value; + $self->{queries_results}->{ $result->{tags}->{ $self->{option_results}->{instance} } }->{instance} = $result->{tags}->{ $self->{option_results}->{instance} }; + $self->{queries_results}->{ $result->{tags}->{ $self->{option_results}->{instance} } }->{ $result->{columns}->[$column_index] } = $value; } }