| 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::dell::compellent::local::mode::volumeusage; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::misc; |
| 28 |
use centreon::common::powershell::dell::compellent::volumeusage; |
| 29 |
|
| 30 |
sub set_counters { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
$self->{maps_counters_type} = [ |
| 34 |
{ name => 'sc', type => 1, cb_prefix_output => 'prefix_sc_output', message_multiple => 'All storage centers are ok', cb_init => 'sc_init' }, |
| 35 |
{ name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes are ok' } |
| 36 |
]; |
| 37 |
|
| 38 |
$self->{maps_counters}->{sc} = [ |
| 39 |
{ label => 'sc-total', set => { |
| 40 |
key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' }, { name => 'type' } ], |
| 41 |
closure_custom_calc => $self->can('custom_usage_calc'), |
| 42 |
closure_custom_output => $self->can('custom_usage_output'), |
| 43 |
closure_custom_perfdata => $self->can('custom_usage_perfdata'), |
| 44 |
closure_custom_threshold_check => $self->can('custom_usage_threshold') |
| 45 |
} |
| 46 |
} |
| 47 |
]; |
| 48 |
|
| 49 |
$self->{maps_counters}->{volume} = [ |
| 50 |
{ label => 'volume-usage', set => { |
| 51 |
key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' }, { name => 'type' } ], |
| 52 |
closure_custom_calc => $self->can('custom_usage_calc'), |
| 53 |
closure_custom_output => $self->can('custom_usage_output'), |
| 54 |
closure_custom_perfdata => $self->can('custom_usage_perfdata'), |
| 55 |
closure_custom_threshold_check => $self->can('custom_usage_threshold') |
| 56 |
} |
| 57 |
}, |
| 58 |
{ label => 'volume-overhead', set => { |
| 59 |
key_values => [ { name => 'overhead' }, { name => 'display' } ], |
| 60 |
output_template => 'Raid Overhead : %s %s', |
| 61 |
output_change_bytes => 1, |
| 62 |
perfdatas => [ |
| 63 |
{ label => 'volume_overhead', template => '%d', |
| 64 |
unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 65 |
] |
| 66 |
} |
| 67 |
}, |
| 68 |
{ label => 'volume-replay', set => { |
| 69 |
key_values => [ { name => 'replay' }, { name => 'display' } ], |
| 70 |
output_template => 'Replay : %s %s', |
| 71 |
output_change_bytes => 1, |
| 72 |
perfdatas => [ |
| 73 |
{ label => 'volume_replay', template => '%d', |
| 74 |
unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 75 |
] |
| 76 |
} |
| 77 |
} |
| 78 |
]; |
| 79 |
} |
| 80 |
|
| 81 |
sub prefix_sc_output { |
| 82 |
my ($self, %options) = @_; |
| 83 |
|
| 84 |
return "Storage center '" . $options{instance_value}->{display} . "' "; |
| 85 |
} |
| 86 |
|
| 87 |
sub prefix_volume_output { |
| 88 |
my ($self, %options) = @_; |
| 89 |
|
| 90 |
return "Volume '" . $options{instance_value}->{display} . "' "; |
| 91 |
} |
| 92 |
|
| 93 |
sub sc_init { |
| 94 |
my ($self, %options) = @_; |
| 95 |
|
| 96 |
if (defined($self->{option_results}->{ps_sc_volume}) && $self->{option_results}->{ps_sc_volume} ne '') { |
| 97 |
return 1; |
| 98 |
} |
| 99 |
return 0; |
| 100 |
} |
| 101 |
|
| 102 |
sub custom_usage_perfdata { |
| 103 |
my ($self, %options) = @_; |
| 104 |
|
| 105 |
my $label = $self->{result_values}->{type} . '_used'; |
| 106 |
my $value_perf = $self->{result_values}->{used}; |
| 107 |
if (defined($self->{instance_mode}->{option_results}->{free})) { |
| 108 |
$label = $self->{result_values}->{type} . '_free'; |
| 109 |
$value_perf = $self->{result_values}->{free}; |
| 110 |
} |
| 111 |
|
| 112 |
my %total_options = (); |
| 113 |
if ($self->{instance_mode}->{option_results}->{units} eq '%') { |
| 114 |
$total_options{total} = $self->{result_values}->{total}; |
| 115 |
$total_options{cast_int} = 1; |
| 116 |
} |
| 117 |
|
| 118 |
$self->{output}->perfdata_add( |
| 119 |
label => $label, unit => 'B', |
| 120 |
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, |
| 121 |
value => $value_perf, |
| 122 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, %total_options), |
| 123 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, %total_options), |
| 124 |
min => 0, max => $self->{result_values}->{total} |
| 125 |
); |
| 126 |
} |
| 127 |
|
| 128 |
sub custom_usage_threshold { |
| 129 |
my ($self, %options) = @_; |
| 130 |
|
| 131 |
my ($exit, $threshold_value); |
| 132 |
$threshold_value = $self->{result_values}->{used}; |
| 133 |
$threshold_value = $self->{result_values}->{free} if (defined($self->{instance_mode}->{option_results}->{free})); |
| 134 |
if ($self->{instance_mode}->{option_results}->{units} eq '%') { |
| 135 |
$threshold_value = $self->{result_values}->{prct_used}; |
| 136 |
$threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); |
| 137 |
} |
| 138 |
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]); |
| 139 |
return $exit; |
| 140 |
} |
| 141 |
|
| 142 |
sub custom_usage_output { |
| 143 |
my ($self, %options) = @_; |
| 144 |
|
| 145 |
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); |
| 146 |
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); |
| 147 |
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); |
| 148 |
my $msg = sprintf( |
| 149 |
"Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", |
| 150 |
$total_size_value . " " . $total_size_unit, |
| 151 |
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, |
| 152 |
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} |
| 153 |
); |
| 154 |
return $msg; |
| 155 |
} |
| 156 |
|
| 157 |
sub custom_usage_calc { |
| 158 |
my ($self, %options) = @_; |
| 159 |
|
| 160 |
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; |
| 161 |
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; |
| 162 |
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; |
| 163 |
$self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; |
| 164 |
|
| 165 |
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; |
| 166 |
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; |
| 167 |
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; |
| 168 |
# snapshot can be over 100% |
| 169 |
if ($self->{result_values}->{free} < 0) { |
| 170 |
$self->{result_values}->{free} = 0; |
| 171 |
$self->{result_values}->{prct_free} = 0; |
| 172 |
} |
| 173 |
|
| 174 |
return 0; |
| 175 |
} |
| 176 |
|
| 177 |
sub new { |
| 178 |
my ($class, %options) = @_; |
| 179 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 180 |
bless $self, $class; |
| 181 |
|
| 182 |
$options{options}->add_options(arguments => { |
| 183 |
'cem-host:s' => { name => 'cem_host' }, |
| 184 |
'cem-user:s' => { name => 'cem_user' }, |
| 185 |
'cem-password:s' => { name => 'cem_password' }, |
| 186 |
'cem-port:s' => { name => 'cem_port', default => 3033 }, |
| 187 |
'sdk-path-dll:s' => { name => 'sdk_path_dll' }, |
| 188 |
'timeout:s' => { name => 'timeout', default => 50 }, |
| 189 |
'command:s' => { name => 'command' }, |
| 190 |
'command-path:s' => { name => 'command_path' }, |
| 191 |
'command-options:s' => { name => 'command_options' }, |
| 192 |
'no-ps' => { name => 'no_ps' }, |
| 193 |
'ps-exec-only' => { name => 'ps_exec_only' }, |
| 194 |
'ps-display' => { name => 'ps_display' }, |
| 195 |
'ps-sc-filter:s' => { name => 'ps_sc_filter' }, |
| 196 |
'ps-sc-volume:s' => { name => 'ps_sc_volume' }, |
| 197 |
'units:s' => { name => 'units', default => '%' }, |
| 198 |
'free' => { name => 'free' } |
| 199 |
}); |
| 200 |
|
| 201 |
return $self; |
| 202 |
} |
| 203 |
|
| 204 |
sub check_options { |
| 205 |
my ($self, %options) = @_; |
| 206 |
$self->SUPER::check_options(%options); |
| 207 |
|
| 208 |
foreach my $label (('cem_host', 'cem_user', 'cem_password', 'cem_port', 'sdk_path_dll')) { |
| 209 |
if (!defined($self->{option_results}->{$label}) || $self->{option_results}->{$label} eq '') { |
| 210 |
my ($label_opt) = $label; |
| 211 |
$label_opt =~ tr/_/-/; |
| 212 |
$self->{output}->add_option_msg(short_msg => "Need to specify --" . $label_opt . " option."); |
| 213 |
$self->{output}->option_exit(); |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
centreon::plugins::misc::check_security_command( |
| 218 |
output => $self->{output}, |
| 219 |
command => $self->{option_results}->{command}, |
| 220 |
command_options => $self->{option_results}->{command_options}, |
| 221 |
command_path => $self->{option_results}->{command_path} |
| 222 |
); |
| 223 |
|
| 224 |
$self->{option_results}->{command} = 'powershell.exe' |
| 225 |
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); |
| 226 |
$self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' |
| 227 |
if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); |
| 228 |
} |
| 229 |
|
| 230 |
sub manage_selection { |
| 231 |
my ($self, %options) = @_; |
| 232 |
|
| 233 |
if (!defined($self->{option_results}->{no_ps})) { |
| 234 |
my $ps = centreon::common::powershell::dell::compellent::volumeusage::get_powershell( |
| 235 |
cem_host => $self->{option_results}->{cem_host}, |
| 236 |
cem_user => $self->{option_results}->{cem_user}, |
| 237 |
cem_password => $self->{option_results}->{cem_password}, |
| 238 |
cem_port => $self->{option_results}->{cem_port}, |
| 239 |
sdk_path_dll => $self->{option_results}->{sdk_path_dll}, |
| 240 |
filter_sc => $self->{option_results}->{ps_sc_filter}, |
| 241 |
filter_vol => $self->{option_results}->{ps_sc_volume} |
| 242 |
); |
| 243 |
if (defined($self->{option_results}->{ps_display})) { |
| 244 |
$self->{output}->output_add( |
| 245 |
severity => 'OK', |
| 246 |
short_msg => $ps |
| 247 |
); |
| 248 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 249 |
$self->{output}->exit(); |
| 250 |
} |
| 251 |
|
| 252 |
$self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); |
| 253 |
} |
| 254 |
|
| 255 |
my ($stdout) = centreon::plugins::misc::windows_execute( |
| 256 |
output => $self->{output}, |
| 257 |
timeout => $self->{option_results}->{timeout}, |
| 258 |
command => $self->{option_results}->{command}, |
| 259 |
command_path => $self->{option_results}->{command_path}, |
| 260 |
command_options => $self->{option_results}->{command_options} |
| 261 |
); |
| 262 |
if (defined($self->{option_results}->{ps_exec_only})) { |
| 263 |
$self->{output}->output_add( |
| 264 |
severity => 'OK', |
| 265 |
short_msg => $stdout |
| 266 |
); |
| 267 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 268 |
$self->{output}->exit(); |
| 269 |
} |
| 270 |
|
| 271 |
# [sc=PRD-SAN-01][volume=SC-S06][configuredSpace=xxxxx][freeSpace=xxxxx][activeSpace=xxxxx][raidOverhead=xxx][totalDiskSpace=xxxx][replaySpace=xxxx] |
| 272 |
$self->{volume} = {}; |
| 273 |
$self->{sc} = {}; |
| 274 |
while ($stdout =~ /^\[sc=(.*?)\]\[volume=(.*?)\]\[configuredSpace=(.*?)\]\[freeSpace=(.*?)\]\[activeSpace=(.*?)\]\[raidOverhead=(.*?)\]\[totalDiskSpace=(.*?)\]\[replaySpace=(.*?)\]/mig) { |
| 275 |
my ($sc, $volume, $configured_space, $free_space, $active_space, $raid_overhead, $total_disk_space, $replay_space) = |
| 276 |
($1, $2, $3, $4, $5, $6, $7, $8); |
| 277 |
my $name = $sc . '/' . $volume; |
| 278 |
|
| 279 |
$self->{volume}->{$name} = { |
| 280 |
display => $name, total => $configured_space, type => 'volume', |
| 281 |
used => $active_space + $raid_overhead + $replay_space, |
| 282 |
overhead => $raid_overhead, replay => $replay_space |
| 283 |
}; |
| 284 |
$self->{sc}->{$sc} = { display => $sc, total => 0, used => 0, type => 'sc' } if (!defined($self->{sc}->{$sc})); |
| 285 |
$self->{sc}->{$sc}->{used} += $active_space + $raid_overhead + $replay_space; |
| 286 |
} |
| 287 |
|
| 288 |
# [sc=PRD-SAN-01][disk=01-01][spare=False][allocatedSpace=960195723264] |
| 289 |
while ($stdout =~ /^\[sc=(.*?)\]\[disk=(.*?)\]\[spare=(.*?)\]\[allocatedSpace=(.*?)\]/mig) { |
| 290 |
my ($sc, $disk, $spare, $allocated_space) = |
| 291 |
($1, $2, $3, $4); |
| 292 |
$self->{sc}->{$sc}->{total} += $allocated_space; |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
1; |
| 297 |
|
| 298 |
__END__ |
| 299 |
|
| 300 |
=head1 MODE |
| 301 |
|
| 302 |
Check storage center and volume usages. |
| 303 |
|
| 304 |
=over 8 |
| 305 |
|
| 306 |
=item B<--cem-host> |
| 307 |
|
| 308 |
Compellent Entreprise Manager hostname (required). |
| 309 |
|
| 310 |
=item B<--cem-user> |
| 311 |
|
| 312 |
Compellent Entreprise Manager username (required). |
| 313 |
|
| 314 |
=item B<--cem-password> |
| 315 |
|
| 316 |
Compellent Entreprise Manager password (required). |
| 317 |
|
| 318 |
=item B<--cem-port> |
| 319 |
|
| 320 |
Compellent Entreprise Manager port (default: 3033). |
| 321 |
|
| 322 |
=item B<--sdk-path-dll> |
| 323 |
|
| 324 |
Path to 'DellStorage.ApiCommandSet.dll' (required). |
| 325 |
|
| 326 |
=item B<--timeout> |
| 327 |
|
| 328 |
Set timeout time for command execution (default: 50 sec) |
| 329 |
|
| 330 |
=item B<--no-ps> |
| 331 |
|
| 332 |
Don't encode powershell. To be used with --command and 'type' command. |
| 333 |
|
| 334 |
=item B<--command> |
| 335 |
|
| 336 |
Command to get information (default: 'powershell.exe'). |
| 337 |
Can be changed if you have output in a file. To be used with --no-ps option!!! |
| 338 |
|
| 339 |
=item B<--command-path> |
| 340 |
|
| 341 |
Command path (default: none). |
| 342 |
|
| 343 |
=item B<--command-options> |
| 344 |
|
| 345 |
Command options (default: '-InputFormat none -NoLogo -EncodedCommand'). |
| 346 |
|
| 347 |
=item B<--ps-display> |
| 348 |
|
| 349 |
Display powershell script. |
| 350 |
|
| 351 |
=item B<--ps-exec-only> |
| 352 |
|
| 353 |
Print powershell output. |
| 354 |
|
| 355 |
=item B<--ps-sc-filter> |
| 356 |
|
| 357 |
Filter Storage Center (only wilcard '*' can be used. In Powershell). |
| 358 |
|
| 359 |
=item B<--ps-sc-volume> |
| 360 |
|
| 361 |
Filter Volume Name to display. |
| 362 |
|
| 363 |
=item B<--units> |
| 364 |
|
| 365 |
Units of thresholds (default: '%') ('%', 'B'). |
| 366 |
|
| 367 |
=item B<--free> |
| 368 |
|
| 369 |
Thresholds are on free space left. |
| 370 |
|
| 371 |
=item B<--filter-counters> |
| 372 |
|
| 373 |
Only display some counters (regexp can be used). |
| 374 |
Example: --filter-counters='^sc-total$' |
| 375 |
|
| 376 |
=item B<--warning-*> |
| 377 |
|
| 378 |
Warning threshold. |
| 379 |
Can be: 'sc-total', 'volume-usage', 'volume-overhead', 'volume-replay'. |
| 380 |
|
| 381 |
=item B<--critical-*> |
| 382 |
|
| 383 |
Critical threshold. |
| 384 |
Can be: 'sc-total', 'volume-usage', 'volume-overhead', 'volume-replay'. |
| 385 |
|
| 386 |
=back |
| 387 |
|
| 388 |
=cut |