| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package storage::emc::xtremio::restapi::mode::ssdendurance; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub new { |
| 29 |
my ($class, %options) = @_; |
| 30 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 31 |
bless $self, $class; |
| 32 |
|
| 33 |
$options{options}->add_options(arguments => |
| 34 |
{ |
| 35 |
"filter:s@" => { name => 'filter' }, |
| 36 |
"warning:s" => { name => 'warning' }, |
| 37 |
"critical:s" => { name => 'critical' }, |
| 38 |
}); |
| 39 |
|
| 40 |
return $self; |
| 41 |
} |
| 42 |
|
| 43 |
sub check_options { |
| 44 |
my ($self, %options) = @_; |
| 45 |
$self->SUPER::init(%options); |
| 46 |
|
| 47 |
$self->{filter} = []; |
| 48 |
foreach my $val (@{$self->{option_results}->{filter}}) { |
| 49 |
next if (!defined($val) || $val eq ''); |
| 50 |
my @values = split (/,/, $val); |
| 51 |
push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; |
| 52 |
} |
| 53 |
|
| 54 |
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { |
| 55 |
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); |
| 56 |
$self->{output}->option_exit(); |
| 57 |
} |
| 58 |
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { |
| 59 |
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); |
| 60 |
$self->{output}->option_exit(); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
sub run { |
| 65 |
my ($self, %options) = @_; |
| 66 |
my $xtremio = $options{custom}; |
| 67 |
|
| 68 |
my $urlbase = '/api/json/types/'; |
| 69 |
my @items = $xtremio->get_items( |
| 70 |
url => $urlbase, |
| 71 |
obj => 'ssds' |
| 72 |
); |
| 73 |
|
| 74 |
$self->{output}->output_add( |
| 75 |
severity => 'OK', |
| 76 |
short_msg => 'All SSDs Endurance are OK' |
| 77 |
); |
| 78 |
|
| 79 |
foreach my $item (@items) { |
| 80 |
next if ($self->check_filter(section => 'ssds', instance => $item)); |
| 81 |
my $details = $xtremio->get_details( |
| 82 |
url => $urlbase, |
| 83 |
obj => 'ssds', |
| 84 |
name => $item |
| 85 |
); |
| 86 |
|
| 87 |
$self->{output}->output_add( |
| 88 |
long_msg => sprintf( |
| 89 |
"SSD '%s' endurance remaining is %i%%", |
| 90 |
$item, $details->{'percent-endurance-remaining'} |
| 91 |
) |
| 92 |
); |
| 93 |
|
| 94 |
my $exit = $self->{perfdata}->threshold_check( |
| 95 |
value => $details->{'percent-endurance-remaining'}, |
| 96 |
threshold => [ |
| 97 |
{ label => 'critical', exit_litteral => 'critical' }, |
| 98 |
{ label => 'warning', exit_litteral => 'warning' } |
| 99 |
] |
| 100 |
); |
| 101 |
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { |
| 102 |
$self->{output}->output_add( |
| 103 |
severity => $exit, |
| 104 |
short_msg => sprintf( |
| 105 |
"SSD '%s' endurance is %i%%", |
| 106 |
$item, $details->{'percent-endurance-remaining'} |
| 107 |
) |
| 108 |
); |
| 109 |
} |
| 110 |
$self->{output}->perfdata_add( |
| 111 |
label => $item . "_endurance", unit => '%', |
| 112 |
value => $details->{'percent-endurance-remaining'}, |
| 113 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), |
| 114 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), |
| 115 |
min => 0, max => 100 |
| 116 |
); |
| 117 |
} |
| 118 |
|
| 119 |
$self->{output}->display(); |
| 120 |
$self->{output}->exit(); |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
sub check_filter { |
| 125 |
my ($self, %options) = @_; |
| 126 |
|
| 127 |
foreach (@{$self->{filter}}) { |
| 128 |
if ($options{section} =~ /$_->{filter}/) { |
| 129 |
if (!defined($options{instance}) && !defined($_->{instance})) { |
| 130 |
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); |
| 131 |
return 1; |
| 132 |
} elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { |
| 133 |
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); |
| 134 |
return 1; |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
return 0; |
| 140 |
} |
| 141 |
|
| 142 |
1; |
| 143 |
|
| 144 |
__END__ |
| 145 |
|
| 146 |
=head1 MODE |
| 147 |
|
| 148 |
Check SSDs endurance level (100% is the best value) |
| 149 |
|
| 150 |
=over 8 |
| 151 |
|
| 152 |
=item B<--filter> |
| 153 |
|
| 154 |
Filter some parts (comma separated list) |
| 155 |
You can also exclude items from specific instances: --filter=ssds,SSD-NAME-NUMBER |
| 156 |
|
| 157 |
=item B<--warning> |
| 158 |
|
| 159 |
Warning trigger for SSD endurance |
| 160 |
|
| 161 |
=item B<--critical> |
| 162 |
|
| 163 |
Critical trigger for SSD endurance |
| 164 |
|
| 165 |
=back |
| 166 |
|
| 167 |
=cut |