| 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::purestorage::flashblade::v2::restapi::mode::arrays; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub custom_usage_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); |
| 32 |
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); |
| 33 |
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); |
| 34 |
return sprintf( |
| 35 |
'space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', |
| 36 |
$total_size_value . " " . $total_size_unit, |
| 37 |
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, |
| 38 |
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
sub array_long_output { |
| 43 |
my ($self, %options) = @_; |
| 44 |
|
| 45 |
return "checking array '" . $options{instance_value}->{name} . "'"; |
| 46 |
} |
| 47 |
|
| 48 |
sub prefix_array_output { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
return "Array '" . $options{instance_value}->{name} . "' "; |
| 52 |
} |
| 53 |
|
| 54 |
sub set_counters { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
$self->{maps_counters_type} = [ |
| 58 |
{ |
| 59 |
name => 'arrays', type => 3, cb_prefix_output => 'prefix_array_output', cb_long_output => 'array_long_output', indent_long_output => ' ', |
| 60 |
message_multiple => 'All arrays are ok', |
| 61 |
group => [ |
| 62 |
{ name => 'space', type => 0, skipped_code => { -10 => 1 } }, |
| 63 |
{ name => 'reduction', type => 0, skipped_code => { -10 => 1 } }, |
| 64 |
{ name => 'perf', type => 0, skipped_code => { -10 => 1 } } |
| 65 |
] |
| 66 |
} |
| 67 |
]; |
| 68 |
|
| 69 |
$self->{maps_counters}->{space} = [ |
| 70 |
{ label => 'space-usage', nlabel => 'array.space.usage.bytes', set => { |
| 71 |
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 72 |
closure_custom_output => $self->can('custom_usage_output'), |
| 73 |
perfdatas => [ |
| 74 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 75 |
] |
| 76 |
} |
| 77 |
}, |
| 78 |
{ label => 'space-usage-free', display_ok => 0, nlabel => 'array.space.free.bytes', set => { |
| 79 |
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], |
| 80 |
closure_custom_output => $self->can('custom_usage_output'), |
| 81 |
perfdatas => [ |
| 82 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1 } |
| 83 |
] |
| 84 |
} |
| 85 |
}, |
| 86 |
{ label => 'space-usage-prct', display_ok => 0, nlabel => 'array.space.usage.percentage', set => { |
| 87 |
key_values => [ { name => 'prct_used' }, { name => 'used' }, { name => 'free' }, { name => 'prct_free' }, { name => 'total' } ], |
| 88 |
closure_custom_output => $self->can('custom_usage_output'), |
| 89 |
perfdatas => [ |
| 90 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 91 |
] |
| 92 |
} |
| 93 |
} |
| 94 |
]; |
| 95 |
|
| 96 |
$self->{maps_counters}->{reduction} = [ |
| 97 |
{ label => 'data-reduction', nlabel => 'array.data.reduction.count', set => { |
| 98 |
key_values => [ { name => 'data' } ], |
| 99 |
output_template => 'data reduction: %.3f', |
| 100 |
perfdatas => [ |
| 101 |
{ template => '%.3f', min => 0, label_extra_instance => 1 } |
| 102 |
] |
| 103 |
} |
| 104 |
} |
| 105 |
]; |
| 106 |
|
| 107 |
$self->{maps_counters}->{perf} = [ |
| 108 |
{ label => 'read', nlabel => 'array.io.read.usage.bytespersecond', set => { |
| 109 |
key_values => [ { name => 'read_bytes' }, { name => 'name' }, { name => 'resolution' } ], |
| 110 |
output_template => 'read: %s %s/s', |
| 111 |
output_change_bytes => 1, |
| 112 |
closure_custom_perfdata => sub { |
| 113 |
my ($self, %options) = @_; |
| 114 |
|
| 115 |
$self->{output}->perfdata_add( |
| 116 |
nlabel => $self->{nlabel}, |
| 117 |
unit => 'B/s', |
| 118 |
instances => [$self->{result_values}->{name}, $self->{result_values}->{resolution}], |
| 119 |
value => $self->{result_values}->{read_bytes}, |
| 120 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 121 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 122 |
min => 0 |
| 123 |
); |
| 124 |
} |
| 125 |
} |
| 126 |
}, |
| 127 |
{ label => 'write', nlabel => 'array.io.write.usage.bytespersecond', set => { |
| 128 |
key_values => [ { name => 'write_bytes' }, { name => 'name' }, { name => 'resolution' } ], |
| 129 |
output_template => 'write: %s %s/s', |
| 130 |
output_change_bytes => 1, |
| 131 |
closure_custom_perfdata => sub { |
| 132 |
my ($self, %options) = @_; |
| 133 |
|
| 134 |
$self->{output}->perfdata_add( |
| 135 |
nlabel => $self->{nlabel}, |
| 136 |
unit => 'B/s', |
| 137 |
instances => [$self->{result_values}->{name}, $self->{result_values}->{resolution}], |
| 138 |
value => $self->{result_values}->{write_bytes}, |
| 139 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 140 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 141 |
min => 0 |
| 142 |
); |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
]; |
| 147 |
} |
| 148 |
|
| 149 |
sub new { |
| 150 |
my ($class, %options) = @_; |
| 151 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 152 |
bless $self, $class; |
| 153 |
|
| 154 |
$options{options}->add_options(arguments => { |
| 155 |
'filter-id:s' => { name => 'filter_id' }, |
| 156 |
'filter-name:s' => { name => 'filter_name' }, |
| 157 |
'perf-resolution:s' => { name => 'perf_resolution' } |
| 158 |
}); |
| 159 |
|
| 160 |
return $self; |
| 161 |
} |
| 162 |
|
| 163 |
my $map_resolution = { |
| 164 |
'1s' => 1000, '30s' => 30000, '5m' => 300000, |
| 165 |
'30m' => 1800000, '2h' => 7200000, '8h' => 28800000, |
| 166 |
'24h' => 86400000 |
| 167 |
}; |
| 168 |
|
| 169 |
sub check_options { |
| 170 |
my ($self, %options) = @_; |
| 171 |
$self->SUPER::check_options(%options); |
| 172 |
|
| 173 |
$self->{option_results}->{perf_resolution} = '5m' |
| 174 |
if (!defined($self->{option_results}->{perf_resolution}) || $self->{option_results}->{perf_resolution} eq ''); |
| 175 |
|
| 176 |
if (!defined($map_resolution->{ $self->{option_results}->{perf_resolution} })) { |
| 177 |
$self->{output}->add_option_msg(short_msg => 'Unsupported --perf-resolution value. Can be: 1s, 30s, 5m, 30m, 2h, 8h, 24h'); |
| 178 |
$self->{output}->option_exit(); |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
sub manage_selection { |
| 183 |
my ($self, %options) = @_; |
| 184 |
|
| 185 |
my $items = $options{custom}->request(endpoint => '/arrays/space'); |
| 186 |
my $perfs = $options{custom}->request(endpoint => '/arrays/performance', get_param => ['resolution=' . $map_resolution->{ $self->{option_results}->{perf_resolution} }]); |
| 187 |
|
| 188 |
#{ |
| 189 |
# "capacity": 29159353378407, |
| 190 |
# "id": "1dcca71d-8bca-4951-9ba5-10ca0f5744d8", |
| 191 |
# "name": "filer-c", |
| 192 |
# "parity": 1.0, |
| 193 |
# "space": { |
| 194 |
# "data_reduction": 3.808265875566517, |
| 195 |
# "replication": 0, |
| 196 |
# "shared": 2182502918574, |
| 197 |
# "snapshots": 0, |
| 198 |
# "system": 0, |
| 199 |
# "thin_provisioning": 0.3114475926111792, |
| 200 |
# "total_physical": 17760870565810, |
| 201 |
# "total_provisioned": 98232344510464, |
| 202 |
# "total_reduction": 5.5308293670898685, |
| 203 |
# "unique": 15578367647236, |
| 204 |
# "virtual": 67638117296128 |
| 205 |
# }, |
| 206 |
# "time": 1670839151850 |
| 207 |
#} |
| 208 |
$self->{arrays} = {}; |
| 209 |
foreach my $item (@$items) { |
| 210 |
next if (defined($self->{option_results}->{filter_id}) && $self->{option_results}->{filter_id} ne '' && |
| 211 |
$item->{id} !~ /$self->{option_results}->{filter_id}/); |
| 212 |
next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 213 |
$item->{name} !~ /$self->{option_results}->{filter_name}/); |
| 214 |
|
| 215 |
$self->{arrays}->{ $item->{name} } = { |
| 216 |
name => $item->{name}, |
| 217 |
reduction => { |
| 218 |
data => $item->{space}->{data_reduction} |
| 219 |
}, |
| 220 |
space => { |
| 221 |
total => $item->{capacity}, |
| 222 |
used => $item->{space}->{total_physical}, |
| 223 |
free => $item->{capacity} - $item->{space}->{total_physical}, |
| 224 |
prct_used => $item->{space}->{total_physical} * 100 / $item->{capacity}, |
| 225 |
prct_free => (100 - ($item->{space}->{total_physical} * 100 / $item->{capacity})) |
| 226 |
} |
| 227 |
}; |
| 228 |
} |
| 229 |
|
| 230 |
foreach my $perf (@$perfs) { |
| 231 |
next if (!defined($self->{arrays}->{ $perf->{name} })); |
| 232 |
|
| 233 |
$self->{arrays}->{ $perf->{name} }->{perf} = { |
| 234 |
name => $perf->{name}, |
| 235 |
resolution => $self->{option_results}->{perf_resolution}, |
| 236 |
read_bytes => $perf->{read_bytes_per_sec}, |
| 237 |
write_bytes => $perf->{write_bytes_per_sec} |
| 238 |
}; |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
1; |
| 243 |
|
| 244 |
__END__ |
| 245 |
|
| 246 |
=head1 MODE |
| 247 |
|
| 248 |
Check arrays. |
| 249 |
|
| 250 |
=over 8 |
| 251 |
|
| 252 |
=item B<--filter-counters> |
| 253 |
|
| 254 |
Only display some counters (regexp can be used). |
| 255 |
Example: --filter-counters='data-reduction' |
| 256 |
|
| 257 |
=item B<--filter-id> |
| 258 |
|
| 259 |
Filter arrays by ID (can be a regexp). |
| 260 |
|
| 261 |
=item B<--filter-name> |
| 262 |
|
| 263 |
Filter arrays by name (can be a regexp). |
| 264 |
|
| 265 |
=item B<--filter-resolution> |
| 266 |
|
| 267 |
Time resolution for array performance. |
| 268 |
Can be: 1s, 30s, 5m, 30m, 2h, 8h, 24h (default: 5m). |
| 269 |
|
| 270 |
=item B<--warning-*> B<--critical-*> |
| 271 |
|
| 272 |
Thresholds. |
| 273 |
Can be: 'space-usage' (B), 'space-usage-free' (B), 'space-usage-prct' (%), |
| 274 |
'data-reduction', 'read', 'write'. |
| 275 |
|
| 276 |
=back |
| 277 |
|
| 278 |
=cut |