This commit is contained in:
garnier-quentin 2020-07-06 15:55:59 +02:00
parent 1a2b2cab21
commit 83d09816af
9 changed files with 1241 additions and 0 deletions

View File

@ -0,0 +1,261 @@
#
# Copyright 2020 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 storage::nimble::restapi::custom::api;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::statefile;
use JSON::XS;
use Digest::MD5 qw(md5_hex);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n";
exit 3;
}
if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port'},
'proto:s' => { name => 'proto' },
'api-username:s' => { name => 'api_username' },
'api-password:s' => { name => 'api_password' },
'timeout:s' => { name => 'timeout', default => 30 }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{http} = centreon::plugins::http->new(%options);
$self->{cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub set_options {
my ($self, %options) = @_;
$self->{option_results} = $options{option_results};
}
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} : 5392;
$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->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : '';
$self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : '';
if ($self->{hostname} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --hostname option.");
$self->{output}->option_exit();
}
if ($self->{api_username} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --api-username option.");
$self->{output}->option_exit();
}
if ($self->{api_password} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify --api-password option.");
$self->{output}->option_exit();
}
$self->{cache}->check_options(option_results => $self->{option_results});
return 0;
}
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}->{timeout} = $self->{timeout};
}
sub settings {
my ($self, %options) = @_;
$self->build_options_for_httplib();
$self->{http}->add_header(key => 'Content-Type', value => 'application/json;charset=UTF-8');
$self->{http}->add_header(key => 'Accept', value => 'application/json;charset=UTF-8');
$self->{http}->set_options(%{$self->{option_results}});
}
sub json_decode {
my ($self, %options) = @_;
my $decoded;
eval {
$decoded = JSON::XS->new->utf8->decode($options{content});
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "cannot decode json response: $@");
$self->{output}->option_exit();
}
return $decoded;
}
sub clean_token {
my ($self, %options) = @_;
my $datas = { last_timestamp => time() };
$options{statefile}->write(data => $datas);
$self->{token} = undef;
$self->{http}->add_header(key => 'X-Auth-Token', value => undef);
}
sub authenticate {
my ($self, %options) = @_;
my $has_cache_file = $options{statefile}->read(statefile => 'nimble_' . md5_hex($self->{option_results}->{hostname}) . '_' . md5_hex($self->{option_results}->{api_username}));
my $token = $options{statefile}->get(name => 'token');
if ($has_cache_file == 0 || !defined($token)) {
my $json_request = { data => { username => $self->{api_username}, password => $self->{api_password} } };
my $encoded;
eval {
$encoded = encode_json($json_request);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => 'cannot encode json request');
$self->{output}->option_exit();
}
my ($content) = $self->{http}->request(
method => 'POST',
url_path => '/v1/tokens',
query_form_post => $encoded,
warning_status => '', unknown_status => '', critical_status => ''
);
if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) {
$self->{output}->add_option_msg(short_msg => "Login error [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");
$self->{output}->option_exit();
}
my $decoded = $self->json_decode(content => $content);
$token = defined($decoded->{data}->{session_token}) ? $decoded->{data}->{session_token} : undef;
if (!defined($token)) {
$self->{output}->add_option_msg(short_msg => "error retrieving token");
$self->{output}->option_exit();
}
my $datas = { last_timestamp => time(), token => $token };
$options{statefile}->write(data => $datas);
}
$self->{token} = $token;
$self->{http}->add_header(key => 'X-Auth-Token', value => $self->{token});
}
sub request_api {
my ($self, %options) = @_;
$self->settings();
if (!defined($self->{token})) {
$self->authenticate(statefile => $self->{cache});
}
my $content = $self->{http}->request(
endpoint => $options{endpoint},
warning_status => '', unknown_status => '', critical_status => ''
);
# Maybe there is an issue with the token. So we retry.
if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) {
$self->clean_token(statefile => $self->{cache});
$self->authenticate(statefile => $self->{cache});
$content = $self->{http}->request(
endpoint => $options{endpoint},
warning_status => '', unknown_status => '', critical_status => ''
);
}
my $decoded = $self->json_decode(content => $content);
if (!defined($decoded)) {
$self->{output}->add_option_msg(short_msg => 'Error while retrieving data (add --debug option for detailed message)');
$self->{output}->option_exit();
}
if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) {
$self->{output}->add_option_msg(short_msg => 'api request error');
$self->{output}->option_exit();
}
return $decoded;
}
1;
__END__
=head1 NAME
Nimble API
=head1 REST API OPTIONS
=over 8
=item B<--hostname>
Set hostname.
=item B<--port>
Set port (Default: '5392').
=item B<--proto>
Specify https if needed (Default: 'https').
=item B<--api-username>
Set username.
=item B<--api-password>
Set password.
=item B<--timeout>
Threshold for HTTP timeout (Default: '30').
=back
=cut

View File

@ -0,0 +1,215 @@
#
# Copyright 2020 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 storage::nimble::restapi::mode::arrays;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
'status: %s',
$self->{result_values}->{status}
);
}
sub custom_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space});
return sprintf(
'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space}
);
}
sub prefix_array_output {
my ($self, %options) = @_;
return "Storage array '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'arrays', type => 1, cb_prefix_output => 'prefix_array_output', message_multiple => 'All storage arrays are ok' }
];
$self->{maps_counters}->{arrays} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'space-usage', nlabel => 'array.space.usage.bytes', set => {
key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ],
closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'space-usage-free', nlabel => 'array.space.free.bytes', display_ok => 0, set => {
key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ],
closure_custom_output => $self->can('custom_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1, label_extra_instance => 1 }
]
}
},
{ label => 'space-usage-prct', nlabel => 'array.space.usage.percentage', display_ok => 0, set => {
key_values => [ { name => 'prct_used_space' }, { name => 'display' } ],
output_template => 'space used: %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
]
}
},
{ label => 'snapshots-compression-rate', nlabel => 'array.snapshots.compression.rate.count', display_ok => 0, set => {
key_values => [ { name => 'snap_compression' }, { name => 'display' } ],
output_template => 'snapshots compression rate: %s',
perfdatas => [
{ template => '%s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => 'snapshots-space-reduction-rate', nlabel => 'array.snapshots.space.reduction.rate.count', display_ok => 0, set => {
key_values => [ { name => 'snap_space_reduction' }, { name => 'display' } ],
output_template => 'snapshots space reduction rate: %s',
perfdatas => [
{ template => '%s', min => 0, label_extra_instance => 1 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /unreachable/i' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
}
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->request_api(endpoint => '/v1/arrays/detail');
$self->{arrays} = {};
foreach (@{$results->{data}}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$_->{name} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping array '" . $_->{name} . "': no matching filter.", debug => 1);
next;
}
my $total = $_->{usage} + $_->{available_bytes};
$self->{arrays}->{ $_->{name} } = {
display => $_->{name},
status => $_->{status},
total_space => $total,
used_space => $_->{usage},
free_space => $_->{available_bytes},
prct_used_space => $_->{usage} * 100 / $total,
prct_free_space => $_->{available_bytes} * 100 / $total,
snap_compression => $_->{snap_compression},
snap_space_reduction => $_->{snap_space_reduction}
};
}
if (scalar(keys %{$self->{arrays}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No storage arrays found");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check storage arrays.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='status'
=item B<--filter-name>
Filter array name (can be a regexp).
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{status}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /unreachable/i').
Can used special variables like: %{status}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'space-usage' (B), 'space-usage-free' (B), 'space-usage-prct' (%),
'snapshots-compression-rate', 'snapshots-space-reduction-rate'.
=back
=cut

View File

@ -0,0 +1,89 @@
#
# Copyright 2020 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 storage::nimble::restapi::mode::components::disk;
use strict;
use warnings;
sub load {
my ($self) = @_;
$self->{requests}->{disk} = '/v1/disks/detail';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking disks');
$self->{components}->{disk} = { name => 'disks', total => 0, skip => 0 };
return if ($self->check_filter(section => 'disk'));
return if (!defined($self->{results}->{disk}));
foreach (@{$self->{results}->{disk}->{data}}) {
my $instance = $_->{serial};
next if ($self->check_filter(section => 'disk', instance => $instance));
$self->{components}->{disk}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"disk '%s' array '%s' shelf '%s' state is '%s' [instance = %s] [raid state: %s]",
$instance,
$_->{array_name},
$_->{shelf_location},
$_->{state},
$instance,
$_->{raid_state}
)
);
my $exit = $self->get_severity(section => 'disk', value => $_->{state});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Disk '%s' array '%s' shelf '%s' state is '%s'",
$instance,
$_->{array_name},
$_->{shelf_location},
$_->{state}
)
);
}
$exit = $self->get_severity(section => 'raid', value => $_->{raid_state});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Disk '%s' array '%s' shelf '%s' raid state is '%s'",
$instance,
$_->{array_name},
$_->{shelf_location},
$_->{raid_state}
)
);
}
}
}
1;

View File

@ -0,0 +1,98 @@
#
# Copyright 2020 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 storage::nimble::restapi::mode::components::fan;
use strict;
use warnings;
sub load {
my ($self) = @_;
$self->{requests}->{shelve} = '/v1/shelves/detail';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking fans');
$self->{components}->{fan} = { name => 'fans', total => 0, skip => 0 };
return if ($self->check_filter(section => 'fan'));
return if (!defined($self->{results}->{shelve}));
foreach my $array (@{$self->{results}->{shelve}->{data}}) {
my $array_name = $array->{array_name};
foreach my $ctrl (@{$array->{ctrlrs}}) {
foreach my $sensor (@{$ctrl->{ctrlr_sensors}}) {
next if ($sensor->{type} ne 'fan');
my $instance = $sensor->{cid} . ':' . $sensor->{name};
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"fan '%s' array '%s' status is '%s' [instance = %s, value = %s]",
$instance,
$array_name,
$sensor->{status},
$instance,
$sensor->{value}
)
);
my $exit = $self->get_severity(label => 'sensor', section => 'fan', value => $sensor->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Fan '%s' array '%s' status is '%s'",
$instance,
$array_name,
$sensor->{status}
)
);
}
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $sensor->{value});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit2,
short_msg => sprintf("fan '%s' array '%s' speed is %s rpm", $instance, $array_name, $sensor->{value})
);
}
$self->{output}->perfdata_add(
nlabel => 'hardware.sensor.fan.speed.rpm',
unit => 'rpm',
instances => [$array_name, $instance],
value => $sensor->{value},
warning => $warn,
critical => $crit,
min => 0
);
}
}
}
}
1;

View File

@ -0,0 +1,78 @@
#
# Copyright 2020 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 storage::nimble::restapi::mode::components::psu;
use strict;
use warnings;
sub load {
my ($self) = @_;
$self->{requests}->{shelve} = '/v1/shelves/detail';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking power supplies');
$self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 };
return if ($self->check_filter(section => 'psu'));
return if (!defined($self->{results}->{shelve}));
foreach my $array (@{$self->{results}->{shelve}->{data}}) {
my $array_name = $array->{array_name};
foreach my $sensor (@{$array->{chassis_sensors}}) {
next if ($sensor->{type} ne 'power supply');
my $instance = $sensor->{cid} . ':' . $sensor->{name};
next if ($self->check_filter(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"power supply '%s' array '%s' status is '%s' [instance = %s]",
$instance,
$array_name,
$sensor->{status},
$instance
)
);
my $exit = $self->get_severity(label => 'sensor', section => 'psu', value => $sensor->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Power supply '%s' array '%s' status is '%s'",
$instance,
$array_name,
$sensor->{status}
)
);
}
}
}
}
1;

View File

@ -0,0 +1,97 @@
#
# Copyright 2020 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 storage::nimble::restapi::mode::components::temperature;
use strict;
use warnings;
sub load {
my ($self) = @_;
$self->{requests}->{shelve} = '/v1/shelves/detail';
}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking temperatures');
$self->{components}->{temperature} = { name => 'temperatures', total => 0, skip => 0 };
return if ($self->check_filter(section => 'temperature'));
return if (!defined($self->{results}->{shelve}));
foreach my $array (@{$self->{results}->{shelve}->{data}}) {
my $array_name = $array->{array_name};
foreach my $ctrl (@{$array->{ctrlrs}}) {
foreach my $sensor (@{$ctrl->{ctrlr_sensors}}) {
next if ($sensor->{type} ne 'temperature');
my $instance = $sensor->{cid} . ':' . $sensor->{name};
next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"temperature '%s' array '%s' status is '%s' [instance = %s, value = %s]",
$instance,
$array_name,
$sensor->{status},
$instance,
$sensor->{value}
)
);
my $exit = $self->get_severity(label => 'sensor', section => 'temperature', value => $sensor->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"Temperature '%s' array '%s' status is '%s'",
$instance,
$array_name,
$sensor->{status}
)
);
}
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $sensor->{value});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit2,
short_msg => sprintf("temperature '%s' array '%s' is %s degree celsius", $instance, $array_name, $sensor->{value})
);
}
$self->{output}->perfdata_add(
nlabel => 'hardware.sensor.temperature.celsius',
unit => 'C',
instances => [$array_name, $instance],
value => $sensor->{value},
warning => $warn,
critical => $crit
);
}
}
}
}
1;

View File

@ -0,0 +1,128 @@
#
# Copyright 2020 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 storage::nimble::restapi::mode::hardware;
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_overload_check_section_option} = '^(?:disk|fan|psu|temperature)$';
$self->{regexp_threshold_numeric_check_section_option} = '^(?:fan|temperature)$';
$self->{cb_hook2} = 'execute_custom';
$self->{thresholds} = {
sensor => [
['ok', 'OK'],
['alerted', 'CRITICAL'],
['failed', 'CRITICAL'],
['missing', 'OK']
],
disk => [
['valid', 'OK'],
['in use', 'OK'],
['failed', 'CRITICAL'],
['absent', 'OK'],
['removed', 'OK'],
['void', 'OK'],
['t_fail', 'CRITICAL'],
['foreign', 'OK']
],
raid => [
['N/A', 'OK'],
['okay', 'OK'],
['resynchronizing', 'OK'],
['spare', 'OK'],
['faulty', 'CRITICAL']
]
};
$self->{components_path} = 'storage::nimble::restapi::mode::components';
$self->{components_module} = ['disk', 'fan', 'temperature', 'psu'];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {});
$self->{requests} = {};
return $self;
}
sub execute_custom {
my ($self, %options) = @_;
$self->{results} = {};
foreach (keys %{$self->{requests}}) {
my $result = $options{custom}->request_api(endpoint => $self->{requests}->{$_});
$self->{results}->{$_} = $result;
}
}
1;
=head1 MODE
Check hardware.
=over 8
=item B<--component>
Which component to check (Default: '.*').
Can be: 'disk', 'fan', 'psu', 'temperature'.
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --filter=psu)
Can also exclude specific instance: --filter=fan,A:fan1
=item B<--no-component>
Return an error if no compenents are checked.
If total (with skipped) is 0. (Default: 'critical' returns).
=item B<--threshold-overload>
Set to overload default threshold values (syntax: section,[instance,]status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='sensor,WARNING,missing'
=item B<--warning>
Set warning threshold for 'fan', 'temperature' (syntax: section,[instance,]status,regexp)
Example: --warning='temperature,.*,30' --warning='fan,.*,1000'
=item B<--critical>
Set critical threshold for 'fan', 'temperature' (syntax: section,[instance,]status,regexp)
Example: --critical='temperature,.*,40'
=back
=cut

View File

@ -0,0 +1,219 @@
#
# Copyright 2020 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 storage::nimble::restapi::mode::volumes;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
'state: %s [space usage level: %s]',
$self->{result_values}->{state},
$self->{result_values}->{space_usage_level}
);
}
sub prefix_volume_output {
my ($self, %options) = @_;
return "Volume '" . $options{instance_value}->{display} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'volumes', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes are ok' }
];
$self->{maps_counters}->{volumes} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'state' }, { name => 'space_usage_level' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
}
},
{ label => 'space-usage', nlabel => 'volume.space.usage.bytes', set => {
key_values => [ { name => 'used_space' }, { name => 'display' } ],
output_template => 'space used: %s %s',
output_change_bytes => 1,
perfdatas => [
{ template => '%d', min => 0, unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' }
]
}
},
{ label => 'read', nlabel => 'volume.io.read.usage.bytespersecond', display_ok => 0, set => {
key_values => [ { name => 'read' } ],
output_template => 'read: %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ template => '%d', unit => 'B/s', label_extra_instance => 1 }
]
}
},
{ label => 'write', nlabel => 'volume.io.write.usage.bytespersecond', display_ok => 0, set => {
key_values => [ { name => 'write' } ],
output_template => 'write: %s %s/s',
output_change_bytes => 1,
perfdatas => [
{ template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 }
]
}
},
{ label => 'read-iops', nlabel => 'volume.io.read.usage.iops', set => {
key_values => [ { name => 'read_iops' } ],
output_template => 'read iops: %s',
perfdatas => [
{ template => '%s', unit => 'iops', min => 0, label_extra_instance => 1 }
]
}
},
{ label => 'write-iops', nlabel => 'volume.io.write.usage.iops', set => {
key_values => [ { name => 'write_iops' } ],
output_template => 'write iops: %s',
perfdatas => [
{ template => '%s', unit => 'iops', min => 0, label_extra_instance => 1 }
]
}
},
{ label => 'read-latency', nlabel => 'volume.io.read.latency.milliseconds', set => {
key_values => [ { name => 'read_latency' } ],
output_template => 'read latency: %s ms',
perfdatas => [
{ template => '%s', unit => 'ms', min => 0, label_extra_instance => 1 }
]
}
},
{ label => 'write-latency', nlabel => 'volume.io.write.latency.milliseconds', set => {
key_values => [ { name => 'write_latency' } ],
output_template => 'write latency: %s ms',
perfdatas => [
{ template => '%s', unit => 'ms', min => 0, label_extra_instance => 1 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '%{space_usage_level} =~ /warning/' },
'critical-status:s' => { name => 'critical_status', default => '%{state} !~ /online/i || %{space_usage_level} =~ /critical/' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']);
}
sub manage_selection {
my ($self, %options) = @_;
my $results = $options{custom}->request_api(endpoint => '/v1/volumes/detail');
$self->{volumes} = {};
foreach (@{$results->{data}}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$_->{name} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping volume '" . $_->{name} . "': no matching filter.", debug => 1);
next;
}
$self->{volumes}->{ $_->{name} } = {
display => $_->{name},
state => $_->{vol_state},
space_usage_level => $_->{space_usage_level},
used_space => $_->{total_usage_bytes},
read => $_->{avg_stats_last_5mins}->{read_throughput},
write => $_->{avg_stats_last_5mins}->{write_throughput},
read_iops => $_->{avg_stats_last_5mins}->{read_iops},
write_iops => $_->{avg_stats_last_5mins}->{write_iops},
read_latency => $_->{avg_stats_last_5mins}->{read_latency},
write_latency => $_->{avg_stats_last_5mins}->{write_latency}
};
}
if (scalar(keys %{$self->{volumes}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No volumes found");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check volumes.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='status'
=item B<--filter-name>
Filter volume name (can be a regexp).
=item B<--unknown-status>
Set unknown threshold for status.
Can used special variables like: %{state}, %{space_level_usage}, %{display}
=item B<--warning-status>
Set warning threshold for status (Default: '%{space_usage_level} =~ /warning/').
Can used special variables like: %{state}, %{space_level_usage}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{state} !~ /online/i || %{space_usage_level} =~ /critical/').
Can used special variables like: %{state}, %{space_level_usage}, %{display}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'space-usage' (B), 'read' (B/s), 'read-iops', 'write' (B/s), 'write-iops',
'read-latency' (ms), 'write-latency' (ms).
=back
=cut

View File

@ -0,0 +1,56 @@
#
# Copyright 2020 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 storage::nimble::restapi::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_custom);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$self->{modes} = {
'arrays' => 'storage::nimble::restapi::mode::arrays',
'hardware' => 'storage::nimble::restapi::mode::hardware',
'volumes' => 'storage::nimble::restapi::mode::volumes'
};
$self->{custom_modes}->{api} = 'storage::nimble::restapi::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check nimble through HTTP/REST API.
=over 8
=back
=cut