mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-04-07 20:35:27 +02:00
style(plugin): adjust indentation - CTOR-586 (#5033)
This commit is contained in:
parent
53fc5ca260
commit
ebbf35b945
@ -29,7 +29,7 @@ use JSON::XS;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
if (!defined($options{output})) {
|
||||
@ -42,12 +42,12 @@ sub new {
|
||||
}
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
$options{options}->add_options(arguments => {
|
||||
'hostname:s' => { name => 'hostname' },
|
||||
'port:s' => { name => 'port'},
|
||||
'port:s' => { name => 'port' },
|
||||
'proto:s' => { name => 'proto' },
|
||||
'api-password:s' => { name => 'api_password' },
|
||||
'timeout:s' => { name => 'timeout', default => 30 },
|
||||
'timeout:s' => { name => 'timeout'},
|
||||
'unknown-http-status:s' => { name => 'unknown_http_status' },
|
||||
'warning-http-status:s' => { name => 'warning_http_status' },
|
||||
'critical-http-status:s' => { name => 'critical_http_status' }
|
||||
@ -57,7 +57,7 @@ sub new {
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
|
||||
|
||||
$self->{output} = $options{output};
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
$self->{http} = centreon::plugins::http->new(%options);
|
||||
|
||||
return $self;
|
||||
}
|
||||
@ -73,14 +73,14 @@ sub set_defaults {}
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
|
||||
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443;
|
||||
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30;
|
||||
$self->{ssl_opt} = (defined($self->{option_results}->{ssl_opt})) ? $self->{option_results}->{ssl_opt} : undef;
|
||||
$self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : '';
|
||||
$self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300';
|
||||
$self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : '';
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
|
||||
$self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443;
|
||||
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30;
|
||||
$self->{ssl_opt} = (defined($self->{option_results}->{ssl_opt})) ? $self->{option_results}->{ssl_opt} : undef;
|
||||
$self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : '';
|
||||
$self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300';
|
||||
$self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : '';
|
||||
$self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : '';
|
||||
|
||||
if ($self->{hostname} eq '') {
|
||||
@ -99,10 +99,10 @@ sub build_options_for_httplib {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{option_results}->{hostname} = $self->{hostname};
|
||||
$self->{option_results}->{port} = $self->{port};
|
||||
$self->{option_results}->{proto} = $self->{proto};
|
||||
$self->{option_results}->{ssl_opt} = $self->{ssl_opt};
|
||||
$self->{option_results}->{timeout} = $self->{timeout};
|
||||
$self->{option_results}->{port} = $self->{port};
|
||||
$self->{option_results}->{proto} = $self->{proto};
|
||||
$self->{option_results}->{ssl_opt} = $self->{ssl_opt};
|
||||
$self->{option_results}->{timeout} = $self->{timeout};
|
||||
}
|
||||
|
||||
sub settings {
|
||||
@ -119,9 +119,9 @@ sub request_api {
|
||||
|
||||
$self->settings();
|
||||
my $content = $self->{http}->request(
|
||||
%options,
|
||||
unknown_status => $self->{unknown_http_status},
|
||||
warning_status => $self->{warning_http_status},
|
||||
%options,
|
||||
unknown_status => $self->{unknown_http_status},
|
||||
warning_status => $self->{warning_http_status},
|
||||
critical_status => $self->{critical_http_status}
|
||||
);
|
||||
|
||||
@ -145,8 +145,8 @@ sub internal_search {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $status = $self->request_api(
|
||||
method => 'GET',
|
||||
url_path => '/apiv2/search',
|
||||
method => 'GET',
|
||||
url_path => '/apiv2/search',
|
||||
get_param => [
|
||||
'size=1',
|
||||
'from=-' . $options{time_period} . 'm',
|
||||
@ -160,8 +160,8 @@ sub internal_events {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $status = $self->request_api(
|
||||
method => 'GET',
|
||||
url_path => '/apiv2/events',
|
||||
method => 'GET',
|
||||
url_path => '/apiv2/events',
|
||||
get_param => ['rsid=' . $options{id}]
|
||||
);
|
||||
return $status;
|
||||
@ -172,7 +172,7 @@ sub api_events {
|
||||
|
||||
my $id = $self->internal_search(
|
||||
time_period => $options{time_period},
|
||||
query => $options{query}
|
||||
query => $options{query}
|
||||
);
|
||||
my $status = $self->internal_events(id => $id);
|
||||
|
||||
@ -207,8 +207,8 @@ sub internal_fields {
|
||||
|
||||
# 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(
|
||||
method => 'GET',
|
||||
url_path => '/apiv2/fields/' . $options{field} . '/',
|
||||
method => 'GET',
|
||||
url_path => '/apiv2/fields/' . $options{field} . '/',
|
||||
get_param => [
|
||||
'facet_size=300',
|
||||
'from=-' . $options{time_period} . 'm',
|
||||
@ -223,12 +223,12 @@ sub api_fields {
|
||||
|
||||
my $status = $self->internal_fields(
|
||||
time_period => $options{time_period},
|
||||
field => $options{field},
|
||||
query => $options{query}
|
||||
field => $options{field},
|
||||
query => $options{query}
|
||||
);
|
||||
|
||||
# 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} =~ s/[\r\n]//g;
|
||||
$status->{ $options{field} }->[$i]->{term} =~ s/^\s+|\s+$//g;
|
||||
}
|
||||
|
@ -34,19 +34,19 @@ sub set_counters {
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'events', nlabel => 'events.count', set => {
|
||||
key_values => [ { name => 'events' } ],
|
||||
output_template => 'Matching events: %s',
|
||||
perfdatas => [
|
||||
{ template => '%s', value => 'events', min => 0 }
|
||||
]
|
||||
}
|
||||
key_values => [{ name => 'events' }],
|
||||
output_template => 'Matching events: %s',
|
||||
perfdatas => [
|
||||
{ template => '%s', value => 'events', min => 0 }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
@ -77,8 +77,8 @@ sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $results = $options{custom}->api_events(
|
||||
time_period => $self->{option_results}->{time_period},
|
||||
query => $self->{option_results}->{query},
|
||||
time_period => $self->{option_results}->{time_period},
|
||||
query => $self->{option_results}->{query},
|
||||
output_field => $self->{option_results}->{output_field}
|
||||
);
|
||||
$self->{global} = { events => $results->{total_events} };
|
||||
@ -99,11 +99,11 @@ Count events matching the query.
|
||||
|
||||
=item B<--time-period>
|
||||
|
||||
Set request period, in minutes.
|
||||
Set request period, in minutes (mandatory option).
|
||||
|
||||
=item B<--query>
|
||||
|
||||
Set the query.
|
||||
Set the query (mandatory option).
|
||||
|
||||
=item B<--output-field>
|
||||
|
||||
|
@ -35,31 +35,31 @@ sub set_counters {
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'events', nlabel => 'events.count', display_ok => 1, set => {
|
||||
key_values => [ { name => 'events' } ],
|
||||
output_template => 'Matching events: %s',
|
||||
perfdatas => [
|
||||
{ template => '%s', min => 0 }
|
||||
]
|
||||
}
|
||||
key_values => [{ name => 'events' }],
|
||||
output_template => 'Matching events: %s',
|
||||
perfdatas => [
|
||||
{ template => '%s', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'fields', nlabel => 'fields.count', display_ok => 1, set => {
|
||||
key_values => [ { name => 'fields' } ],
|
||||
output_template => 'Matching fields: %s',
|
||||
perfdatas => [
|
||||
{ template => '%s', min => 0 }
|
||||
]
|
||||
}
|
||||
key_values => [{ name => 'fields' }],
|
||||
output_template => 'Matching fields: %s',
|
||||
perfdatas => [
|
||||
{ template => '%s', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{field} = [
|
||||
{ label => 'field-events', nlabel => 'field.events.count', set => {
|
||||
key_values => [ { name => 'count' }, { name => 'display' } ],
|
||||
output_template => 'matching events: %s',
|
||||
perfdatas => [
|
||||
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
key_values => [{ name => 'count' }, { name => 'display' }],
|
||||
output_template => 'matching events: %s',
|
||||
perfdatas => [
|
||||
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
@ -72,7 +72,7 @@ sub prefix_field_output {
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
@ -118,8 +118,8 @@ sub manage_selection {
|
||||
|
||||
my $results = $options{custom}->api_fields(
|
||||
time_period => $self->{option_results}->{time_period},
|
||||
query => $self->{option_results}->{query},
|
||||
field => $self->{option_results}->{field}
|
||||
query => $self->{option_results}->{query},
|
||||
field => $self->{option_results}->{field}
|
||||
);
|
||||
|
||||
my ($events, $fields) = (0, 0);
|
||||
@ -128,10 +128,10 @@ sub manage_selection {
|
||||
foreach (@{$results->{$self->{option_results}->{field}}}) {
|
||||
if (!defined($self->{option_results}->{filter_field}) || ($_->{term} =~ /$self->{option_results}->{filter_field}/i)) {
|
||||
$fields++;
|
||||
$events += $_->{count};
|
||||
$events+= $_->{count};
|
||||
$self->{field}->{$fields} = {
|
||||
display => $_->{term},
|
||||
count => $_->{count}
|
||||
count => $_->{count}
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -151,19 +151,19 @@ Count unique field-values from events matching the query.
|
||||
|
||||
=item B<--time-period>
|
||||
|
||||
Set request period, in minutes.
|
||||
Set request period, in minutes (mandatory option).
|
||||
|
||||
=item B<--query>
|
||||
|
||||
Set the query.
|
||||
Set the query (mandatory option).
|
||||
|
||||
=item B<--field>
|
||||
|
||||
Set the field to count unique values for (example: json.host).
|
||||
Set the field to count unique values for example: json.host (mandatory option).
|
||||
|
||||
=item B<--filter-field>
|
||||
|
||||
Set the a field filter.
|
||||
Define which fields should be counted. This option will be treated as a regular expression. If this option is empty, all fields will be counted.
|
||||
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
|
@ -26,11 +26,11 @@ use base qw(centreon::plugins::script_custom);
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$self->{modes} = {
|
||||
$self->{modes} = {
|
||||
'events' => 'apps::monitoring::loggly::restapi::mode::events',
|
||||
'fields' => 'apps::monitoring::loggly::restapi::mode::fields'
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
--add-sysdesc
|
||||
--api-password
|
||||
--display-transform-dst
|
||||
--display-transform-src
|
||||
--exclude-fs
|
||||
@ -33,6 +34,7 @@ interface-dsl-name
|
||||
IpAddr
|
||||
Iwsva
|
||||
license-instances-usage-prct
|
||||
Loggly
|
||||
MBean
|
||||
NagVis
|
||||
Netscaler
|
||||
|
Loading…
x
Reference in New Issue
Block a user