| 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::netapp::santricity::restapi::mode::storagevolumes; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
use Digest::MD5 qw(md5_hex); |
| 29 |
|
| 30 |
sub custom_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return sprintf( |
| 34 |
'status: %s', |
| 35 |
$self->{result_values}->{status} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub ss_long_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return "checking storage system '" . $options{instance_value}->{display} . "'"; |
| 43 |
} |
| 44 |
|
| 45 |
sub prefix_ss_output { |
| 46 |
my ($self, %options) = @_; |
| 47 |
|
| 48 |
return "storage system '" . $options{instance_value}->{display} . "' "; |
| 49 |
} |
| 50 |
|
| 51 |
sub prefix_volume_output { |
| 52 |
my ($self, %options) = @_; |
| 53 |
|
| 54 |
return "volume '" . $options{instance_value}->{display} . "' "; |
| 55 |
} |
| 56 |
|
| 57 |
sub set_counters { |
| 58 |
my ($self, %options) = @_; |
| 59 |
|
| 60 |
$self->{maps_counters_type} = [ |
| 61 |
{ name => 'ss', type => 3, cb_prefix_output => 'prefix_ss_output', cb_long_output => 'ss_long_output', indent_long_output => ' ', message_multiple => 'All storage systems are ok', |
| 62 |
group => [ |
| 63 |
{ name => 'volumes', display_long => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'volumes are ok', type => 1, skipped_code => { -10 => 1 } } |
| 64 |
] |
| 65 |
} |
| 66 |
]; |
| 67 |
|
| 68 |
$self->{maps_counters}->{volumes} = [ |
| 69 |
{ |
| 70 |
label => 'volume-status', |
| 71 |
type => 2, |
| 72 |
warning_default => '%{status} =~ /degraded/i', |
| 73 |
critical_default => '%{status} =~ /failed/i', |
| 74 |
set => { |
| 75 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 76 |
closure_custom_output => $self->can('custom_status_output'), |
| 77 |
closure_custom_perfdata => sub { return 0; }, |
| 78 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 79 |
} |
| 80 |
}, |
| 81 |
{ label => 'read', nlabel => 'volume.io.read.usage.bytespersecond', set => { |
| 82 |
key_values => [ { name => 'read_bytes', per_second => 1 }, { name => 'display' } ], |
| 83 |
output_template => 'read: %s %s/s', |
| 84 |
output_change_bytes => 1, |
| 85 |
perfdatas => [ |
| 86 |
{ template => '%d', unit => 'B/s', label_extra_instance => 1 } |
| 87 |
] |
| 88 |
} |
| 89 |
}, |
| 90 |
{ label => 'write', nlabel => 'volume.io.write.usage.bytespersecond', set => { |
| 91 |
key_values => [ { name => 'write_bytes', per_second => 1 }, { name => 'display' } ], |
| 92 |
output_template => 'write: %s %s/s', |
| 93 |
output_change_bytes => 1, |
| 94 |
perfdatas => [ |
| 95 |
{ template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 } |
| 96 |
] |
| 97 |
} |
| 98 |
}, |
| 99 |
{ label => 'read-iops', nlabel => 'volume.io.read.usage.iops', set => { |
| 100 |
key_values => [ { name => 'read_iops', per_second => 1 }, { name => 'display' } ], |
| 101 |
output_template => 'read: %.2f iops', |
| 102 |
perfdatas => [ |
| 103 |
{ template => '%.2f', unit => 'iops', min => 0, label_extra_instance => 1 } |
| 104 |
] |
| 105 |
} |
| 106 |
}, |
| 107 |
{ label => 'write-iops', nlabel => 'volume.io.write.usage.iops', set => { |
| 108 |
key_values => [ { name => 'write_iops', per_second => 1 }, { name => 'display' } ], |
| 109 |
output_template => 'write: %.2f iops', |
| 110 |
perfdatas => [ |
| 111 |
{ template => '%.2f', unit => 'iops', min => 0, label_extra_instance => 1 } |
| 112 |
] |
| 113 |
} |
| 114 |
} |
| 115 |
]; |
| 116 |
} |
| 117 |
|
| 118 |
sub new { |
| 119 |
my ($class, %options) = @_; |
| 120 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 121 |
bless $self, $class; |
| 122 |
|
| 123 |
$options{options}->add_options(arguments => { |
| 124 |
'filter-storage-name:s' => { name => 'filter_storage_name' }, |
| 125 |
'filter-volume-name:s' => { name => 'filter_volume_name' } |
| 126 |
}); |
| 127 |
|
| 128 |
return $self; |
| 129 |
} |
| 130 |
|
| 131 |
sub manage_selection { |
| 132 |
my ($self, %options) = @_; |
| 133 |
|
| 134 |
my $results = $options{custom}->execute_storages_request( |
| 135 |
endpoints => [ |
| 136 |
{ endpoint => '/volumes' }, |
| 137 |
{ endpoint => '/volume-statistics', get_param => 'usecache=false' } |
| 138 |
], |
| 139 |
filter_name => $self->{option_results}->{filter_storage_name} |
| 140 |
); |
| 141 |
|
| 142 |
$self->{ss} = {}; |
| 143 |
foreach (@{$results->{storages}}) { |
| 144 |
my $storage_name = $_->{name}; |
| 145 |
|
| 146 |
$self->{ss}->{$storage_name} = { |
| 147 |
display => $storage_name, |
| 148 |
volumes => {} |
| 149 |
}; |
| 150 |
|
| 151 |
next if (!defined($_->{'/volumes'})); |
| 152 |
|
| 153 |
foreach my $entry (@{$_->{'/volumes'}}) { |
| 154 |
|
| 155 |
next if (defined($options{filter_volume_name}) && $options{filter_volume_name} ne '' && |
| 156 |
$entry->{name} !~ /$options{filter_volume_name}/); |
| 157 |
|
| 158 |
$self->{ss}->{$storage_name}->{volumes}->{ $entry->{name} } = { |
| 159 |
display => $entry->{name}, |
| 160 |
status => $entry->{status} |
| 161 |
}; |
| 162 |
} |
| 163 |
|
| 164 |
foreach my $entry (@{$_->{'/volume-statistics'}}) { |
| 165 |
next if (!defined($self->{ss}->{$storage_name}->{volumes}->{ $entry->{volumeName} })); |
| 166 |
|
| 167 |
$self->{ss}->{$storage_name}->{volumes}->{ $entry->{volumeName} }->{write_bytes} = $entry->{writeBytes}; |
| 168 |
$self->{ss}->{$storage_name}->{volumes}->{ $entry->{volumeName} }->{read_bytes} = $entry->{readBytes}; |
| 169 |
$self->{ss}->{$storage_name}->{volumes}->{ $entry->{volumeName} }->{read_iops} = $entry->{readOps}; |
| 170 |
$self->{ss}->{$storage_name}->{volumes}->{ $entry->{volumeName} }->{write_iops} = $entry->{writeOps}; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
$self->{cache_name} = 'netapp_santricity_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . |
| 175 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . |
| 176 |
(defined($self->{option_results}->{filter_storage_name}) ? md5_hex($self->{option_results}->{filter_storage_name}) : md5_hex('all')) . '_' . |
| 177 |
(defined($self->{option_results}->{filter_volume_name}) ? md5_hex($self->{option_results}->{filter_volume_name}) : md5_hex('all')); |
| 178 |
} |
| 179 |
|
| 180 |
1; |
| 181 |
|
| 182 |
__END__ |
| 183 |
|
| 184 |
=head1 MODE |
| 185 |
|
| 186 |
Check storage volumes. |
| 187 |
|
| 188 |
=over 8 |
| 189 |
|
| 190 |
=item B<--filter-counters> |
| 191 |
|
| 192 |
Only display some counters (regexp can be used). |
| 193 |
Example: --filter-counters='volume-status' |
| 194 |
|
| 195 |
=item B<--filter-storage-name> |
| 196 |
|
| 197 |
Filter storage name (can be a regexp). |
| 198 |
|
| 199 |
=item B<--filter-volume-name> |
| 200 |
|
| 201 |
Filter volume name (can be a regexp). |
| 202 |
|
| 203 |
=item B<--unknown-volume-status> |
| 204 |
|
| 205 |
Define the conditions to match for the status to be UNKNOWN. |
| 206 |
You can use the following variables: %{status}, %{display} |
| 207 |
|
| 208 |
=item B<--warning-volume-status> |
| 209 |
|
| 210 |
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /degraded/i'). |
| 211 |
You can use the following variables: %{status}, %{display} |
| 212 |
|
| 213 |
=item B<--critical-volume-status> |
| 214 |
|
| 215 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /failed/i'). |
| 216 |
You can use the following variables: %{status}, %{display} |
| 217 |
|
| 218 |
=item B<--warning-*> B<--critical-*> |
| 219 |
|
| 220 |
Thresholds. |
| 221 |
Can be: 'read' (B/s), 'write' (B/s), 'read-iops', 'write-iops'. |
| 222 |
|
| 223 |
=back |
| 224 |
|
| 225 |
=cut |