From b9dbef83c1714e0e09be375fd72148f44e40dcfb Mon Sep 17 00:00:00 2001 From: qgarnier Date: Thu, 30 Sep 2021 12:21:52 +0200 Subject: [PATCH] add(plugin): Dell PowerStore rest api (#3160) --- storage/dell/powerstore/restapi/custom/api.pm | 209 ++++++++++++++++++ .../dell/powerstore/restapi/mode/alerts.pm | 196 ++++++++++++++++ .../restapi/mode/components/appliance.pm | 37 ++++ .../restapi/mode/components/battery.pm | 37 ++++ .../restapi/mode/components/dimm.pm | 37 ++++ .../restapi/mode/components/disk.pm | 42 ++++ .../restapi/mode/components/enclosure.pm | 37 ++++ .../powerstore/restapi/mode/components/fan.pm | 37 ++++ .../restapi/mode/components/iomodule.pm | 37 ++++ .../restapi/mode/components/node.pm | 37 ++++ .../powerstore/restapi/mode/components/psu.pm | 37 ++++ .../restapi/mode/components/resources.pm | 67 ++++++ .../powerstore/restapi/mode/components/sfp.pm | 37 ++++ .../dell/powerstore/restapi/mode/hardware.pm | 107 +++++++++ storage/dell/powerstore/restapi/plugin.pm | 50 +++++ 15 files changed, 1004 insertions(+) create mode 100644 storage/dell/powerstore/restapi/custom/api.pm create mode 100644 storage/dell/powerstore/restapi/mode/alerts.pm create mode 100644 storage/dell/powerstore/restapi/mode/components/appliance.pm create mode 100644 storage/dell/powerstore/restapi/mode/components/battery.pm create mode 100644 storage/dell/powerstore/restapi/mode/components/dimm.pm create mode 100644 storage/dell/powerstore/restapi/mode/components/disk.pm create mode 100644 storage/dell/powerstore/restapi/mode/components/enclosure.pm create mode 100644 storage/dell/powerstore/restapi/mode/components/fan.pm create mode 100644 storage/dell/powerstore/restapi/mode/components/iomodule.pm create mode 100644 storage/dell/powerstore/restapi/mode/components/node.pm create mode 100644 storage/dell/powerstore/restapi/mode/components/psu.pm create mode 100644 storage/dell/powerstore/restapi/mode/components/resources.pm create mode 100644 storage/dell/powerstore/restapi/mode/components/sfp.pm create mode 100644 storage/dell/powerstore/restapi/mode/hardware.pm create mode 100644 storage/dell/powerstore/restapi/plugin.pm diff --git a/storage/dell/powerstore/restapi/custom/api.pm b/storage/dell/powerstore/restapi/custom/api.pm new file mode 100644 index 000000000..85ea6cdb9 --- /dev/null +++ b/storage/dell/powerstore/restapi/custom/api.pm @@ -0,0 +1,209 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use JSON::XS; + +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); + + 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} : 443; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 50; + $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->{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(); + } + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{api_username}; + $self->{option_results}->{password} = $self->{api_password}; +} + +sub settings { + my ($self, %options) = @_; + + return if (defined($self->{settings_done})); + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{http}->set_options(%{$self->{option_results}}); + $self->{settings_done} = 1; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub get_port { + my ($self, %options) = @_; + + return $self->{port}; +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + my $content = $self->{http}->request( + url_path => $options{endpoint}, + get_param => $options{get_param}, + 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->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 + +Dell PowerStore Rest API + +=head1 REST API OPTIONS + +Dell PowerStore Rest 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: 50). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/storage/dell/powerstore/restapi/mode/alerts.pm b/storage/dell/powerstore/restapi/mode/alerts.pm new file mode 100644 index 000000000..f1242f891 --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/alerts.pm @@ -0,0 +1,196 @@ +# +# Copyright 2018 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::dell::powerstore::restapi::mode::alerts; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::statefile; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + "alert [severity: %s] [name: %s] [resource: %s] %s", + $self->{result_values}->{severity}, + $self->{result_values}->{name}, + $self->{result_values}->{resource}, + $self->{result_values}->{timeraised} + ); +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Alerts severity '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, + { name => 'alarms', type => 2, message_multiple => '0 alerts detected', format_output => '%s alerts detected', display_counter_problem => { nlabel => 'alerts.problems.current.count', min => 0 }, + group => [ { name => 'alarm', skipped_code => { -11 => 1 } } ] + } + ]; + + $self->{maps_counters}->{global} = []; + foreach ('none', 'info', 'minor', 'major', 'critical') { + push @{$self->{maps_counters}->{global}}, { + label => 'severity-' . $_, nlabel => 'alerts.severity.' . $_ . '.count', display_ok => 0, set => { + key_values => [ { name => $_ } ], + output_template => $_ . ': %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + }; + } + + $self->{maps_counters}->{alarm} = [ + { + label => 'status', + type => 2, + warning_default => '%{severity} =~ /minor/i', + critical_default => '%{severity} =~ /major|critical/i', + set => { + key_values => [ + { name => 'resource' }, { name => 'name' }, + { name => 'severity' }, { name => 'timeraised' } + ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; +} + +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' }, + 'memory' => { name => 'memory' } + }); + + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->check_options(%options); + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { + 'none' => 0, 'info' => 0, 'minor' => 0, 'major' => 0, 'critical' => 0 + }; + $self->{alarms}->{global} = { alarm => {} }; + my $results = $options{custom}->request_api( + endpoint => '/api/rest/alert', + get_param => ['select=id,name,severity,state,resource_name,generated_timestamp'] + ); + + my $alerts_mem; + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->read(statefile => 'dell_powerstore_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port(). '_' . $self->{mode}); + $alerts_mem = $self->{statefile_cache}->get(name => 'alerts'); + } + + foreach my $entry (@$results) { + next if ($entry->{state} eq 'CLEARED'); + + if (defined($self->{option_results}->{memory})) { + if (defined($alerts_mem) && defined($alerts_mem->{ $entry->{id} })) { + next; + } + $alerts_mem->{ $entry->{id} } = 1; + } + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $entry->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $entry->{name} . "': no matching filter.", debug => 1); + next; + } + + $self->{global}->{ lc($entry->{severity}) }++; + $self->{alarms}->{global}->{alarm}->{ $entry->{id} } = { + resource => $entry->{resource_name}, + name => $entry->{name}, + severity => lc($entry->{severity}), + timeraised => $entry->{generated_timestamp} + }; + } + + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->write(data => { alerts => $alerts_mem }); + } +} + +1; + +__END__ + +=head1 MODE + +Check alerts. + +=over 8 + +=item B<--filter-name> + +Filter alerts by name (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{severity} =~ /minor/i') +Can used special variables like: %{severity}, %{resource}, %{name}, %{timeraised} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{severity} =~ /major|critical/i'). +Can used special variables like: %{severity}, %{resource}, %{name}, %{timeraised} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'severity-none', 'severity-info', 'severity-minor', 'severity-major', 'severity-critical'. + +=item B<--memory> + +Only check new alarms. + +=back + +=cut diff --git a/storage/dell/powerstore/restapi/mode/components/appliance.pm b/storage/dell/powerstore/restapi/mode/components/appliance.pm new file mode 100644 index 000000000..2267af394 --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/components/appliance.pm @@ -0,0 +1,37 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::components::appliance; + +use strict; +use warnings; +use storage::dell::powerstore::restapi::mode::components::resources qw(check_component); + +sub check { + my ($self) = @_; + + check_component( + $self, + label => 'appliance', + component => 'Appliance' + ); +} + +1; diff --git a/storage/dell/powerstore/restapi/mode/components/battery.pm b/storage/dell/powerstore/restapi/mode/components/battery.pm new file mode 100644 index 000000000..60f6f19dc --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/components/battery.pm @@ -0,0 +1,37 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::components::battery; + +use strict; +use warnings; +use storage::dell::powerstore::restapi::mode::components::resources qw(check_component); + +sub check { + my ($self) = @_; + + check_component( + $self, + label => 'battery', + component => 'Battery' + ); +} + +1; diff --git a/storage/dell/powerstore/restapi/mode/components/dimm.pm b/storage/dell/powerstore/restapi/mode/components/dimm.pm new file mode 100644 index 000000000..531c2f386 --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/components/dimm.pm @@ -0,0 +1,37 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::components::dimm; + +use strict; +use warnings; +use storage::dell::powerstore::restapi::mode::components::resources qw(check_component); + +sub check { + my ($self) = @_; + + check_component( + $self, + label => 'dimm', + component => 'DIMM' + ); +} + +1; diff --git a/storage/dell/powerstore/restapi/mode/components/disk.pm b/storage/dell/powerstore/restapi/mode/components/disk.pm new file mode 100644 index 000000000..69f73fe44 --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/components/disk.pm @@ -0,0 +1,42 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::components::disk; + +use strict; +use warnings; +use storage::dell::powerstore::restapi::mode::components::resources qw(check_component); + +sub check { + my ($self) = @_; + + check_component( + $self, + label => 'disk', + component => 'Drive' + ); + check_component( + $self, + label => 'disk', + component => 'M2_Drive' + ); +} + +1; diff --git a/storage/dell/powerstore/restapi/mode/components/enclosure.pm b/storage/dell/powerstore/restapi/mode/components/enclosure.pm new file mode 100644 index 000000000..f0f231634 --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/components/enclosure.pm @@ -0,0 +1,37 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::components::enclosure; + +use strict; +use warnings; +use storage::dell::powerstore::restapi::mode::components::resources qw(check_component); + +sub check { + my ($self) = @_; + + check_component( + $self, + label => 'enclosure', + component => 'Base_Enclosure' + ); +} + +1; diff --git a/storage/dell/powerstore/restapi/mode/components/fan.pm b/storage/dell/powerstore/restapi/mode/components/fan.pm new file mode 100644 index 000000000..35c4101e0 --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/components/fan.pm @@ -0,0 +1,37 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::components::fan; + +use strict; +use warnings; +use storage::dell::powerstore::restapi::mode::components::resources qw(check_component); + +sub check { + my ($self) = @_; + + check_component( + $self, + label => 'fan', + component => 'Fan' + ); +} + +1; diff --git a/storage/dell/powerstore/restapi/mode/components/iomodule.pm b/storage/dell/powerstore/restapi/mode/components/iomodule.pm new file mode 100644 index 000000000..340200680 --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/components/iomodule.pm @@ -0,0 +1,37 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::components::iomodule; + +use strict; +use warnings; +use storage::dell::powerstore::restapi::mode::components::resources qw(check_component); + +sub check { + my ($self) = @_; + + check_component( + $self, + label => 'iomodule', + component => 'IO_Module' + ); +} + +1; diff --git a/storage/dell/powerstore/restapi/mode/components/node.pm b/storage/dell/powerstore/restapi/mode/components/node.pm new file mode 100644 index 000000000..d42655cff --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/components/node.pm @@ -0,0 +1,37 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::components::node; + +use strict; +use warnings; +use storage::dell::powerstore::restapi::mode::components::resources qw(check_component); + +sub check { + my ($self) = @_; + + check_component( + $self, + label => 'node', + component => 'Node' + ); +} + +1; diff --git a/storage/dell/powerstore/restapi/mode/components/psu.pm b/storage/dell/powerstore/restapi/mode/components/psu.pm new file mode 100644 index 000000000..c37955252 --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/components/psu.pm @@ -0,0 +1,37 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::components::psu; + +use strict; +use warnings; +use storage::dell::powerstore::restapi::mode::components::resources qw(check_component); + +sub check { + my ($self) = @_; + + check_component( + $self, + label => 'psu', + component => 'Power_Supply' + ); +} + +1; diff --git a/storage/dell/powerstore/restapi/mode/components/resources.pm b/storage/dell/powerstore/restapi/mode/components/resources.pm new file mode 100644 index 000000000..ca3bdfc4b --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/components/resources.pm @@ -0,0 +1,67 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::components::resources; + +use strict; +use warnings; +use Exporter; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(check_component); + +sub check_component { + my ($self, %options) = @_; + + if (!defined($self->{components}->{ $options{label} })) { + $self->{output}->output_add(long_msg => 'checking ' . $options{label}); + $self->{components}->{ $options{label} } = { name => $options{label}, total => 0, skip => 0 }; + } + return if ($self->check_filter(section => $options{label})); + + foreach my $entry (@{$self->{results}}) { + next if (!defined($entry->{type}) || $entry->{type} ne $options{component}); + next if (!defined($entry->{lifecycle_state})); + my $instance = $entry->{id}; + + next if ($self->check_filter(section => $options{label}, instance => $instance)); + next if ($entry->{lifecycle_state} =~ /empty/i && + $self->absent_problem(section => $options{label}, instance => $instance)); + + $self->{components}->{ $options{label} }->{total}++; + + $self->{output}->output_add( + long_msg => sprintf( + "%s '%s' status is '%s' [instance: %s]", + $options{label}, $entry->{name}, $entry->{lifecycle_state}, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => $options{label}, value => $entry->{lifecycle_state}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("%s '%s' status is '%s'", $options{label}, $entry->{name}, $entry->{lifecycle_state}) + ); + } + } +} + +1; diff --git a/storage/dell/powerstore/restapi/mode/components/sfp.pm b/storage/dell/powerstore/restapi/mode/components/sfp.pm new file mode 100644 index 000000000..45070c3d9 --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/components/sfp.pm @@ -0,0 +1,37 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::components::sfp; + +use strict; +use warnings; +use storage::dell::powerstore::restapi::mode::components::resources qw(check_component); + +sub check { + my ($self) = @_; + + check_component( + $self, + label => 'sfp', + component => 'SFP' + ); +} + +1; diff --git a/storage/dell/powerstore/restapi/mode/hardware.pm b/storage/dell/powerstore/restapi/mode/hardware.pm new file mode 100644 index 000000000..f4a375770 --- /dev/null +++ b/storage/dell/powerstore/restapi/mode/hardware.pm @@ -0,0 +1,107 @@ +# +# Copyright 2021 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::dell::powerstore::restapi::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{cb_hook1} = 'init_custom'; + + $self->{thresholds} = { + default => [ + ['Uninitialized', 'OK'], + ['Healthy', 'OK'], + ['Initializing', 'OK'], + ['Failed', 'CRITICAL'], + ['Disconnected', 'OK'], + ['Prepare_Failed', 'CRITICAL'], + ['Trigger_Update', 'OK'], + ['Empty', 'OK'] + ] + }; + + $self->{components_exec_load} = 0; + + $self->{components_path} = 'storage::dell::powerstore::restapi::mode::components'; + $self->{components_module} = ['appliance', 'battery', 'dimm', 'disk', 'enclosure', 'fan', 'node', 'iomodule', 'psu', 'sfp']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, no_performance => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub init_custom { + my ($self, %options) = @_; + + $self->{results} = $options{custom}->request_api( + endpoint => '/api/rest/hardware', + get_param => ['select=*'] + ); +} + +1; + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'appliance', 'battery', 'dimm', 'disk', 'enclosure', 'fan', 'node', 'iomodule', 'psu', 'sfp'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter='disk,26018c5b69264a868e49119eec95b0a9' + +=item B<--absent-problem> + +Return an error if an entity is 'Empty' (default is skipping) +Can be specific or global: --absent-problem="fan,c41c5a99937e4953a180c65756f303f6" + +=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='disk,CRITICAL,Uninitialized' + +=back + +=cut diff --git a/storage/dell/powerstore/restapi/plugin.pm b/storage/dell/powerstore/restapi/plugin.pm new file mode 100644 index 000000000..ae4e1b184 --- /dev/null +++ b/storage/dell/powerstore/restapi/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2021 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::dell::powerstore::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} = '0.1'; + $self->{modes} = { + 'alerts' => 'storage::dell::powerstore::restapi::mode::alerts', + 'hardware' => 'storage::dell::powerstore::restapi::mode::hardware' + }; + + $self->{custom_modes}->{api} = 'storage::dell::powerstore::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Dell PowerStore using Rest API. + +=cut