+ add mode hba usage for dell compellent (WIP)

This commit is contained in:
garnier-quentin 2016-05-25 14:46:24 +02:00
parent 019b61908b
commit 721dd52c15
3 changed files with 427 additions and 0 deletions

View File

@ -0,0 +1,108 @@
#
# Copyright 2016 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package centreon::common::powershell::dell::compellent::hbausage;
use strict;
use warnings;
use centreon::plugins::misc;
sub get_powershell {
my (%options) = @_;
my $no_ps = (defined($options{no_ps})) ? 1 : 0;
return '' if ($no_ps == 1);
my $ps = '
$culture = new-object "System.Globalization.CultureInfo" "en-us"
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
$ProgressPreference = "SilentlyContinue"
$ErrorActionPreference = "Stop"
$scuser = "' . $options{cem_user} . '"
$scpass = ConvertTo-SecureString "' . $options{cem_password} . '" -AsPlainText -Force
$schost = "' . $options{cem_host} . '"
$scport = "' . $options{cem_port} . '"
$connName = "EMDefault"
Function display_hba_information {
$conn = Connect-DellApiConnection -HostName $schost -Port $scport -User $scuser -password $scpass -Save $connName
';
if (defined($options{filter_sc}) && $options{filter_sc} ne '') {
$ps .= '$storageCenters = Get-DellStorageCenter -ConnectionName $connName -Name "' . $options{filter_sc} . '"
';
} else {
$ps .= '$storageCenters = Get-DellStorageCenter -ConnectionName $connName
';
}
$ps .= '
$historical = New-DellHistoricalFilter -FilterTime "Other" -StartTime "' . $options{start_time} . '" -EndTime "' . $options{end_time} . '"
foreach ($sc in $storageCenters) {
$hbaList = Get-DellScServerHba -ConnectionName $connName -StorageCenter $sc
foreach ($hba in $hbaList) {
$usageList = Get-DellScServerHbaHistoricalIoUsage -ConnectionName $connName -Instance $hba -HistoricalFilter $historical
write-host ("[sc={0}]" -f $hba.ScName) -NoNewline
write-host ("[name={0}]" -f $hba.Name) -NoNewline
$attrs = @{ReadKbPerSecond = 0; WriteKbPerSecond = 0; ReadIops = 0; WriteIops = 0; ReadLatency = 0; WriteLatency = 0; }
$count = 0
foreach ($usage in $usageList) {
foreach ($item in $($attrs.GetEnumerator() | sort -Property Key)) {
$attrs[$item.Key] += ($usage | Select -ExpandProperty $item.Key)
}
$count++
}
foreach ($item in $attrs.GetEnumerator() | sort -Property Key) {
write-host ("[{0}={1}]" -f $item.Key, ($item.Value / $count)) -NoNewline
}
write-host
}
}
}
Try {
Import-Module "' . $options{sdk_path_dll} . '"
display_hba_information
} Catch {
Write-Host $Error[0].Exception
$ret = Remove-DellSavedApiConnection -Name $connName
exit 1
}
$ret = Remove-DellSavedApiConnection -Name $connName
exit 0
';
return centreon::plugins::misc::powershell_encoded($ps);
}
1;
__END__
=head1 DESCRIPTION
Method to get compellent hba informations.
=cut

View File

@ -0,0 +1,318 @@
#
# Copyright 2016 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package storage::dell::compellent::local::mode::hbausage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::common::powershell::dell::compellent::volumeusage;
use DateTime;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'hba', type => 1, cb_prefix_output => 'prefix_hba_output', message_multiple => 'All HBA are ok' }
];
$self->{maps_counters}->{hba} = [
{ label => 'read-iops', set => {
key_values => [ { name => 'read_iops' }, { name => 'display' } ],
output_template => 'Read IOPs : %s',
perfdatas => [
{ label => 'read_iops', value => 'read_iops_absolute', template => '%d',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'read-usage', set => {
key_values => [ { name => 'read_bps' }, { name => 'display' } ],
output_template => 'Read usage : %s %s',
output_change_bytes => 2,
perfdatas => [
{ label => 'read_usage', value => 'read_bps_absolute', template => '%d',
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'read-latency', set => {
key_values => [ { name => 'read_latency' }, { name => 'display' } ],
output_template => 'Read latency : %s ms',
perfdatas => [
{ label => 'read_latency', value => 'read_latency_absolute', template => '%d',
unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'write-iops', set => {
key_values => [ { name => 'write_iops' }, { name => 'display' } ],
output_template => 'Write IOPs : %s',
perfdatas => [
{ label => 'write_iops', value => 'write_iops_absolute', template => '%d',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'write-usage', set => {
key_values => [ { name => 'write_bps' }, { name => 'display' } ],
output_template => 'Write Usage : %s %s',
output_change_bytes => 2,
perfdatas => [
{ label => 'write_usage', value => 'read_bps_absolute', template => '%d',
unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'write-latency', set => {
key_values => [ { name => 'write_latency' }, { name => 'display' } ],
output_template => 'Write Latency : %s ms',
perfdatas => [
{ label => 'write_latency', value => 'write_latency_absolute', template => '%d',
unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub prefix_hba_output {
my ($self, %options) = @_;
return "HBA '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"cem-host:s" => { name => 'cem_host' },
"cem-user:s" => { name => 'cem_user' },
"cem-password:s" => { name => 'cem_password' },
"cem-port:s" => { name => 'cem_port', default => 3033 },
"sdk-path-dll:s" => { name => 'sdk_path_dll' },
"timeout:s" => { name => 'timeout', default => 50 },
"command:s" => { name => 'command', default => 'powershell.exe' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' },
"no-ps" => { name => 'no_ps' },
"ps-exec-only" => { name => 'ps_exec_only' },
"ps-sc-filter:s" => { name => 'ps_sc_filter' },
"start-time:s" => { name => 'start_time' },
"end-time:s" => { name => 'end_time' },
"timezone:s" => { name => 'timezone' },
});
return $self;
}
sub get_iso8601 {
my ($self, %options) = @_;
my $value = $options{date}->datetime . '.' . sprintf("%03d", $options{date}->millisecond());
my $offset = $options{date}->offset();
$value .= "-" if ($offset < 0);
$value .= "+" if ($offset >= 0);
$offset = abs($offset);
$value .= sprintf("%02d:%02d", $offset / 3600, $offset % 3600);
return $value;
}
sub parse_date {
my ($self, %options) = @_;
if ($options{date} !~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/) {
$self->{output}->add_option_msg(short_msg => "Wrong time option '" . $options{date} . "'.");
$self->{output}->option_exit();
}
my $dt = DateTime->new(year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6,
time_zone => $self->{option_results}->{timezone});
return $dt;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
foreach my $label (('cem_host', 'cem_user', 'cem_password', 'cem_port', 'sdk_path_dll')) {
if (!defined($self->{option_results}->{$label}) || $self->{option_results}->{$label} eq '') {
my ($label_opt) = $label;
$label_opt =~ tr/_/-/;
$self->{output}->add_option_msg(short_msg => "Need to specify --" . $label_opt . " option.");
$self->{output}->option_exit();
}
}
my ($dt_start, $dt_end);
if (defined($self->{option_results}->{end_time}) && $self->{option_results}->{end_time} ne '') {
$dt_end = $self->parse_date(date => $self->{option_results}->{end_time});
} else {
$dt_end = DateTime->now(time_zone => $self->{option_results}->{timezone});
}
$self->{end_time} = $self->get_iso8601(date => $dt_end);
if (defined($self->{option_results}->{start_time}) && $self->{option_results}->{start_time} ne '') {
$dt_start = $self->parse_date(date => $self->{option_results}->{start_time});
} else {
$dt_start = $dt_end->subtract(minutes => 30);
}
$self->{start_time} = $self->get_iso8601(date => $dt_start);
}
sub manage_selection {
my ($self, %options) = @_;
my $ps = centreon::common::powershell::dell::compellent::volumeusage::get_powershell(cem_host => $self->{option_results}->{cem_host},
cem_user => $self->{option_results}->{cem_user},
cem_password => $self->{option_results}->{cem_password},
cem_port => $self->{option_results}->{cem_port},
sdk_path_dll => $self->{option_results}->{sdk_path_dll},
no_ps => $self->{option_results}->{no_ps},
filter_sc => $self->{option_results}->{ps_sc_filter},
end_time => $self->{end_time}, start_time => $self->{start_time});
$self->{option_results}->{command_options} .= " " . $ps;
my ($stdout) = centreon::plugins::misc::windows_execute(output => $self->{output},
timeout => $self->{option_results}->{timeout},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
if (defined($self->{option_results}->{ps_exec_only})) {
$self->{output}->output_add(severity => 'OK',
short_msg => $stdout);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
# microseconds for latencies
#[sc=PRD-SAN-01][name=xxxx][ReadIops=39,5][ReadKbPerSecond=1220,75][ReadLatency=3997][WriteIops=95,75][WriteKbPerSecond=1217][WriteLatency=3903,25]
$self->{hba} = {};
$self->{sc} = {};
$stdout =~ s/,/\./msg;
while ($stdout =~ /^\[sc=(.*?)\]\[name=(.*?)\]\[ReadIops=(.*?)\]\[ReadKbPerSecond=(.*?)\]\[ReadLatency=(.*?)\]\[WriteIops=(.*?)\]\[WriteKbPerSecond=(.*?)\]\[WriteLatency=(.*?)\]/mig) {
my ($sc, $volume, $read_iops, $read_kbps, $read_latency, $write_iops, $write_kbps, $write_latency) =
($1, $2, $3, $4, $5, $6, $7, $8);
my $name = $sc . '/' . $name;
$self->{hba}->{$name} = { display => $name, read_iops => $read_iops, read_bps => $read_kbps * 1000, read_latency => $read_latency / 1000,
write_iops => $write_iops, write_bps => $write_kbps * 1000, write_latency => $write_latency / 1000 };
}
}
1;
__END__
=head1 MODE
Check hba usages.
=over 8
=item B<--cem-host>
Compellent Entreprise Manager hostname (Required).
=item B<--cem-user>
Compellent Entreprise Manager username (Required).
=item B<--cem-password>
Compellent Entreprise Manager password (Required).
=item B<--cem-port>
Compellent Entreprise Manager port (Default: 3033).
=item B<--sdk-path-dll>
Path to 'DellStorage.ApiCommandSet.dll' (Required).
=item B<--timeout>
Set timeout time for command execution (Default: 50 sec)
=item B<--no-ps>
Don't encode powershell. To be used with --command and 'type' command.
=item B<--command>
Command to get information (Default: 'powershell.exe').
Can be changed if you have output in a file. To be used with --no-ps option!!!
=item B<--command-path>
Command path (Default: none).
=item B<--command-options>
Command options (Default: '-InputFormat none -NoLogo -EncodedCommand').
=item B<--ps-exec-only>
Print powershell output.
=item B<--ps-sc-filter>
Filter Storage Center (only wilcard '*' can be used. In Powershell).
=item B<--start-time>
Begin time for counters sampling. If not set, 30 minutes before the end-time option or current time
Format: 2016-05-25T10:30:00
=item B<--end-time>
End time for counters sampling. If not set, the current execution time.
Format: 2016-05-25T15:30:00
=item B<--timezone>
Timezone of time options.
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^read-iops$'
=item B<--warning-*>
Threshold warning.
Can be: 'read-iops', 'read-usage', 'read-latency',
'write-iops', 'write-usage', 'write-latency'.
=item B<--critical-*>
Threshold critical.
Can be: 'read-iops', 'read-usage', 'read-latency',
'write-iops', 'write-usage', 'write-latency'.
=back
=cut

View File

@ -31,6 +31,7 @@ sub new {
$self->{version} = '0.1';
%{$self->{modes}} = (
'hba-usage' => 'storage::dell::compellent::local::mode::hbausage',
'volume-usage' => 'storage::dell::compellent::local::mode::volumeusage',
);