From 57c62c822c91adf3c8265d3c61ecd7a3e4e07be9 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 29 Mar 2019 14:50:51 +0100 Subject: [PATCH] Fix #429 --- .../dell/equallogic/snmp/mode/arraystats.pm | 348 ----------------- .../dell/equallogic/snmp/mode/arrayusage.pm | 363 ++++++++++++++++++ .../dell/equallogic/snmp/mode/diskusage.pm | 356 ++++++++--------- .../dell/equallogic/snmp/mode/poolusage.pm | 193 +++------- storage/dell/equallogic/snmp/plugin.pm | 14 +- 5 files changed, 589 insertions(+), 685 deletions(-) delete mode 100644 storage/dell/equallogic/snmp/mode/arraystats.pm create mode 100644 storage/dell/equallogic/snmp/mode/arrayusage.pm diff --git a/storage/dell/equallogic/snmp/mode/arraystats.pm b/storage/dell/equallogic/snmp/mode/arraystats.pm deleted file mode 100644 index 54797cfb6..000000000 --- a/storage/dell/equallogic/snmp/mode/arraystats.pm +++ /dev/null @@ -1,348 +0,0 @@ -# -# Copyright 2019 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::equallogic::snmp::mode::arraystats; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::values; -use centreon::plugins::statefile; - -my $maps_counters = { - '000_connections' => { set => { - key_values => [ { name => 'eqlMemberNumberOfConnections' }, { name => 'display' } ], - output_template => 'iSCSI connections : %s', - perfdatas => [ - { label => 'connections', value => 'eqlMemberNumberOfConnections_absolute', template => '%s', - min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - '001_ext-connections' => { set => { - key_values => [ { name => 'eqlMemberNumberOfExtConnections' }, { name => 'display' } ], - output_template => 'External iSCSI connections : %s', - perfdatas => [ - { label => 'ext_connections', value => 'eqlMemberNumberOfExtConnections_absolute', template => '%s', - min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - '002_global-read-avg-latency' => { set => { - key_values => [ { name => 'eqlMemberReadAvgLatency' }, { name => 'display' } ], - output_template => 'Global read average latency : %s ms', - perfdatas => [ - { label => 'global_read_avg_latency', value => 'eqlMemberReadAvgLatency_absolute', template => '%s', - unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - '003_global-write-avg-latency' => { set => { - key_values => [ { name => 'eqlMemberWriteAvgLatency' }, { name => 'display' } ], - output_template => 'Global write average latency : %s ms', - perfdatas => [ - { label => 'global_write_avg_latency', value => 'eqlMemberWriteAvgLatency_absolute', template => '%s', - unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - '005_read-avg-latency' => { set => { - key_values => [ { name => 'eqlMemberReadLatency', diff => 1 }, { name => 'eqlMemberReadOpCount', diff => 1 }, { name => 'display' } ], - output_template => 'Read average latency : %.2f ms', threshold_use => 'read_avg_latency', output_use => 'read_avg_latency', - closure_custom_calc => \&custom_read_avg_latency_calc, - perfdatas => [ - { label => 'read_avg_latency', value => 'read_avg_latency', template => '%.2f', - unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - '006_write-avg-latency' => { set => { - key_values => [ { name => 'eqlMemberWriteLatency', diff => 1 }, { name => 'eqlMemberWriteOpCount', diff => 1 }, { name => 'display' } ], - output_template => 'Write average latency : %.2f ms', threshold_use => 'write_avg_latency', output_use => 'write_avg_latency', - closure_custom_calc => \&custom_write_avg_latency_calc, - perfdatas => [ - { label => 'write_avg_latency', value => 'write_avg_latency', template => '%.2f', - unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - '007_read-iops' => { set => { - key_values => [ { name => 'eqlMemberReadOpCount', diff => 1 }, { name => 'display' } ], - per_second => 1, - output_template => 'Read IOPs : %.2f', - perfdatas => [ - { label => 'read_iops', template => '%.2f', value => 'eqlMemberReadOpCount_per_second', - unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - '008_write-iops' => { set => { - key_values => [ { name => 'eqlMemberWriteOpCount', diff => 1 }, { name => 'display' } ], - per_second => 1, - output_template => 'Write IOPs : %.2f', - perfdatas => [ - { label => 'write_iops', template => '%.2f', value => 'eqlMemberWriteOpCount_per_second', - unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - - '010_traffic-in' => { set => { - key_values => [ { name => 'eqlMemberRxData', diff => 1 }, { name => 'display' } ], - per_second => 1, output_change_bytes => 2, - output_template => 'Traffic In : %s %s/s', - perfdatas => [ - { label => 'traffic_in', value => 'eqlMemberRxData_per_second', template => '%s', - unit => 'b/s', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - '011_traffic-out' => { set => { - key_values => [ { name => 'eqlMemberTxData', diff => 1 }, { name => 'display' } ], - per_second => 1, output_change_bytes => 2, - output_template => 'Traffic Out : %s %s/s', - perfdatas => [ - { label => 'traffic_out', value => 'eqlMemberTxData_per_second', template => '%s', - unit => 'b/s', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, -}; - -sub custom_write_avg_latency_calc { - my ($self, %options) = @_; - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - my $diff_op = $options{new_datas}->{$self->{instance} . '_eqlMemberWriteOpCount'} - $options{old_datas}->{$self->{instance} . '_eqlMemberWriteOpCount'}; - my $diff_latency = $options{new_datas}->{$self->{instance} . '_eqlMemberWriteLatency'} - $options{old_datas}->{$self->{instance} . '_eqlMemberWriteLatency'}; - if ($diff_op == 0) { - $self->{result_values}->{write_avg_latency} = 0; - } else { - $self->{result_values}->{write_avg_latency} = $diff_latency / $diff_op; - } - - return 0; -} - -sub custom_read_avg_latency_calc { - my ($self, %options) = @_; - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - my $diff_op = $options{new_datas}->{$self->{instance} . '_eqlMemberReadOpCount'} - $options{old_datas}->{$self->{instance} . '_eqlMemberReadOpCount'}; - my $diff_latency = $options{new_datas}->{$self->{instance} . '_eqlMemberReadLatency'} - $options{old_datas}->{$self->{instance} . '_eqlMemberReadLatency'}; - if ($diff_op == 0) { - $self->{result_values}->{read_avg_latency} = 0; - } else { - $self->{result_values}->{read_avg_latency} = $diff_latency / $diff_op; - } - return 0; -} - -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 => - { - "filter-name:s" => { name => 'filter_name' }, - }); - $self->{statefile_value} = centreon::plugins::statefile->new(%options); - - foreach (keys %{$maps_counters}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - $maps_counters->{$_}->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value}, - output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); - } - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); - } - - $self->{statefile_value}->check_options(%options); -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - $self->{hostname} = $self->{snmp}->get_hostname(); - $self->{snmp_port} = $self->{snmp}->get_port(); - - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{member_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All array statistics are ok'); - } - - $self->{new_datas} = {}; - $self->{statefile_value}->read(statefile => "dell_equallogic_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); - $self->{new_datas}->{last_timestamp} = time(); - - foreach my $id (sort keys %{$self->{member_selected}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->set(instance => $id); - - my ($value_check) = $maps_counters->{$_}->{obj}->execute(new_datas => $self->{new_datas}, - values => $self->{member_selected}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); - push @exits, $exit2; - - my $output = $maps_counters->{$_}->{obj}->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $maps_counters->{$_}->{obj}->perfdata(level => 1, extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "'" . $self->{member_selected}->{$id}->{display} . "' $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "'" . $self->{member_selected}->{$id}->{display} . "' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "'" . $self->{member_selected}->{$id}->{display} . "' $long_msg"); - } - } - - $self->{statefile_value}->write(data => $self->{new_datas}); - $self->{output}->display(); - $self->{output}->exit(); -} - -my $mapping = { - eqlMemberNumberOfConnections => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.1' }, - eqlMemberReadLatency => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.2' }, - eqlMemberWriteLatency => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.3' }, - eqlMemberReadAvgLatency => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.4' }, - eqlMemberWriteAvgLatency => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.5' }, - eqlMemberReadOpCount => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.6' }, - eqlMemberWriteOpCount => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.7' }, - eqlMemberTxData => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.8' }, - eqlMemberRxData => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.9' }, - eqlMemberNumberOfExtConnections => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.10' }, -}; - -sub manage_selection { - my ($self, %options) = @_; - - my $oid_eqlMemberName = '.1.3.6.1.4.1.12740.2.1.1.1.9'; - my $oid_eqlMemberConnEntry = '.1.3.6.1.4.1.12740.2.1.12.1'; - - $self->{member_selected} = {}; - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_eqlMemberName }, - { oid => $oid_eqlMemberConnEntry }, - ], - nothing_quit => 1); - - foreach my $oid (keys %{$self->{results}->{$oid_eqlMemberConnEntry}}) { - next if ($oid !~ /^$mapping->{eqlMemberNumberOfConnections}->{oid}\.(\d+\.\d+)/); - my $member_instance = $1; - next if (!defined($self->{results}->{$oid_eqlMemberName}->{$oid_eqlMemberName . '.' . $member_instance})); - my $member_name = $self->{results}->{$oid_eqlMemberName}->{$oid_eqlMemberName . '.' . $member_instance}; - - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_eqlMemberConnEntry}, instance => $member_instance); - if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $member_name !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $member_name . "': no matching filter."); - next; - } - - $self->{member_selected}->{$member_name} = { display => $member_name, - %{$result} - }; - $self->{member_selected}->{$member_name}->{eqlMemberTxData} *= 8 if (defined($self->{member_selected}->{$member_name}->{eqlMemberTxData})); - $self->{member_selected}->{$member_name}->{eqlMemberRxData} *= 8 if (defined($self->{member_selected}->{$member_name}->{eqlMemberRxData})); - } - - if (scalar(keys %{$self->{member_selected}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "No entry found."); - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check global array statistics. - -=over 8 - -=item B<--warning-*> - -Threshold warning. -Can be: 'connections', 'ext-connections', 'global-read-avg-latency' (ms), 'global-write-avg-latency' (ms), -'read-avg-latency' (ms), 'write-avg-latency' (ms), 'read-iops' (iops), 'write-iops (iops), 'traffic-in' (b/s), 'traffic-out' (b/s). - -=item B<--critical-*> - -Threshold critical. -Can be: 'connections', 'ext-connections', 'global-read-avg-latency' (ms), 'global-write-avg-latency' (ms), -'read-avg-latency' (ms), 'write-avg-latency' (ms), 'read-iops' (iops), 'write-iops (iops), 'traffic-in' (b/s), 'traffic-out' (b/s). - -=item B<--filter-name> - -Filter disk name (can be a regexp). - -=back - -=cut diff --git a/storage/dell/equallogic/snmp/mode/arrayusage.pm b/storage/dell/equallogic/snmp/mode/arrayusage.pm new file mode 100644 index 000000000..a1e11eab9 --- /dev/null +++ b/storage/dell/equallogic/snmp/mode/arrayusage.pm @@ -0,0 +1,363 @@ +# +# Copyright 2019 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::equallogic::snmp::mode::arrayusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub custom_write_avg_latency_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + my $diff_op = $options{new_datas}->{$self->{instance} . '_eqlMemberWriteOpCount'} - $options{old_datas}->{$self->{instance} . '_eqlMemberWriteOpCount'}; + my $diff_latency = $options{new_datas}->{$self->{instance} . '_eqlMemberWriteLatency'} - $options{old_datas}->{$self->{instance} . '_eqlMemberWriteLatency'}; + if ($diff_op == 0) { + $self->{result_values}->{write_avg_latency} = 0; + } else { + $self->{result_values}->{write_avg_latency} = $diff_latency / $diff_op; + } + + return 0; +} + +sub custom_read_avg_latency_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + my $diff_op = $options{new_datas}->{$self->{instance} . '_eqlMemberReadOpCount'} - $options{old_datas}->{$self->{instance} . '_eqlMemberReadOpCount'}; + my $diff_latency = $options{new_datas}->{$self->{instance} . '_eqlMemberReadLatency'} - $options{old_datas}->{$self->{instance} . '_eqlMemberReadLatency'}; + if ($diff_op == 0) { + $self->{result_values}->{read_avg_latency} = 0; + } else { + $self->{result_values}->{read_avg_latency} = $diff_latency / $diff_op; + } + return 0; +} + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $extra_label = ''; + if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { + $extra_label .= '_' . $self->{result_values}->{display}; + } + $self->{output}->perfdata_add(label => 'used' . $extra_label, unit => 'B', + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + + my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_eqlMemberTotalStorage'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_eqlMemberUsedStorage'}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'array', type => 1, cb_prefix_output => 'prefix_array_output', message_multiple => 'All array usages are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{array} = [ + { label => 'used', set => { + key_values => [ { name => 'display' }, { name => 'eqlMemberTotalStorage' }, { name => 'eqlMemberUsedStorage' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + { label => 'snapshot', set => { + key_values => [ { name => 'eqlMemberSnapStorage' }, { name => 'display' } ], + output_change_bytes => 1, + output_template => 'Snapshot usage : %s %s', + perfdatas => [ + { label => 'snapshost', value => 'eqlMemberSnapStorage_absolute', template => '%s', + unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'replication', set => { + key_values => [ { name => 'eqlMemberReplStorage' }, { name => 'display' } ], + output_change_bytes => 1, + output_template => 'Replication usage : %s %s', + perfdatas => [ + { label => 'replication', value => 'eqlMemberReplStorage_absolute', template => '%s', + unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'connections', set => { + key_values => [ { name => 'eqlMemberNumberOfConnections' }, { name => 'display' } ], + output_template => 'iSCSI connections : %s', + perfdatas => [ + { label => 'connections', value => 'eqlMemberNumberOfConnections_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'ext-connections', display_ok => 0, set => { + key_values => [ { name => 'eqlMemberNumberOfExtConnections' }, { name => 'display' } ], + output_template => 'External iSCSI connections : %s', + perfdatas => [ + { label => 'ext_connections', value => 'eqlMemberNumberOfExtConnections_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'global-read-avg-latency', display_ok => 0, set => { + key_values => [ { name => 'eqlMemberReadAvgLatency' }, { name => 'display' } ], + output_template => 'Global read average latency : %s ms', + perfdatas => [ + { label => 'global_read_avg_latency', value => 'eqlMemberReadAvgLatency_absolute', template => '%s', + unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'global-write-avg-latency', display_ok => 0, set => { + key_values => [ { name => 'eqlMemberWriteAvgLatency' }, { name => 'display' } ], + output_template => 'Global write average latency : %s ms', + perfdatas => [ + { label => 'global_write_avg_latency', value => 'eqlMemberWriteAvgLatency_absolute', template => '%s', + unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'read-avg-latency', set => { + key_values => [ { name => 'eqlMemberReadLatency', diff => 1 }, { name => 'eqlMemberReadOpCount', diff => 1 }, { name => 'display' } ], + output_template => 'Read average latency : %.2f ms', threshold_use => 'read_avg_latency', output_use => 'read_avg_latency', + closure_custom_calc => $self->can('custom_read_avg_latency_calc'), + perfdatas => [ + { label => 'read_avg_latency', value => 'read_avg_latency', template => '%.2f', + unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'write-avg-latency', display_ok => 0, set => { + key_values => [ { name => 'eqlMemberWriteLatency', diff => 1 }, { name => 'eqlMemberWriteOpCount', diff => 1 }, { name => 'display' } ], + output_template => 'Write average latency : %.2f ms', threshold_use => 'write_avg_latency', output_use => 'write_avg_latency', + closure_custom_calc => $self->can('custom_write_avg_latency_calc'), + perfdatas => [ + { label => 'write_avg_latency', value => 'write_avg_latency', template => '%.2f', + unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'read-iops', set => { + key_values => [ { name => 'eqlMemberReadOpCount', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'Read IOPs : %.2f', + perfdatas => [ + { label => 'read_iops', template => '%.2f', value => 'eqlMemberReadOpCount_per_second', + unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'write-iops', set => { + key_values => [ { name => 'eqlMemberWriteOpCount', diff => 1 }, { name => 'display' } ], + per_second => 1, + output_template => 'Write IOPs : %.2f', + perfdatas => [ + { label => 'write_iops', template => '%.2f', value => 'eqlMemberWriteOpCount_per_second', + unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'traffic-in', display_ok => 0, set => { + key_values => [ { name => 'eqlMemberRxData', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic In : %s %s/s', + perfdatas => [ + { label => 'traffic_in', value => 'eqlMemberRxData_per_second', template => '%s', + unit => 'b/s', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'traffic-out', display_ok => 0, set => { + key_values => [ { name => 'eqlMemberTxData', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic Out : %s %s/s', + perfdatas => [ + { label => 'traffic_out', value => 'eqlMemberTxData_per_second', template => '%s', + unit => 'b/s', min => 0, cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_array_output { + my ($self, %options) = @_; + + return "Array '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +my $mapping = { + eqlMemberTotalStorage => { oid => '.1.3.6.1.4.1.12740.2.1.10.1.1' }, # MB + eqlMemberUsedStorage => { oid => '.1.3.6.1.4.1.12740.2.1.10.1.2' }, # MB + eqlMemberSnapStorage => { oid => '.1.3.6.1.4.1.12740.2.1.10.1.3' }, # MB + eqlMemberReplStorage => { oid => '.1.3.6.1.4.1.12740.2.1.10.1.4' }, # MB + + eqlMemberNumberOfConnections => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.1' }, + eqlMemberReadLatency => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.2' }, + eqlMemberWriteLatency => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.3' }, + eqlMemberReadAvgLatency => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.4' }, + eqlMemberWriteAvgLatency => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.5' }, + eqlMemberReadOpCount => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.6' }, + eqlMemberWriteOpCount => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.7' }, + eqlMemberTxData => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.8' }, + eqlMemberRxData => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.9' }, + eqlMemberNumberOfExtConnections => { oid => '.1.3.6.1.4.1.12740.2.1.12.1.10' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + my $oid_eqlMemberName = '.1.3.6.1.4.1.12740.2.1.1.1.9'; + + $self->{array} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_eqlMemberName, nothing_quit => 1); + foreach my $oid (keys %{$snmp_result}) { + $oid =~ /^$oid_eqlMemberName\.(.*)$/; + my $instance = $1; + my $name = $snmp_result->{$oid_eqlMemberName . '.' . $instance}; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping array '" . $name . "'.", debug => 1); + next; + } + + $self->{array}->{$instance} = { display => $name }; + } + + if (scalar(keys %{$self->{array}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No entry found."); + $self->{output}->option_exit(); + } + + $options{snmp}->load(oids => [ + map($_->{oid}, values(%$mapping)) + ], + instances => [keys %{$self->{array}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{array}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + $result->{eqlMemberTxData} *= 8 if (defined($result->{eqlMemberTxData})); + $result->{eqlMemberRxData} *= 8 if (defined($result->{eqlMemberRxData})); + + $result->{eqlMemberTotalStorage} *= 1024 * 1024; + $result->{eqlMemberUsedStorage} *= 1024 * 1024; + $result->{eqlMemberSnapStorage} *= 1024 * 1024; + $result->{eqlMemberReplStorage} *= 1024 * 1024; + + $self->{array}->{$_} = { %{$self->{array}->{$_}}, %$result }; + } + + $self->{cache_name} = "dell_equallogic_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check array member usage. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'used' (%), 'snapshot' (B), 'replication' (B), +'connections', 'ext-connections', 'global-read-avg-latency' (ms), 'global-write-avg-latency' (ms), +'read-avg-latency' (ms), 'write-avg-latency' (ms), 'read-iops' (iops), 'write-iops (iops), 'traffic-in' (b/s), 'traffic-out' (b/s). + +=item B<--critical-*> + +Threshold critical. +Can be: 'used' (%), 'snapshot' (B), 'replication' (B), +'connections', 'ext-connections', 'global-read-avg-latency' (ms), 'global-write-avg-latency' (ms), +'read-avg-latency' (ms), 'write-avg-latency' (ms), 'read-iops' (iops), 'write-iops (iops), 'traffic-in' (b/s), 'traffic-out' (b/s). + +=item B<--filter-name> + +Filter array name (can be a regexp). + +=back + +=cut diff --git a/storage/dell/equallogic/snmp/mode/diskusage.pm b/storage/dell/equallogic/snmp/mode/diskusage.pm index 6b1aa6544..224eeab98 100644 --- a/storage/dell/equallogic/snmp/mode/diskusage.pm +++ b/storage/dell/equallogic/snmp/mode/diskusage.pm @@ -20,231 +20,178 @@ package storage::dell::equallogic::snmp::mode::diskusage; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use Digest::MD5 qw(md5_hex); -my $maps_counters = { - '000_used' => { set => { - key_values => [ { name => 'display' }, { name => 'total' }, { name => 'used' } ], - closure_custom_calc => \&custom_usage_calc, - closure_custom_output => \&custom_usage_output, - closure_custom_perfdata => \&custom_usage_perfdata, - closure_custom_threshold_check => \&custom_usage_threshold, - } - }, - '001_snapshot' => { set => { - key_values => [ { name => 'snap' }, { name => 'display' } ], - output_change_bytes => 1, - output_template => 'Snapshot usage : %s %s', - perfdatas => [ - { label => 'snapshost', value => 'snap_absolute', template => '%s', - unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, - '002_replication' => { set => { - key_values => [ { name => 'repl' }, { name => 'display' } ], - output_change_bytes => 1, - output_template => 'Replication usage : %s %s', - perfdatas => [ - { label => 'replication', value => 'repl_absolute', template => '%s', - unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, -}; - -sub custom_usage_perfdata { +sub custom_status_output { my ($self, %options) = @_; - - my $extra_label = ''; - if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { - $extra_label .= '_' . $self->{result_values}->{display}; - } - $self->{output}->perfdata_add(label => 'used' . $extra_label, unit => 'B', - value => $self->{result_values}->{used}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), - min => 0, max => $self->{result_values}->{total}); -} -sub custom_usage_threshold { - my ($self, %options) = @_; - - my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); - return $exit; -} - -sub custom_usage_output { - my ($self, %options) = @_; - - my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); - my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); - my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); - - my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + my $msg = 'status : ' . $self->{result_values}->{status} . ' [smart health: ' . $self->{result_values}->{health} . ']'; return $msg; } -sub custom_usage_calc { +sub custom_status_calc { my ($self, %options) = @_; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_eqlDiskStatus'}; + $self->{result_values}->{health} = $options{new_datas}->{$self->{instance} . '_eqlDiskHealth'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; - $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; - $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; - $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total}; - $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; return 0; } +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'disk', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All disk usages are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{disk} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'eqlDiskHealth' }, { name => 'eqlDiskStatus' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'read', set => { + key_values => [ { name => 'eqlDiskStatusBytesRead', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 1, + output_template => 'read : %s %s/s', + perfdatas => [ + { label => 'read_iops', template => '%.2f', value => 'eqlDiskStatusBytesRead_per_second', + unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'write', set => { + key_values => [ { name => 'eqlDiskStatusBytesWritten', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 1, + output_template => 'write : %s %s/s', + perfdatas => [ + { label => 'write', template => '%.2f', value => 'eqlDiskStatusBytesWritten_per_second', + unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'busy-time', set => { + key_values => [ { name => 'eqlDiskStatusBusyTime', diff => 1 }, { name => 'display' } ], + output_template => 'time busy : %s sec', + perfdatas => [ + { label => 'busy_time', template => '%s', value => 'eqlDiskStatusBusyTime_absolute', + unit => 's', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_disk_output { + my ($self, %options) = @_; + + return "Disk '" . $options{instance_value}->{display} . "' "; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; - + $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "filter-name:s" => { name => 'filter_name' }, - }); - - foreach (keys %{$maps_counters}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - $maps_counters->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); - } - + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + "unknown-status:s" => { name => 'unknown_status', default => '' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /on-line|spare|off-line/i' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); - } + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); } -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; +my $map_disk_status = { + 1 => 'on-line', 2 => 'spare', 3 => 'failed', 4 => 'off-line', + 5 => 'alt-sig', 6 => 'too-small', 7 => 'history-of-failures', + 8 => 'unsupported-version', 9 => 'unhealthy', 10 => 'replacement', + 11 => 'encrypted', 12 => 'notApproved', 13 => 'preempt-failed', +}; - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{member_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All disk usages are ok'); - } - - foreach my $id (sort keys %{$self->{member_selected}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->set(instance => $id); - - my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{member_selected}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); - push @exits, $exit2; - - my $output = $maps_counters->{$_}->{obj}->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $maps_counters->{$_}->{obj}->perfdata(level => 1, extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "Disk '" . $self->{member_selected}->{$id}->{display} . "' $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "Disk '" . $self->{member_selected}->{$id}->{display} . "' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "Disk '" . $self->{member_selected}->{$id}->{display} . "' $long_msg"); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} +my $map_disk_health = { + 0 => 'smart-status-not-available', + 1 => 'smart-ok', + 2 => 'smart-tripped', +}; my $mapping = { - eqlMemberTotalStorage => { oid => '.1.3.6.1.4.1.12740.2.1.10.1.1' }, # MB - eqlMemberUsedStorage => { oid => '.1.3.6.1.4.1.12740.2.1.10.1.2' }, # MB - eqlMemberSnapStorage => { oid => '.1.3.6.1.4.1.12740.2.1.10.1.3' }, # MB - eqlMemberReplStorage => { oid => '.1.3.6.1.4.1.12740.2.1.10.1.4' }, # MB + eqlDiskHealth => { oid => '.1.3.6.1.4.1.12740.3.1.1.1.17', map => $map_disk_health }, + eqlDiskStatusBytesRead => { oid => '.1.3.6.1.4.1.12740.3.1.2.1.2' }, # MB + eqlDiskStatusBytesWritten => { oid => '.1.3.6.1.4.1.12740.3.1.2.1.3' }, # MB + eqlDiskStatusBusyTime => { oid => '.1.3.6.1.4.1.12740.3.1.2.1.4' }, # in seconds }; sub manage_selection { my ($self, %options) = @_; - - my $oid_eqlMemberName = '.1.3.6.1.4.1.12740.2.1.1.1.9'; - my $oid_eqlMemberStorageEntry = '.1.3.6.1.4.1.12740.2.1.10.1'; - $self->{member_selected} = {}; - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_eqlMemberName }, - { oid => $oid_eqlMemberStorageEntry }, - ], - nothing_quit => 1); - foreach my $oid (keys %{$self->{results}->{$oid_eqlMemberStorageEntry}}) { - next if ($oid !~ /^$mapping->{eqlMemberTotalStorage}->{oid}\.(\d+\.\d+)/); - my $member_instance = $1; - next if (!defined($self->{results}->{$oid_eqlMemberName}->{$oid_eqlMemberName . '.' . $member_instance})); - my $member_name = $self->{results}->{$oid_eqlMemberName}->{$oid_eqlMemberName . '.' . $member_instance}; - - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_eqlMemberStorageEntry}, instance => $member_instance); - if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $member_name !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $member_name . "': no matching filter."); - next; - } - - $self->{member_selected}->{$member_name} = { display => $member_name, - total => $result->{eqlMemberTotalStorage} * 1024 * 1024, - used => $result->{eqlMemberUsedStorage} * 1024 * 1024, - snap => $result->{eqlMemberSnapStorage} * 1024 * 1024, - repl => $result->{eqlMemberReplStorage} * 1024 * 1024 - }; + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); } - if (scalar(keys %{$self->{member_selected}}) <= 0) { + my $oid_eqlMemberName = '.1.3.6.1.4.1.12740.2.1.1.1.9'; + my $oid_eqlDiskStatus = '.1.3.6.1.4.1.12740.3.1.1.1.8'; + + $self->{disk} = {}; + my $snmp_result = $options{snmp}->get_multiple_table(oids => [{ oid => $oid_eqlMemberName }, { oid => $oid_eqlDiskStatus }], return_type => 1, nothing_quit => 1); + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$oid_eqlDiskStatus\.(\d+)\.(\d+)\.(\d+)$/); + my $instance = $1 . '.' . $2 . '.' . $3; + my $array_name = $snmp_result->{$oid_eqlMemberName . '.' . $1 . '.' . $2}; + my $name = $array_name . '.' . $3; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping disk '" . $name . "'.", debug => 1); + next; + } + + $self->{disk}->{$instance} = { display => $name, eqlDiskStatus => $map_disk_status->{$snmp_result->{$oid}} }; + } + + if (scalar(keys %{$self->{disk}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No entry found."); $self->{output}->option_exit(); } + + $options{snmp}->load(oids => [ + map($_->{oid}, values(%$mapping)) + ], + instances => [keys %{$self->{disk}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{disk}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + $result->{eqlDiskStatusBytesRead} *= 1024 * 1024; + $result->{eqlDiskStatusBytesWritten} *= 1024 * 1024; + $result->{eqlDiskHealth} = 'n/a' if (!defined($result->{eqlDiskHealth})); + + $self->{disk}->{$_} = { %{$self->{disk}->{$_}}, %$result }; + } + + $self->{cache_name} = "dell_equallogic_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); } 1; @@ -253,24 +200,39 @@ __END__ =head1 MODE -Check disk usages. +Check disk usage. =over 8 -=item B<--warning-*> - -Threshold warning. -Can be: 'used' (%), 'snapshot' (B), 'replication' (B). - -=item B<--critical-*> - -Threshold critical. -Can be: 'used' (%), 'snapshot' (B), 'replication' (B). - =item B<--filter-name> Filter disk name (can be a regexp). +=item B<--unknown-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{health}, %{status}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{health}, %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /on-line|spare|off-line/i'). +Can used special variables like: %{health}, %{status}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'busy-time' (s), 'read-iops' (iops), 'write-iops (iops). + +=item B<--critical-*> + +Threshold critical. +Can be: 'busy-time' (s), 'read-iops' (iops), 'write-iops (iops). + =back =cut diff --git a/storage/dell/equallogic/snmp/mode/poolusage.pm b/storage/dell/equallogic/snmp/mode/poolusage.pm index 7dd00403d..15b7f632a 100644 --- a/storage/dell/equallogic/snmp/mode/poolusage.pm +++ b/storage/dell/equallogic/snmp/mode/poolusage.pm @@ -20,22 +20,10 @@ package storage::dell::equallogic::snmp::mode::poolusage; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; - -my $maps_counters = { - '000_used' => { set => { - key_values => [ { name => 'display' }, { name => 'total' }, { name => 'used' } ], - closure_custom_calc => \&custom_usage_calc, - closure_custom_output => \&custom_usage_output, - closure_custom_perfdata => \&custom_usage_perfdata, - closure_custom_threshold_check => \&custom_usage_threshold, - } - }, -}; sub custom_usage_perfdata { my ($self, %options) = @_; @@ -84,153 +72,92 @@ sub custom_usage_calc { return 0; } +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All Pool usages are ok' } + ]; + + $self->{maps_counters}->{pool} = [ + { label => 'used', set => { + key_values => [ { name => 'display' }, { name => 'total' }, { name => 'used' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub prefix_pool_output { + my ($self, %options) = @_; + + return "Pool '" . $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 => - { - "filter-name:s" => { name => 'filter_name' }, - }); - - foreach (keys %{$maps_counters}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - $maps_counters->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); - } - + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{pool_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All Pool usages are ok'); - } - - foreach my $id (sort keys %{$self->{pool_selected}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->set(instance => $id); - - my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{pool_selected}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); - push @exits, $exit2; - - my $output = $maps_counters->{$_}->{obj}->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $maps_counters->{$_}->{obj}->perfdata(level => 1, extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "Pool '" . $self->{pool_selected}->{$id}->{display} . "' $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "Pool '" . $self->{pool_selected}->{$id}->{display} . "' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "Pool '" . $self->{pool_selected}->{$id}->{display} . "' $long_msg"); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} - my $mapping = { - eqlStoragePoolStatsSpace => { oid => '.1.3.6.1.4.1.12740.16.1.2.1.1' }, # MB + eqlStoragePoolStatsSpace => { oid => '.1.3.6.1.4.1.12740.16.1.2.1.1' }, # MB eqlStoragePoolStatsSpaceUsed => { oid => '.1.3.6.1.4.1.12740.16.1.2.1.2' }, # MB }; sub manage_selection { my ($self, %options) = @_; - - my $oid_eqlStoragePoolName = '.1.3.6.1.4.1.12740.16.1.1.1.3'; - my $oid_eqlStoragePoolStatsEntry = '.1.3.6.1.4.1.12740.16.1.2.1'; - if ($self->{snmp}->is_snmpv1()) { + if ($options{snmp}->is_snmpv1()) { $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); $self->{output}->option_exit(); } - $self->{pool_selected} = {}; - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_eqlStoragePoolName }, - { oid => $oid_eqlStoragePoolStatsEntry, start => $mapping->{eqlStoragePoolStatsSpace}->{oid}, end => $mapping->{eqlStoragePoolStatsSpaceUsed}->{oid}}, - ], - nothing_quit => 1); + my $oid_eqlStoragePoolName = '.1.3.6.1.4.1.12740.16.1.1.1.3'; - foreach my $oid (keys %{$self->{results}->{$oid_eqlStoragePoolStatsEntry}}) { - next if ($oid !~ /^$mapping->{eqlStoragePoolStatsSpace}->{oid}\.(\d+\.\d+)/); - my $pool_instance = $1; - next if (!defined($self->{results}->{$oid_eqlStoragePoolName}->{$oid_eqlStoragePoolName . '.' . $pool_instance})); - my $pool_name = $self->{results}->{$oid_eqlStoragePoolName}->{$oid_eqlStoragePoolName . '.' . $pool_instance}; - - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_eqlStoragePoolStatsEntry}, instance => $pool_instance); + $self->{pool} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_eqlStoragePoolName, nothing_quit => 1); + foreach my $oid (keys %{$snmp_result}) { + $oid =~ /^$oid_eqlStoragePoolName\.(.*)$/; + my $instance = $1; + my $name = $snmp_result->{$oid_eqlStoragePoolName . '.' . $instance}; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $pool_name !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $pool_name . "': no matching filter."); + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping pool '" . $name . "'.", debug => 1); next; } - if ($result->{eqlStoragePoolStatsSpace} == 0) { - $self->{output}->output_add(long_msg => "Skipping '" . $pool_name . "': total size is 0."); - next; - } - - $self->{pool_selected}->{$pool_name} = { display => $pool_name, - total => $result->{eqlStoragePoolStatsSpace} * 1024 * 1024, - used => $result->{eqlStoragePoolStatsSpaceUsed} * 1024 * 1024, - }; + + $self->{pool}->{$instance} = { display => $name }; } - - if (scalar(keys %{$self->{pool_selected}}) <= 0) { + + if (scalar(keys %{$self->{pool}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No entry found."); $self->{output}->option_exit(); } + + $options{snmp}->load(oids => [ + $mapping->{eqlStoragePoolStatsSpace}->{oid}, $mapping->{eqlStoragePoolStatsSpaceUsed}->{oid}, + ], + instances => [keys %{$self->{pool}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{pool}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + $self->{pool}->{$_}->{total} = $result->{eqlStoragePoolStatsSpace} * 1024 * 1024; + $self->{pool}->{$_}->{used} = $result->{eqlStoragePoolStatsSpaceUsed} * 1024 * 1024; + } } 1; diff --git a/storage/dell/equallogic/snmp/plugin.pm b/storage/dell/equallogic/snmp/plugin.pm index 56a413f21..adc1e2fea 100644 --- a/storage/dell/equallogic/snmp/plugin.pm +++ b/storage/dell/equallogic/snmp/plugin.pm @@ -31,13 +31,13 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'array-stats' => 'storage::dell::equallogic::snmp::mode::arraystats', - 'disk-usage' => 'storage::dell::equallogic::snmp::mode::diskusage', - 'hardware' => 'storage::dell::equallogic::snmp::mode::hardware', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'pool-usage' => 'storage::dell::equallogic::snmp::mode::poolusage', - ); + 'array-usage' => 'storage::dell::equallogic::snmp::mode::arrayusage', + 'disk-usage' => 'storage::dell::equallogic::snmp::mode::diskusage', + 'hardware' => 'storage::dell::equallogic::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'pool-usage' => 'storage::dell::equallogic::snmp::mode::poolusage', + ); return $self; }