enh elasticsearch

This commit is contained in:
Colin Gagnaire 2019-06-18 11:24:57 +02:00
parent 6fa8cff206
commit 525a925ada
4 changed files with 204 additions and 2 deletions

View File

@ -188,12 +188,14 @@ Example: --filter-counters='^status$'
=item B<--warning-*>
Threshold warning.
Can be: 'active-primary-shards', 'active-shards'.
Can be: 'documents-total', 'data-size-primaries',
'data-size-total', 'shards-active', 'shards-unassigned'.
=item B<--critical-*>
Threshold critical.
Can be: 'active-primary-shards', 'active-shards'.
Can be: 'documents-total', 'data-size-primaries',
'data-size-total', 'shards-active', 'shards-unassigned'.
=item B<--warning-status>

View File

@ -0,0 +1,98 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package database::elasticsearch::restapi::mode::listindices;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{results} = $options{custom}->get(path => '/_cluster/health?level=indices');
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $indice (keys %{$self->{results}->{indices}}) {
$self->{output}->output_add(long_msg => sprintf("[name = %s][status = %s]",
$indice,
$self->{results}->{indices}->{$indice}->{status})
);
}
$self->{output}->output_add(severity => 'OK',
short_msg => "List indices:");
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'status']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $indice (keys %{$self->{results}->{indices}}) {
$self->{output}->add_disco_entry(
name => $indice,
status => $self->{results}->{indices}->{$indice}->{status}
);
}
}
1;
__END__
=head1 MODE
List indices
=over 8
=back
=cut

View File

@ -0,0 +1,100 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package database::elasticsearch::restapi::mode::listnodes;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{results} = $options{custom}->get(path => '/_nodes/stats');
}
sub run {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $node (keys %{$self->{results}->{nodes}}) {
$self->{output}->output_add(long_msg => sprintf("[name = %s][host = %s][ip = %s]",
$self->{results}->{nodes}->{$node}->{name},
$self->{results}->{nodes}->{$node}->{host},
$self->{results}->{nodes}->{$node}->{ip})
);
}
$self->{output}->output_add(severity => 'OK',
short_msg => "List nodes:");
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name', 'host', 'ip']);
}
sub disco_show {
my ($self, %options) = @_;
$self->manage_selection(%options);
foreach my $node (keys %{$self->{results}->{nodes}}) {
$self->{output}->add_disco_entry(
name => $self->{results}->{nodes}->{$node}->{name},
host => $self->{results}->{nodes}->{$node}->{host},
ip => $self->{results}->{nodes}->{$node}->{ip}
);
}
}
1;
__END__
=head1 MODE
List nodes
=over 8
=back
=cut

View File

@ -34,6 +34,8 @@ sub new {
'cluster-statistics' => 'database::elasticsearch::restapi::mode::clusterstatistics',
'indice-statistics' => 'database::elasticsearch::restapi::mode::indicestatistics',
'license' => 'database::elasticsearch::restapi::mode::license',
'list-indices' => 'database::elasticsearch::restapi::mode::listindices',
'list-nodes' => 'database::elasticsearch::restapi::mode::listnodes',
'node-statistics' => 'database::elasticsearch::restapi::mode::nodestatistics',
);
$self->{custom_modes}{api} = 'database::elasticsearch::restapi::custom::api';