mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 07:34:35 +02:00
Fix #2126
This commit is contained in:
parent
ddad6e597e
commit
f3b1d574c8
@ -26,7 +26,6 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
use centreon::plugins::http;
|
use centreon::plugins::http;
|
||||||
use JSON::XS;
|
use JSON::XS;
|
||||||
use Encode;
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
@ -128,7 +127,7 @@ sub request_api {
|
|||||||
|
|
||||||
my $decoded;
|
my $decoded;
|
||||||
eval {
|
eval {
|
||||||
$decoded = JSON::XS->new->decode($content);
|
$decoded = JSON::XS->new->utf8->decode($content);
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
|
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
|
||||||
@ -150,7 +149,7 @@ sub internal_search {
|
|||||||
url_path => '/apiv2/search',
|
url_path => '/apiv2/search',
|
||||||
get_param => [
|
get_param => [
|
||||||
'size=1',
|
'size=1',
|
||||||
'from=' . $options{time_period} . 'm',
|
'from=-' . $options{time_period} . 'm',
|
||||||
'q=' . $options{query}
|
'q=' . $options{query}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -192,7 +191,6 @@ sub api_events {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Message may be messed-up with wrongly encoded characters, let's force some cleanup
|
# Message may be messed-up with wrongly encoded characters, let's force some cleanup
|
||||||
$message = Encode::encode('UTF-8', $message);
|
|
||||||
$message =~ s/[\r\n]//g;
|
$message =~ s/[\r\n]//g;
|
||||||
$message =~ s/^\s+|\s+$//g;
|
$message =~ s/^\s+|\s+$//g;
|
||||||
|
|
||||||
@ -210,10 +208,10 @@ sub internal_fields {
|
|||||||
# 300 limitation comes from the API : https://documentation.solarwinds.com/en/Success_Center/loggly/Content/admin/api-retrieving-data.htm
|
# 300 limitation comes from the API : https://documentation.solarwinds.com/en/Success_Center/loggly/Content/admin/api-retrieving-data.htm
|
||||||
my $status = $self->request_api(
|
my $status = $self->request_api(
|
||||||
method => 'GET',
|
method => 'GET',
|
||||||
url_path => '/apiv2/fields/'
|
url_path => '/apiv2/fields/' . $options{field} . '/',
|
||||||
get_param => [
|
get_param => [
|
||||||
'facet_size=300',
|
'facet_size=300',
|
||||||
'from=' . $options{time_period} . 'm',
|
'from=-' . $options{time_period} . 'm',
|
||||||
'q=' . $options{query}
|
'q=' . $options{query}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -225,12 +223,12 @@ sub api_fields {
|
|||||||
|
|
||||||
my $status = $self->internal_fields(
|
my $status = $self->internal_fields(
|
||||||
time_period => $options{time_period},
|
time_period => $options{time_period},
|
||||||
|
field => $options{field},
|
||||||
query => $options{query}
|
query => $options{query}
|
||||||
);
|
);
|
||||||
|
|
||||||
# Fields may be messed-up with wrongly encoded characters, let's force some cleanup
|
# Fields may be messed-up with wrongly encoded characters, let's force some cleanup
|
||||||
for (my $i = 0; $i < scalar(@{$status->{ $options{field} }}); $i++) {
|
for (my $i = 0; $i < scalar(@{$status->{ $options{field} }}); $i++) {
|
||||||
$status->{ $options{field} }->[$i]->{term} = Encode::encode('UTF-8', $status->{ $options{field} }->[$i]->{term});
|
|
||||||
$status->{ $options{field} }->[$i]->{term} =~ s/[\r\n]//g;
|
$status->{ $options{field} }->[$i]->{term} =~ s/[\r\n]//g;
|
||||||
$status->{ $options{field} }->[$i]->{term} =~ s/^\s+|\s+$//g;
|
$status->{ $options{field} }->[$i]->{term} =~ s/^\s+|\s+$//g;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user