(plugin) storage::hp::storeonce::4::restapi - new (#3682)

This commit is contained in:
qgarnier 2022-05-24 10:29:04 +02:00 committed by GitHub
parent bcd36981c4
commit 1dce8986b9
14 changed files with 1656 additions and 0 deletions

View File

@ -0,0 +1,271 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::custom::api;
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 = {};
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 => {
'api-username:s' => { name => 'api_username' },
'api-password:s' => { name => 'api_password' },
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port' },
'proto:s' => { name => 'proto' },
'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' }
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
$self->{output} = $options{output};
$self->{http} = centreon::plugins::http->new(%options, default_backend => 'curl');
$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->{option_results}->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : '';
$self->{option_results}->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443;
$self->{option_results}->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https';
$self->{option_results}->{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} : '';
$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->{option_results}->{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 settings {
my ($self, %options) = @_;
return if (defined($self->{settings_done}));
$self->{http}->set_options(%{$self->{option_results}});
$self->{http}->add_header(key => 'Accept', value => 'application/json');
$self->{settings_done} = 1;
}
sub get_connection_info {
my ($self, %options) = @_;
return $self->{option_results}->{hostname} . ':' . $self->{option_results}->{port};
}
sub get_token {
my ($self, %options) = @_;
my $has_cache_file = $self->{cache}->read(statefile => 'storeonce_' . md5_hex($self->get_connection_info() . '_' . $self->{api_username}));
my $token = $self->{cache}->get(name => 'token');
my $md5_secret_cache = $self->{cache}->get(name => 'md5_secret');
my $md5_secret = md5_hex($self->{api_username} . $self->{api_password});
if ($has_cache_file == 0 ||
!defined($token) ||
(defined($md5_secret_cache) && $md5_secret_cache ne $md5_secret)
) {
my $json_request = {
username => $self->{api_username},
password => $self->{api_password},
grant_type => '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();
}
$self->settings();
my $content = $self->{http}->request(
method => 'POST',
url_path => '/pml/login/authenticatewithobject',
query_form_post => $encoded,
unknown_status => $self->{unknown_http_status},
warning_status => $self->{warning_http_status},
critical_status => $self->{critical_http_status},
header => ['Content-Type: application/json']
);
my $decoded;
eval {
$decoded = JSON::XS->new->utf8->decode($content);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response");
$self->{output}->option_exit();
}
$token = $decoded->{access_token};
my $datas = {
updated => time(),
token => $token,
md5_secret => $md5_secret
};
$self->{cache}->write(data => $datas);
}
return $token;
}
sub clean_token {
my ($self, %options) = @_;
my $datas = { updated => time() };
$self->{cache}->write(data => $datas);
}
sub request_api {
my ($self, %options) = @_;
$self->settings();
my $token = $self->get_token();
my ($content) = $self->{http}->request(
url_path => $options{endpoint},
get_param => $options{get_param},
header => ['Authorization: Bearer ' . $token]
);
# Maybe token is invalid. so we retry
if ($self->{http}->get_code() < 200 || $self->{http}->get_code() >= 300) {
$self->clean_token();
$token = $self->get_token();
$content = $self->{http}->request(
url_path => $options{endpoint},
get_param => $options{get_param},
header => ['Authorization: Bearer ' . $token],
unknown_status => $self->{unknown_http_status},
warning_status => $self->{warning_http_status},
critical_status => $self->{critical_http_status}
);
}
if (!defined($content) || $content eq '') {
$self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");
$self->{output}->option_exit();
}
my $decoded;
eval {
$decoded = JSON::XS->new->allow_nonref(1)->utf8->decode($content);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
$self->{output}->option_exit();
}
return $decoded;
}
1;
__END__
=head1 NAME
StoreOnce API
=head1 REST API OPTIONS
StoreOnce API
=over 8
=item B<--hostname>
Set hostname.
=item B<--port>
Port used (Default: 443)
=item B<--proto>
Specify https if needed (Default: 'https')
=item B<--api-username>
API username.
=item B<--api-password>
API password.
=item B<--timeout>
Set timeout in seconds (Default: 30).
=back
=head1 DESCRIPTION
B<custom>.
=cut

View File

@ -0,0 +1,255 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::appliances;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_disk_usage_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
return sprintf(
'disk 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},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
);
}
sub appliance_long_output {
my ($self, %options) = @_;
return sprintf(
"checking appliance '%s'",
$options{instance_value}->{name}
);
}
sub prefix_appliance_output {
my ($self, %options) = @_;
return sprintf(
"appliance '%s' ",
$options{instance_value}->{name}
);
}
sub prefix_global_output {
my ($self, %options) = @_;
return 'Number of appliances ';
}
sub prefix_service_output {
my ($self, %options) = @_;
return sprintf(
"service '%s' ",
$options{instance_value}->{service}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
{
name => 'appliances', type => 3, cb_prefix_output => 'prefix_appliance_output', cb_long_output => 'appliance_long_output', indent_long_output => ' ', message_multiple => 'All appliances are ok',
group => [
{ name => 'disk', type => 0 },
{ name => 'dedup', type => 0 },
{ name => 'services', type => 1, cb_prefix_output => 'prefix_service_output', message_multiple => 'services are ok', display_long => 1, skipped_code => { -10 => 1 } },
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'appliances-detected', display_ok => 0, nlabel => 'appliances.detected.count', set => {
key_values => [ { name => 'detected' } ],
output_template => 'detected: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{services} = [
{
label => 'service-status',
type => 2,
warning_default => '%{status} =~ /warning/i',
critical_default => '%{status} =~ /critical/i',
set => {
key_values => [
{ name => 'status' }, { name => 'service' }
],
output_template => "status: %s",
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
$self->{maps_counters}->{disk} = [
{ label => 'disk-space-usage', nlabel => 'appliance.disk.space.usage.bytes', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
closure_custom_output => $self->can('custom_disk_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'name' }
]
}
},
{ label => 'disk-space-usage-free', nlabel => 'appliance.disk.space.free.bytes', display_ok => 0, set => {
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
closure_custom_output => $self->can('custom_disk_usage_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'name' }
]
}
},
{ label => 'disk-space-usage-prct', nlabel => 'appliance.disk.space.usage.percentage', display_ok => 0, set => {
key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' }, { name => 'name' } ],
closure_custom_output => $self->can('custom_disk_usage_output'),
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'name' }
]
}
}
];
$self->{maps_counters}->{dedup} = [
{ label => 'dedup', nlabel => 'appliance.deduplication.ratio.count', set => {
key_values => [ { name => 'dedup' }, { name => 'name' } ],
output_template => 'deduplication ratio: %.2f',
perfdatas => [
{ template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'name' }
]
}
}
];
}
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-uuid:s' => { name => 'filter_uuid' },
'filter-hostname:s' => { name => 'filter_hostname' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $members = $options{custom}->request_api(endpoint => '/api/v1/management-services/federation/members');
$self->{global} = { detected => 0 };
$self->{appliances} = {};
foreach my $member (@{$members->{members}}) {
next if (defined($self->{option_results}->{filter_uuid}) && $self->{option_results}->{filter_uuid} ne '' &&
$member->{uuid} !~ /$self->{option_results}->{filter_uuid}/);
next if (defined($self->{option_results}->{filter_hostname}) && $self->{option_results}->{filter_hostname} ne '' &&
$member->{hostname} !~ /$self->{option_results}->{filter_hostname}/);
$self->{global}->{detected}++;
my $appliance = $options{custom}->request_api(endpoint => '/api/v1/data-services/dashboard/appliance/' . $member->{uuid});
$self->{appliances}->{ $member->{uuid} } = {
name => $member->{hostname},
services => {
dataServices => { service => 'dataServices', status => lc($appliance->{dataServicesStatus}) },
license => { service => 'license', status => lc($appliance->{licenseStatus}) },
userStorage => { service => 'userStorage', status => lc($appliance->{userStorageStatus}) },
hardware => { service => 'hardware', status => lc($appliance->{hardwareStatus}) },
remoteSupport => { service => 'remoteSupport', status => lc($appliance->{remoteSupportStatus}) }
},
disk => {
name => $member->{hostname},
total => $appliance->{localCapacityBytes},
used => $appliance->{localCapacityBytes} - $appliance->{localFreeBytes},
free => $appliance->{localFreeBytes},
prct_used => 100 - ($appliance->{localFreeBytes} * 100 / $appliance->{localCapacityBytes}),
prct_free => $appliance->{localFreeBytes} * 100 / $appliance->{localCapacityBytes}
},
dedup => {
name => $member->{hostname},
dedup => $appliance->{dedupeRatio}
}
};
}
}
1;
__END__
=head1 MODE
Check appliances.
=over 8
=item B<--filter-uuid>
Filter appliances by UUID.
=item B<--filter-name>
Filter appliances by hostname.
=item B<--unknown-service-status>
Set unknown threshold for status.
Can used special variables like: %{service}, %{status}
=item B<--warning-service-status>
Set warning threshold for status (Default: '%{status} =~ /warning/i').
Can used special variables like: %{service}, %{status}
=item B<--critical-service-status>
Set critical threshold for status (Default: '%{status} =~ /critical/i').
Can used special variables like: %{service}, %{status}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'appliances-detected', 'disk-space-usage, 'disk-space-usage-free',
'disk-space-usage-prct', 'dedup'.
=back
=cut

View File

@ -0,0 +1,60 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::components::drive;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking drives');
$self->{components}->{drive} = { name => 'drive', total => 0, skip => 0 };
return if ($self->check_filter(section => 'drive'));
foreach my $entry (@{$self->{subsystems}->{drive}}) {
my $instance = $entry->{name};
next if ($self->check_filter(section => 'drive', instance => $instance));
$self->{components}->{drive}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"drive '%s' status is %s",
$entry->{name},
$entry->{status}
)
);
my $exit = $self->get_severity(label => 'default', section => 'drive', value => $entry->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"drive '%s' status is %s",
$entry->{name}, $entry->{status}
)
);
}
}
}
1;

View File

@ -0,0 +1,60 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::components::driveencl;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking drive enclosures');
$self->{components}->{driveencl} = { name => 'driveencl', total => 0, skip => 0 };
return if ($self->check_filter(section => 'driveencl'));
foreach my $entry (@{$self->{subsystems}->{driveEnclosure}}) {
my $instance = $entry->{name};
next if ($self->check_filter(section => 'drive', instance => $instance));
$self->{components}->{driveencl}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"drive enclosure '%s' status is %s",
$entry->{name},
$entry->{status}
)
);
my $exit = $self->get_severity(label => 'default', section => 'driveencl', value => $entry->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"drive enclosure '%s' status is %s",
$entry->{name}, $entry->{status}
)
);
}
}
}
1;

View File

@ -0,0 +1,84 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::components::fan;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking fans');
$self->{components}->{fan} = { name => 'fan', total => 0, skip => 0 };
return if ($self->check_filter(section => 'fan'));
foreach my $entry (@{$self->{subsystems}->{fan}}) {
my $instance = $entry->{name};
next if ($self->check_filter(section => 'fan', instance => $instance));
$self->{components}->{fan}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"fan '%s' status is %s [speed: %s]",
$entry->{name},
$entry->{status},
$entry->{speed}
)
);
my $exit = $self->get_severity(label => 'default', section => 'fan', value => $entry->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"fan '%s' status is %s",
$entry->{name}, $entry->{status}
)
);
}
next if (!defined($entry->{speed}));
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan.speed', instance => $instance, value => $entry->{speed});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit2,
short_msg => sprintf(
"fan '%s' '%s' speed is %s rpm",
$entry->{name},
$entry->{speed}
)
);
}
$self->{output}->perfdata_add(
nlabel => 'hardware.fan.speed.rpm',
unit => 'rpm',
instances => $entry->{name},
value => $entry->{speed},
warning => $warn,
critical => $crit,
min => 0
);
}
}
1;

View File

@ -0,0 +1,60 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::components::iomodule;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking iomodules');
$self->{components}->{iomodule} = { name => 'iomodule', total => 0, skip => 0 };
return if ($self->check_filter(section => 'iomodule'));
foreach my $entry (@{$self->{subsystems}->{IOmodule}}) {
my $instance = $entry->{name};
next if ($self->check_filter(section => 'iomodule', instance => $instance));
$self->{components}->{iomodule}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"iomodule '%s' status is %s",
$entry->{name},
$entry->{status}
)
);
my $exit = $self->get_severity(label => 'default', section => 'iomodule', value => $entry->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"iomodule '%s' status is %s",
$entry->{name}, $entry->{status}
)
);
}
}
}
1;

View File

@ -0,0 +1,60 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::components::pool;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking pools');
$self->{components}->{pool} = { name => 'pool', total => 0, skip => 0 };
return if ($self->check_filter(section => 'pool'));
foreach my $entry (@{$self->{subsystems}->{pool}}) {
my $instance = $entry->{name};
next if ($self->check_filter(section => 'pool', instance => $instance));
$self->{components}->{drive}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"pool '%s' status is %s",
$entry->{name},
$entry->{status}
)
);
my $exit = $self->get_severity(label => 'default', section => 'pool', value => $entry->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"pool '%s' status is %s",
$entry->{name}, $entry->{status}
)
);
}
}
}
1;

View File

@ -0,0 +1,60 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::components::psu;
use strict;
use warnings;
sub load {}
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'));
foreach my $entry (@{$self->{subsystems}->{powerSupply}}) {
my $instance = $entry->{name};
next if ($self->check_filter(section => 'psu', instance => $instance));
$self->{components}->{psu}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"power supply '%s' status is %s",
$entry->{name},
$entry->{status}
)
);
my $exit = $self->get_severity(label => 'default', section => 'psu', value => $entry->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"power supply '%s' status is %s",
$entry->{name}, $entry->{status}
)
);
}
}
}
1;

View File

@ -0,0 +1,93 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::components::temperature;
use strict;
use warnings;
sub load {}
sub check {
my ($self) = @_;
$self->{output}->output_add(long_msg => 'checking temperatures');
$self->{components}->{temperature} = { name => 'temperature', total => 0, skip => 0 };
return if ($self->check_filter(section => 'temperature'));
foreach my $entry (@{$self->{subsystems}->{tempSensor}}) {
my $instance = $entry->{name};
next if ($self->check_filter(section => 'temperature', instance => $instance));
$self->{components}->{temperature}->{total}++;
$self->{output}->output_add(
long_msg => sprintf(
"temperature '%s' status is %s [current: %s]",
$entry->{name},
$entry->{status},
$entry->{temperature}
)
);
my $exit = $self->get_severity(label => 'default', section => 'temperature', value => $entry->{status});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit,
short_msg => sprintf(
"temperature '%s' status is %s",
$entry->{name}, $entry->{status}
)
);
}
next if (!defined($entry->{temperature}));
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $entry->{temperature});
if ($checked == 0) {
my $warn_th = defined($entry->{upperNonCriticalThreshold}) ? $entry->{upperNonCriticalThreshold} : '';
my $crit_th = defined($entry->{upperCriticalThreshold}) ? $entry->{upperCriticalThreshold} : '';
$self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th);
$self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th);
$warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance);
$crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance)
}
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(
severity => $exit2,
short_msg => sprintf(
"temperature '%s' is %s degree centigrade",
$entry->{name},
$entry->{temperature}
)
);
}
$self->{output}->perfdata_add(
nlabel => 'hardware.temperature.celsius',,
unit => 'C',
instances => $entry->{name},
value => $entry->{temperature},
warning => $warn,
critical => $crit
);
}
}
1;

View File

@ -0,0 +1,149 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::hardwarestorage;
use base qw(centreon::plugins::templates::hardware);
use strict;
use warnings;
sub set_system {
my ($self, %options) = @_;
$self->{regexp_threshold_numeric_check_section_option} = '^(?:fan\.speed|temperature)$';
$self->{cb_hook2} = 'snmp_execute';
$self->{thresholds} = {
default => [
['ok', 'OK'],
['missing', 'OK'],
['degraded', 'OK'],
['critical', 'CRITICAL']
]
};
$self->{components_path} = 'storage::hp::storeonce::4::restapi::mode::components';
$self->{components_module} = ['drive', 'driveencl', 'fan', 'iomodule', 'pool', 'psu', 'temperature'];
}
sub browse_components {
my ($self, %options) = @_;
foreach my $comp (@{${$options{components}}}) {
if ($comp->{name} =~ /tempSensor|pool|driveEnclosure|powerSupply|IOmodule|fan|drive/) {
my $entry = {
name => join(':', @{$options{path}}, (defined($comp->{value}->{location}) ? $comp->{value}->{location} : $comp->{value}->{name})),
status => $comp->{value}->{status}
};
if ($comp->{name} eq 'tempSensor') {
$entry->{temperature} = defined($comp->{value}->{temperature}) && $comp->{value}->{temperature} =~ /^\s*(\d+)\s*C/ ? $1 : undef;
$entry->{upperNonCriticalThreshold} = defined($comp->{value}->{upperNonCriticalThreshold}) && $comp->{value}->{upperNonCriticalThreshold} =~ /^\s*(\d+)\s*C/ ? $1 : undef;
$entry->{upperCriticalThreshold} = defined($comp->{value}->{upperCriticalThreshold}) && $comp->{value}->{upperCriticalThreshold} =~ /^\s*(\d+)\s*C/ ? $1 : undef;
} elsif ($comp->{name} eq 'fan') {
$entry->{speed} = defined($comp->{value}->{speed}) && $comp->{value}->{speed} =~ /^\s*(\d+)\s*RPM/i ? $1 : undef;
}
push @{$self->{subsystems}->{ $comp->{name} }}, $entry;
}
$self->browse_components(
components => \$comp->{value}->{component},
path => [@{$options{path}}, (defined($comp->{value}->{location}) ? $comp->{value}->{location} : $comp->{value}->{name})]
);
}
}
sub snmp_execute {
my ($self, %options) = @_;
$self->{subsystems} = {
tempSensor => [],
pool => [],
driveEnclosure => [],
powerSupply => [],
IOmodule => [],
fan => [],
drive => []
};
my $storages = $options{custom}->request_api(endpoint => '/hwmonitor/storage');
foreach my $storage (@{$storages->{storageCluster}}) {
my $sc_infos = $options{custom}->request_api(endpoint => '/hwmonitor/storage/' . $storage->{name});
$self->browse_components(
components => \$sc_infos->{hardwareReportResponse}->{hardwareReport}->{component}->[0]->{value}->{component},
path => [$storage->{name}]
);
}
}
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 => {});
return $self;
}
1;
__END__
=head1 MODE
Check hardware.
=over 8
=item B<--component>
Which component to check.
Can be: 'drive', 'driveencl', 'fan', 'iomodule', 'pool', 'psu', 'temperature'.
=item B<--filter>
Exclude some parts (comma seperated list) (Example: --filter=psu)
Can also exclude specific instance: --filter=fan,fan slot 1
=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,status,regexp)
It used before default thresholds (order stays).
Example: --threshold-overload='fan,WARNING,missing'
=item B<--warning>
Set warning threshold for 'fan.speed' (syntax: section,[instance,]status,regexp)
Example: --warning='fan.speed,.*,10000'
=item B<--critical>
Set critical threshold for 'fan.speed' (syntax: section,[instance,]status,regexp)
Example: --critical='fan.speed,.*,11000'
=back
=cut

View File

@ -0,0 +1,110 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::listappliances;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $members = $options{custom}->request_api(endpoint => '/api/v1/management-services/federation/members');
my $results = [];
foreach my $member (@{$members->{members}}) {
push @$results, $member;
}
return $results;
}
sub run {
my ($self, %options) = @_;
my $results = $self->manage_selection(%options);
foreach (@$results) {
$self->{output}->output_add(
long_msg => sprintf(
'[uuid: %s][hostname: %s][serial: %s]',
$_->{uuid},
$_->{hostname},
$_->{serialNumber}
)
);
}
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List appliances:'
);
$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 => ['uuid', 'hostname', 'serial']);
}
sub disco_show {
my ($self, %options) = @_;
my $results = $self->manage_selection(%options);
foreach (@$results) {
$self->{output}->add_disco_entry(
uuid => $_->{uuid},
hostname => $_->{hostname},
serial => $_->{serialNumber}
);
}
}
1;
__END__
=head1 MODE
List appliances.
=over 8
=back
=cut

View File

@ -0,0 +1,118 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::liststores;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $members = $options{custom}->request_api(endpoint => '/api/v1/data-services/cat/stores');
my $results = [];
foreach my $member (@{$members->{members}}) {
push @$results, $member;
}
return $results;
}
my %mapping_health_level = (
0 => 'unknown',
1 => 'ok',
2 => 'information',
3 => 'warning',
4 => 'critical'
);
sub run {
my ($self, %options) = @_;
my $results = $self->manage_selection(%options);
foreach (@$results) {
$self->{output}->output_add(
long_msg => sprintf(
'[id: %s][name: %s][health: %s]',
$_->{id},
$_->{name},
$mapping_health_level{ $_->{healthLevel} }
)
);
}
$self->{output}->output_add(
severity => 'OK',
short_msg => 'List stores:'
);
$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 => ['id', 'name', 'health']);
}
sub disco_show {
my ($self, %options) = @_;
my $results = $self->manage_selection(%options);
foreach (@$results) {
$self->{output}->add_disco_entry(
id => $_->{id},
name => $_->{name},
health => $mapping_health_level{ $_->{healthLevel} }
);
}
}
1;
__END__
=head1 MODE
List catalyst stores.
=over 8
=back
=cut

View File

@ -0,0 +1,224 @@
#
# Copyright 2022 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::hp::storeonce::4::restapi::mode::stores;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub store_long_output {
my ($self, %options) = @_;
return sprintf(
"checking catalyst store '%s'",
$options{instance_value}->{name}
);
}
sub store_appliance_output {
my ($self, %options) = @_;
return sprintf(
"catalyst store '%s' ",
$options{instance_value}->{name}
);
}
sub prefix_global_output {
my ($self, %options) = @_;
return 'Number of catalyst stores ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
{
name => 'stores', type => 3, cb_prefix_output => 'prefix_store_output', cb_long_output => 'store_long_output', indent_long_output => ' ', message_multiple => 'All catalyst stores are ok',
group => [
{ name => 'health', type => 0 },
{ name => 'space', type => 0 },
{ name => 'dedup', type => 0 }
]
}
];
$self->{maps_counters}->{global} = [
{ label => 'stores-detected', display_ok => 0, nlabel => 'stores.detected.count', set => {
key_values => [ { name => 'detected' } ],
output_template => 'detected: %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{health} = [
{
label => 'health',
type => 2,
unknown_default => '%{health} =~ /unknown/i',
warning_default => '%{health} =~ /warning/i',
critical_default => '%{health} =~ /critical/i',
set => {
key_values => [ { name => 'health' }, { name => 'name' } ],
output_template => 'health: %s',
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
$self->{maps_counters}->{space} = [
{ label => 'disk-space-usage', nlabel => 'store.disk.space.usage.bytes', set => {
key_values => [ { name => 'disk_used' }, { name => 'name' } ],
output_template => 'disk space used: %s%s',
output_change_bytes => 1,
perfdatas => [
{ template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'name' }
]
}
},
{ label => 'user-space-usage', nlabel => 'store.user.space.usage.bytes', set => {
key_values => [ { name => 'user_used' }, { name => 'name' } ],
output_template => 'user space used: %s%s',
output_change_bytes => 1,
perfdatas => [
{ template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'name' }
]
}
}
];
$self->{maps_counters}->{dedup} = [
{ label => 'dedup', nlabel => 'store.deduplication.ratio.count', set => {
key_values => [ { name => 'dedup' }, { name => 'name' } ],
output_template => 'deduplication ratio: %.2f',
perfdatas => [
{ template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'name' }
]
}
}
];
}
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-id:s' => { name => 'filter_id' },
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
my %mapping_health_level = (
0 => 'unknown',
1 => 'ok',
2 => 'information',
3 => 'warning',
4 => 'critical'
);
sub manage_selection {
my ($self, %options) = @_;
my $members = $options{custom}->request_api(endpoint => '/api/v1/data-services/cat/stores');
$self->{global} = { detected => 0 };
$self->{stores} = {};
foreach my $member (@{$members->{members}}) {
next if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' &&
$member->{id} !~ /$self->{option_results}->{filter_id}/);
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$member->{name} !~ /$self->{option_results}->{filter_name}/);
$self->{global}->{detected}++;
$self->{stores}->{ $member->{id} } = {
name => $member->{name},
health => {
name => $member->{name},
health => $mapping_health_level{ $member->{healthLevel} }
},
space => {
name => $member->{name},
disk_used => $member->{diskBytes},
user_used => $member->{userBytes}
},
dedup => {
name => $member->{name},
dedup => $member->{dedupeRatio}
}
};
}
}
1;
__END__
=head1 MODE
Check catalyst stores.
=over 8
=item B<--filter-id>
Filter stores by id.
=item B<--filter-name>
Filter stores by hostname.
=item B<--unknown-health>
Set unknown threshold for status (Default: '%{health} =~ /unknown/i').
Can used special variables like: %{health}, %{name}
=item B<--warning-health>
Set warning threshold for status (Default: '%{health} =~ /warning/i').
Can used special variables like: %{health}, %{name}
=item B<--critical-health>
Set critical threshold for status (Default: '%{health} =~ /critical/i').
Can used special variables like: %{health}, %{name}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'stores-detected', 'disk-space-usage, 'user-space-usage', 'dedup'.
=back
=cut

View File

@ -0,0 +1,52 @@
#
# Copyright 2022 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::hp::storeonce::4::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->{modes} = {
'appliances' => 'storage::hp::storeonce::4::restapi::mode::appliances',
'hardware-storage' => 'storage::hp::storeonce::4::restapi::mode::hardwarestorage',
'list-appliances' => 'storage::hp::storeonce::4::restapi::mode::listappliances',
'list-stores' => 'storage::hp::storeonce::4::restapi::mode::liststores',
'stores' => 'storage::hp::storeonce::4::restapi::mode::stores'
};
$self->{custom_modes}->{api} = 'storage::hp::storeonce::4::restapi::custom::api';
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Hp Storeonce 4.x through HTTP/REST API.
=cut