InfluxDB, allow to select custom field
This commit is contained in:
parent
ae5255d4e9
commit
5818d14ce9
|
@ -175,7 +175,7 @@ sub query {
|
|||
|
||||
my $data;
|
||||
foreach my $query (@{$options{queries}}) {
|
||||
my $results = $self->request(method => 'POST', url_path => '/query', post_param => ['q=' . $query]);
|
||||
my $results = $self->request(method => 'POST', url_path => '/query?epoch=s', post_param => ['q=' . $query]);
|
||||
|
||||
if (defined($results->{results}[0]->{error})) {
|
||||
$self->{output}->add_option_msg(short_msg => "API returns error '" . $results->{results}[0]->{error} . "'");
|
||||
|
@ -196,22 +196,22 @@ sub compute {
|
|||
my $points = 0;
|
||||
foreach my $value (@{$options{values}}) {
|
||||
$result = 0 if (!defined($result));
|
||||
$result += $$value[1];
|
||||
$result += $$value[$options{column}];
|
||||
$points++;
|
||||
}
|
||||
$result /= $points;
|
||||
} elsif ($options{aggregation} eq 'minimum') {
|
||||
foreach my $value (@{$options{values}}) {
|
||||
$result = $$value[1] if (!defined($result) || $$value[1] < $result);
|
||||
$result = $$value[$options{column}] if (!defined($result) || $$value[$options{column}] < $result);
|
||||
}
|
||||
} elsif ($options{aggregation} eq 'maximum') {
|
||||
foreach my $value (@{$options{values}}) {
|
||||
$result = $$value[1] if (!defined($result) || $$value[1] > $result);
|
||||
$result = $$value[$options{column}] if (!defined($result) || $$value[$options{column}] > $result);
|
||||
}
|
||||
} elsif ($options{aggregation} eq 'sum') {
|
||||
foreach my $value (@{$options{values}}) {
|
||||
$result = 0 if (!defined($result));
|
||||
$result += $$value[1];
|
||||
$result += $$value[$options{column}];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
use List::MoreUtils qw(first_index);
|
||||
|
||||
sub custom_status_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -141,21 +142,24 @@ sub manage_selection {
|
|||
$self->{queries_results} = {};
|
||||
my (@results, @queries);
|
||||
|
||||
my $query_index = -1;
|
||||
foreach my $label (keys %{$self->{queries}}) {
|
||||
$query_index++;
|
||||
@queries = ();
|
||||
push @queries, $self->{queries}->{$label};
|
||||
}
|
||||
|
||||
my $queries_results = $options{custom}->query(queries => \@queries) if (scalar(@queries) > 0);
|
||||
|
||||
foreach my $result (@{$queries_results}) {
|
||||
next if (!defined($result->{tags}->{$self->{option_results}->{instance}}));
|
||||
my $value;
|
||||
$value = $options{custom}->compute(aggregation => $self->{option_results}->{aggregation}, values => $result->{values}) 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}[1]} = $value;
|
||||
my $queries_results = $options{custom}->query(queries => \@queries) if (scalar(@queries) > 0);
|
||||
|
||||
foreach my $result (@{$queries_results}) {
|
||||
next if (!defined($result->{tags}->{$self->{option_results}->{instance}}));
|
||||
my $column_index = first_index { $_ eq $self->{custom_keys}[$query_index] } @{$result->{columns}};
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (scalar(keys %{$self->{queries_results}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No queries found.");
|
||||
$self->{output}->option_exit();
|
||||
|
|
Loading…
Reference in New Issue