| 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::hbausage; |
| 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::hbausage; |
| 29 |
use DateTime; |
| 30 |
|
| 31 |
sub set_counters { |
| 32 |
my ($self, %options) = @_; |
| 33 |
|
| 34 |
$self->{maps_counters_type} = [ |
| 35 |
{ name => 'hba', type => 1, cb_prefix_output => 'prefix_hba_output', message_multiple => 'All HBA are ok' } |
| 36 |
]; |
| 37 |
|
| 38 |
$self->{maps_counters}->{hba} = [ |
| 39 |
{ label => 'read-iops', set => { |
| 40 |
key_values => [ { name => 'read_iops' }, { name => 'display' } ], |
| 41 |
output_template => 'Read IOPs : %s', |
| 42 |
perfdatas => [ |
| 43 |
{ label => 'read_iops', value => 'read_iops', template => '%d', |
| 44 |
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 45 |
], |
| 46 |
} |
| 47 |
}, |
| 48 |
{ label => 'read-usage', set => { |
| 49 |
key_values => [ { name => 'read_bps' }, { name => 'display' } ], |
| 50 |
output_template => 'Read usage : %s %s/s', |
| 51 |
output_change_bytes => 2, |
| 52 |
perfdatas => [ |
| 53 |
{ label => 'read_usage', value => 'read_bps', template => '%d', |
| 54 |
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 55 |
], |
| 56 |
} |
| 57 |
}, |
| 58 |
{ label => 'read-latency', set => { |
| 59 |
key_values => [ { name => 'read_latency' }, { name => 'display' } ], |
| 60 |
output_template => 'Read latency : %s ms', |
| 61 |
perfdatas => [ |
| 62 |
{ label => 'read_latency', value => 'read_latency', template => '%d', |
| 63 |
unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 64 |
], |
| 65 |
} |
| 66 |
}, |
| 67 |
{ label => 'write-iops', set => { |
| 68 |
key_values => [ { name => 'write_iops' }, { name => 'display' } ], |
| 69 |
output_template => 'Write IOPs : %s', |
| 70 |
perfdatas => [ |
| 71 |
{ label => 'write_iops', value => 'write_iops', template => '%d', |
| 72 |
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 73 |
], |
| 74 |
} |
| 75 |
}, |
| 76 |
{ label => 'write-usage', set => { |
| 77 |
key_values => [ { name => 'write_bps' }, { name => 'display' } ], |
| 78 |
output_template => 'Write Usage : %s %s/s', |
| 79 |
output_change_bytes => 2, |
| 80 |
perfdatas => [ |
| 81 |
{ label => 'write_usage', value => 'write_bps', template => '%d', |
| 82 |
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 83 |
], |
| 84 |
} |
| 85 |
}, |
| 86 |
{ label => 'write-latency', set => { |
| 87 |
key_values => [ { name => 'write_latency' }, { name => 'display' } ], |
| 88 |
output_template => 'Write Latency : %s ms', |
| 89 |
perfdatas => [ |
| 90 |
{ label => 'write_latency', value => 'write_latency', template => '%d', |
| 91 |
unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 92 |
], |
| 93 |
} |
| 94 |
}, |
| 95 |
]; |
| 96 |
} |
| 97 |
|
| 98 |
sub prefix_hba_output { |
| 99 |
my ($self, %options) = @_; |
| 100 |
|
| 101 |
return "HBA '" . $options{instance_value}->{display} . "' "; |
| 102 |
} |
| 103 |
|
| 104 |
sub new { |
| 105 |
my ($class, %options) = @_; |
| 106 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 107 |
bless $self, $class; |
| 108 |
|
| 109 |
$options{options}->add_options(arguments => { |
| 110 |
'cem-host:s' => { name => 'cem_host' }, |
| 111 |
'cem-user:s' => { name => 'cem_user' }, |
| 112 |
'cem-password:s' => { name => 'cem_password' }, |
| 113 |
'cem-port:s' => { name => 'cem_port', default => 3033 }, |
| 114 |
'sdk-path-dll:s' => { name => 'sdk_path_dll' }, |
| 115 |
'timeout:s' => { name => 'timeout', default => 50 }, |
| 116 |
'command:s' => { name => 'command' }, |
| 117 |
'command-path:s' => { name => 'command_path' }, |
| 118 |
'command-options:s' => { name => 'command_options' }, |
| 119 |
'no-ps' => { name => 'no_ps' }, |
| 120 |
'ps-exec-only' => { name => 'ps_exec_only' }, |
| 121 |
'ps-display' => { name => 'ps_display' }, |
| 122 |
'ps-sc-filter:s' => { name => 'ps_sc_filter' }, |
| 123 |
'start-time:s' => { name => 'start_time' }, |
| 124 |
'end-time:s' => { name => 'end_time' }, |
| 125 |
'timezone:s' => { name => 'timezone' } |
| 126 |
}); |
| 127 |
|
| 128 |
return $self; |
| 129 |
} |
| 130 |
|
| 131 |
sub get_iso8601 { |
| 132 |
my ($self, %options) = @_; |
| 133 |
my $value = $options{date}->datetime . '.' . sprintf("%03d", $options{date}->millisecond()); |
| 134 |
my $offset = $options{date}->offset(); |
| 135 |
|
| 136 |
$value .= "-" if ($offset < 0); |
| 137 |
$value .= "+" if ($offset >= 0); |
| 138 |
$offset = abs($offset); |
| 139 |
$value .= sprintf("%02d:%02d", $offset / 3600, $offset % 3600); |
| 140 |
|
| 141 |
return $value; |
| 142 |
} |
| 143 |
|
| 144 |
sub parse_date { |
| 145 |
my ($self, %options) = @_; |
| 146 |
|
| 147 |
if ($options{date} !~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/) { |
| 148 |
$self->{output}->add_option_msg(short_msg => "Wrong time option '" . $options{date} . "'."); |
| 149 |
$self->{output}->option_exit(); |
| 150 |
} |
| 151 |
|
| 152 |
my $dt = DateTime->new( |
| 153 |
year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6, |
| 154 |
%{$self->{tz}} |
| 155 |
); |
| 156 |
return $dt; |
| 157 |
} |
| 158 |
|
| 159 |
sub check_options { |
| 160 |
my ($self, %options) = @_; |
| 161 |
$self->SUPER::check_options(%options); |
| 162 |
|
| 163 |
$self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq ''); |
| 164 |
foreach my $label (('cem_host', 'cem_user', 'cem_password', 'cem_port', 'sdk_path_dll')) { |
| 165 |
if (!defined($self->{option_results}->{$label}) || $self->{option_results}->{$label} eq '') { |
| 166 |
my ($label_opt) = $label; |
| 167 |
$label_opt =~ tr/_/-/; |
| 168 |
$self->{output}->add_option_msg(short_msg => "Need to specify --" . $label_opt . " option."); |
| 169 |
$self->{output}->option_exit(); |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
my ($dt_start, $dt_end); |
| 174 |
$self->{tz} = centreon::plugins::misc::set_timezone(name => $self->{option_results}->{timezone}); |
| 175 |
if (defined($self->{option_results}->{end_time}) && $self->{option_results}->{end_time} ne '') { |
| 176 |
$dt_end = $self->parse_date(date => $self->{option_results}->{end_time}); |
| 177 |
} else { |
| 178 |
$dt_end = DateTime->now(%{$self->{tz}}); |
| 179 |
} |
| 180 |
$self->{end_time} = $self->get_iso8601(date => $dt_end); |
| 181 |
|
| 182 |
if (defined($self->{option_results}->{start_time}) && $self->{option_results}->{start_time} ne '') { |
| 183 |
$dt_start = $self->parse_date(date => $self->{option_results}->{start_time}); |
| 184 |
} else { |
| 185 |
$dt_start = $dt_end->subtract(minutes => 30); |
| 186 |
} |
| 187 |
$self->{start_time} = $self->get_iso8601(date => $dt_start); |
| 188 |
|
| 189 |
centreon::plugins::misc::check_security_command( |
| 190 |
output => $self->{output}, |
| 191 |
command => $self->{option_results}->{command}, |
| 192 |
command_options => $self->{option_results}->{command_options}, |
| 193 |
command_path => $self->{option_results}->{command_path} |
| 194 |
); |
| 195 |
|
| 196 |
$self->{option_results}->{command} = 'powershell.exe' |
| 197 |
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); |
| 198 |
$self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' |
| 199 |
if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); |
| 200 |
} |
| 201 |
|
| 202 |
sub manage_selection { |
| 203 |
my ($self, %options) = @_; |
| 204 |
|
| 205 |
if (!defined($self->{option_results}->{no_ps})) { |
| 206 |
my $ps = centreon::common::powershell::dell::compellent::hbausage::get_powershell( |
| 207 |
cem_host => $self->{option_results}->{cem_host}, |
| 208 |
cem_user => $self->{option_results}->{cem_user}, |
| 209 |
cem_password => $self->{option_results}->{cem_password}, |
| 210 |
cem_port => $self->{option_results}->{cem_port}, |
| 211 |
sdk_path_dll => $self->{option_results}->{sdk_path_dll}, |
| 212 |
filter_sc => $self->{option_results}->{ps_sc_filter}, |
| 213 |
end_time => $self->{end_time}, start_time => $self->{start_time} |
| 214 |
); |
| 215 |
if (defined($self->{option_results}->{ps_display})) { |
| 216 |
$self->{output}->output_add( |
| 217 |
severity => 'OK', |
| 218 |
short_msg => $ps |
| 219 |
); |
| 220 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 221 |
$self->{output}->exit(); |
| 222 |
} |
| 223 |
|
| 224 |
$self->{option_results}->{command_options} .= " " . centreon::plugins::misc::powershell_encoded($ps); |
| 225 |
} |
| 226 |
|
| 227 |
my ($stdout) = centreon::plugins::misc::windows_execute( |
| 228 |
output => $self->{output}, |
| 229 |
timeout => $self->{option_results}->{timeout}, |
| 230 |
command => $self->{option_results}->{command}, |
| 231 |
command_path => $self->{option_results}->{command_path}, |
| 232 |
command_options => $self->{option_results}->{command_options} |
| 233 |
); |
| 234 |
if (defined($self->{option_results}->{ps_exec_only})) { |
| 235 |
$self->{output}->output_add( |
| 236 |
severity => 'OK', |
| 237 |
short_msg => $stdout |
| 238 |
); |
| 239 |
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); |
| 240 |
$self->{output}->exit(); |
| 241 |
} |
| 242 |
|
| 243 |
# microseconds for latencies |
| 244 |
#[sc=PRD-SAN-01][name=xxxx][ReadIops=39,5][ReadKbPerSecond=1220,75][ReadLatency=3997][WriteIops=95,75][WriteKbPerSecond=1217][WriteLatency=3903,25] |
| 245 |
$self->{hba} = {}; |
| 246 |
$stdout =~ s/,/\./msg; |
| 247 |
while ($stdout =~ /^\[sc=(.*?)\]\[name=(.*?)\]\[ReadIops=(.*?)\]\[ReadKbPerSecond=(.*?)\]\[ReadLatency=(.*?)\]\[WriteIops=(.*?)\]\[WriteKbPerSecond=(.*?)\]\[WriteLatency=(.*?)\]/mig) { |
| 248 |
my ($sc, $name, $read_iops, $read_kbps, $read_latency, $write_iops, $write_kbps, $write_latency) = |
| 249 |
($1, $2, $3, $4, $5, $6, $7, $8); |
| 250 |
my $display = $sc . '/' . $name; |
| 251 |
|
| 252 |
$self->{hba}->{$name} = { |
| 253 |
display => $display, read_iops => $read_iops, read_bps => $read_kbps * 1000, read_latency => $read_latency / 1000, |
| 254 |
write_iops => $write_iops, write_bps => $write_kbps * 1000, write_latency => $write_latency / 1000 |
| 255 |
}; |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
1; |
| 260 |
|
| 261 |
__END__ |
| 262 |
|
| 263 |
=head1 MODE |
| 264 |
|
| 265 |
Check hba usages. |
| 266 |
|
| 267 |
=over 8 |
| 268 |
|
| 269 |
=item B<--cem-host> |
| 270 |
|
| 271 |
Compellent Entreprise Manager hostname (required). |
| 272 |
|
| 273 |
=item B<--cem-user> |
| 274 |
|
| 275 |
Compellent Entreprise Manager username (required). |
| 276 |
|
| 277 |
=item B<--cem-password> |
| 278 |
|
| 279 |
Compellent Entreprise Manager password (required). |
| 280 |
|
| 281 |
=item B<--cem-port> |
| 282 |
|
| 283 |
Compellent Entreprise Manager port (default: 3033). |
| 284 |
|
| 285 |
=item B<--sdk-path-dll> |
| 286 |
|
| 287 |
Path to 'DellStorage.ApiCommandSet.dll' (required). |
| 288 |
|
| 289 |
=item B<--timeout> |
| 290 |
|
| 291 |
Set timeout time for command execution (default: 50 sec) |
| 292 |
|
| 293 |
=item B<--no-ps> |
| 294 |
|
| 295 |
Don't encode powershell. To be used with --command and 'type' command. |
| 296 |
|
| 297 |
=item B<--command> |
| 298 |
|
| 299 |
Command to get information (default: 'powershell.exe'). |
| 300 |
Can be changed if you have output in a file. To be used with --no-ps option!!! |
| 301 |
|
| 302 |
=item B<--command-path> |
| 303 |
|
| 304 |
Command path (default: none). |
| 305 |
|
| 306 |
=item B<--command-options> |
| 307 |
|
| 308 |
Command options (default: '-InputFormat none -NoLogo -EncodedCommand'). |
| 309 |
|
| 310 |
=item B<--ps-display> |
| 311 |
|
| 312 |
Display powershell script. |
| 313 |
|
| 314 |
=item B<--ps-exec-only> |
| 315 |
|
| 316 |
Print powershell output. |
| 317 |
|
| 318 |
=item B<--ps-sc-filter> |
| 319 |
|
| 320 |
Filter Storage Center (only wilcard '*' can be used. In Powershell). |
| 321 |
|
| 322 |
=item B<--start-time> |
| 323 |
|
| 324 |
Begin time for counters sampling. If not set, 30 minutes before the end-time option or current time |
| 325 |
Format: 2016-05-25T10:30:00 |
| 326 |
|
| 327 |
=item B<--end-time> |
| 328 |
|
| 329 |
End time for counters sampling. If not set, the current execution time. |
| 330 |
Format: 2016-05-25T15:30:00 |
| 331 |
|
| 332 |
=item B<--timezone> |
| 333 |
|
| 334 |
Timezone of time options. Default is 'GMT'. |
| 335 |
|
| 336 |
=item B<--filter-counters> |
| 337 |
|
| 338 |
Only display some counters (regexp can be used). |
| 339 |
Example: --filter-counters='^read-iops$' |
| 340 |
|
| 341 |
=item B<--warning-*> |
| 342 |
|
| 343 |
Warning threshold. |
| 344 |
Can be: 'read-iops', 'read-usage', 'read-latency', |
| 345 |
'write-iops', 'write-usage', 'write-latency'. |
| 346 |
|
| 347 |
=item B<--critical-*> |
| 348 |
|
| 349 |
Critical threshold. |
| 350 |
Can be: 'read-iops', 'read-usage', 'read-latency', |
| 351 |
'write-iops', 'write-usage', 'write-latency'. |
| 352 |
|
| 353 |
=back |
| 354 |
|
| 355 |
=cut |