diff --git a/storage/purestorage/restapi/mode/hardware.pm b/storage/purestorage/restapi/mode/hardware.pm new file mode 100644 index 000000000..fc95843d3 --- /dev/null +++ b/storage/purestorage/restapi/mode/hardware.pm @@ -0,0 +1,162 @@ +# +# Copyright 2017 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::purestorage::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} = '^(entity)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature)$'; + + $self->{cb_hook2} = 'restapi_execute'; + + $self->{thresholds} = { + entity => [ + ['ok', 'OK'], + ['critical', 'CRITICAL'], + ['degraded', 'WARNING'], + ['device_off', 'WARNING'], + ['identifying', 'OK'], + ['not_installed', 'OK'], + ['unknown', 'UNKNOWN'], + ], + }; + + $self->{components_path} = 'storage::purestorage::restapi::mode::components'; + $self->{components_module} = ['entity']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub restapi_execute { + my ($self, %options) = @_; + + $self->{results} = $options{custom}->get_object(path => '/hardware'); +} + +1; + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'entity'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=entity,CT1.FC0 + +=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='entity,OK,device_off' + +=item B<--warning> + +Set warning threshold for 'temperature', 'fan' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,40' + +=item B<--critical> + +Set critical threshold for 'temperature', 'fan' (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,50' + +=back + +=cut + +package storage::purestorage::restapi::mode::components::entity; + +use strict; +use warnings; + +sub load { } + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking entity"); + $self->{components}->{entity} = {name => 'entity', total => 0, skip => 0}; + return if ($self->check_filter(section => 'entity')); + + # [ + # {"status": "ok", "slot": null, "name": "CH0", "index": 0, "identify": "off", "voltage": null, "details": null, "speed": null, "temperature": null}, + # ... + # ] + + foreach my $entry (@{$self->{results}}) { + my $instance = $entry->{name}; + + next if ($self->check_filter(section => 'entity', instance => $instance)); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add(long_msg => sprintf("entity '%s' status is '%s' [instance = %s]", + $entry->{name}, $entry->{status}, $instance)); + my $exit = $self->get_severity(section => 'entity', value => $entry->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("entity '%s' status is '%s'", $entry->{name}, $entry->{status})); + } + + if (defined($entry->{temperature}) && $entry->{temperature} =~ /[0-9]/) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $entry->{temperature}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("entity '%s' temperature is %s C", $entry->{name}, $entry->{temperature})); + } + $self->{output}->perfdata_add(label => 'temperature_' . $entry->{name}, unit => 'C', + value => $entry->{temperature}, + warning => $warn, + critical => $crit, min => 0 + ); + } + } +} + +1; diff --git a/storage/purestorage/restapi/mode/listvolumes.pm b/storage/purestorage/restapi/mode/listvolumes.pm new file mode 100644 index 000000000..19c0cde56 --- /dev/null +++ b/storage/purestorage/restapi/mode/listvolumes.pm @@ -0,0 +1,93 @@ +# +# Copyright 2017 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::purestorage::restapi::mode::listvolumes; + +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; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{volumes} = $options{custom}->get_object(path => '/volume'); +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (@{$self->{volumes}}) { + $self->{output}->output_add(long_msg => "[name = '" . $_->{name} . "']"); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List volumes:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach (@{$self->{volumes}}) { + $self->{output}->add_disco_entry(name => $_->{name}); + } +} + +1; + +__END__ + +=head1 MODE + +List volumes. + +=over 8 + +=back + +=cut + diff --git a/storage/purestorage/restapi/mode/volumeusage.pm b/storage/purestorage/restapi/mode/volumeusage.pm index b1c5964f1..e48b3d7e5 100644 --- a/storage/purestorage/restapi/mode/volumeusage.pm +++ b/storage/purestorage/restapi/mode/volumeusage.pm @@ -179,13 +179,13 @@ sub manage_selection { #] foreach my $entry (@{$result}) { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $entry->{volume_name} !~ /$self->{option_results}->{filter_name}/) { + $entry->{name} !~ /$self->{option_results}->{filter_name}/) { $self->{output}->output_add(long_msg => "skipping '" . $entry->{volume_name} . "': no matching filter.", debug => 1); next; } - $self->{volume}->{$entry->{volume_name}} = { - display => $entry->{volume_name}, + $self->{volume}->{$entry->{name}} = { + display => $entry->{name}, %{$entry}, }; } diff --git a/storage/purestorage/restapi/plugin.pm b/storage/purestorage/restapi/plugin.pm index 75525c278..d64b3364a 100644 --- a/storage/purestorage/restapi/plugin.pm +++ b/storage/purestorage/restapi/plugin.pm @@ -31,6 +31,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( + 'hardware' => 'storage::purestorage::restapi::mode::hardware', + 'list-volumes' => 'storage::purestorage::restapi::mode::listvolumes', 'volume-usage' => 'storage::purestorage::restapi::mode::volumeusage', );