From 9deb7bf7ca61ff6c85194546caa9962f1e19fee8 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 23 May 2019 16:34:05 +0200 Subject: [PATCH] Fix #1514 --- .../terastation/snmp/mode/arrayusage.pm | 156 ++++++++++++++++++ .../terastation/snmp/mode/components/disk.pm | 70 ++++++++ .../terastation/snmp/mode/components/iscsi.pm | 69 ++++++++ .../terastation/snmp/mode/components/psu.pm | 67 ++++++++ .../buffalo/terastation/snmp/mode/hardware.pm | 121 ++++++++++++++ .../buffalo/terastation/snmp/plugin.pm | 54 ++++++ 6 files changed, 537 insertions(+) create mode 100644 centreon-plugins/storage/buffalo/terastation/snmp/mode/arrayusage.pm create mode 100644 centreon-plugins/storage/buffalo/terastation/snmp/mode/components/disk.pm create mode 100644 centreon-plugins/storage/buffalo/terastation/snmp/mode/components/iscsi.pm create mode 100644 centreon-plugins/storage/buffalo/terastation/snmp/mode/components/psu.pm create mode 100644 centreon-plugins/storage/buffalo/terastation/snmp/mode/hardware.pm create mode 100644 centreon-plugins/storage/buffalo/terastation/snmp/plugin.pm diff --git a/centreon-plugins/storage/buffalo/terastation/snmp/mode/arrayusage.pm b/centreon-plugins/storage/buffalo/terastation/snmp/mode/arrayusage.pm new file mode 100644 index 000000000..89e47a1e5 --- /dev/null +++ b/centreon-plugins/storage/buffalo/terastation/snmp/mode/arrayusage.pm @@ -0,0 +1,156 @@ +# +# 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::buffalo::terastation::snmp::mode::arrayusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +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}->{prct_used} = $options{new_datas}->{$self->{instance} . '_nasArrayUsed'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_nasArrayCapacity'} * 1024 * 1024 * 1024; + $self->{result_values}->{used} = int($self->{result_values}->{prct_used} * $self->{result_values}->{total} / 100); + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + 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 arrays are ok' } + ]; + + $self->{maps_counters}->{array} = [ + { label => 'usage', nlabel => 'array.space.usage.bytes', set => { + key_values => [ { name => 'display' }, { name => 'nasArrayCapacity' }, { name => 'nasArrayUsed' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + threshold_use => 'prct_used', + perfdatas => [ + { label => 'used', value => 'used', template => '%s', + unit => 'B', min => 0, max => 'total', cast_int => 1 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub prefix_array_output { + my ($self, %options) = @_; + + return "Array '" . $options{instance_value}->{display} . "' "; +} + +my $mapping = { + nasArrayCapacity => { oid => '.1.3.6.1.4.1.5227.27.1.3.1.3' }, # in GB + nasArrayUsed => { oid => '.1.3.6.1.4.1.5227.27.1.3.1.4' }, # in % +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_nasArrayEntry = '.1.3.6.1.4.1.5227.27.1.3.1'; + my $snmp_result = $options{snmp}->get_table(oid => $oid_nasArrayEntry, end => $mapping->{nasArrayUsed}->{oid}, nothing_quit => 1); + + $self->{array} = {}; + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{nasArrayCapacity}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $instance !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $instance . "': no matching array name.", debug => 1); + next; + } + if ($result->{nasArrayUsed} == -1) { + $self->{output}->output_add(long_msg => "skipping '" . $instance . "': array not used.", debug => 1); + next; + } + + $self->{array}->{$instance} = { display => $instance, %$result }; + } + + if (scalar(keys %{$self->{array}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No array found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check array usages. + +=over 8 + +=item B<--filter-name> + +Filter by name (regexp can be used). + +=item B<--warning-usage> + +Threshold warning (in percent). + +=item B<--critical-usage> + +Threshold critical (in percent). + +=back + +=cut diff --git a/centreon-plugins/storage/buffalo/terastation/snmp/mode/components/disk.pm b/centreon-plugins/storage/buffalo/terastation/snmp/mode/components/disk.pm new file mode 100644 index 000000000..e9df170b1 --- /dev/null +++ b/centreon-plugins/storage/buffalo/terastation/snmp/mode/components/disk.pm @@ -0,0 +1,70 @@ +# +# 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::buffalo::terastation::snmp::::mode::components::disk; + +use strict; +use warnings; + +my %map_disk_status = ( + 1 => 'notSupport', 1 => 'normal', 2 => 'array1', 3 => 'array2', + 4 => 'standby', 5 => 'degrade', 6 => 'remove', 7 => 'standbyRemoved', + 8 => 'degradeRemoved', 9 => 'removeRemoved', 10 => 'array3', + 11 => 'array4', 12 => 'mediaCartridge', 13 => 'array5', 14 => 'array6', +); + +my $mapping = { + nasDiskStatus => { oid => '.1.3.6.1.4.1.5227.27.1.2.1.2', map => \%map_disk_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping->{nasDiskStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking disks"); + $self->{components}->{disk} = { name => 'disks', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'disk')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping->{nasDiskStatus}->{oid} }})) { + $oid =~ /^$mapping->{nasDiskStatus}->{oid}\.(.*)$/; + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{nasDiskStatus}->{oid} }, instance => $instance); + + next if ($self->check_filter(section => 'disk', instance => $instance)); + $self->{components}->{disk}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("disk '%s' status is '%s' [instance: %s].", + $instance, $result->{nasDiskStatus}, $instance + )); + my $exit = $self->get_severity(section => 'disk', value => $result->{nasDiskStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Disk '%s' status is '%s'", + $instance, $result->{nasDiskStatus})); + } + } +} + +1; diff --git a/centreon-plugins/storage/buffalo/terastation/snmp/mode/components/iscsi.pm b/centreon-plugins/storage/buffalo/terastation/snmp/mode/components/iscsi.pm new file mode 100644 index 000000000..f8162bc4a --- /dev/null +++ b/centreon-plugins/storage/buffalo/terastation/snmp/mode/components/iscsi.pm @@ -0,0 +1,69 @@ +# +# 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::buffalo::terastation::snmp::::mode::components::iscsi; + +use strict; +use warnings; + +my %map_iscsi_status = ( + 1 => 'unknown', 1 => 'connected', 2 => 'standing-by', +); + +my $mapping = { + nasISCSIName => { oid => '.1.3.6.1.4.1.5227.27.1.9.1.2' }, + nasISCSIStatus => { oid => '.1.3.6.1.4.1.5227.27.1.9.1.3', map => \%map_iscsi_status }, +}; +my $nasISCSIEntry = '.1.3.6.1.4.1.5227.27.1.9.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $nasISCSIEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking iscsi"); + $self->{components}->{iscsi} = { name => 'iscsi', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'iscsi')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $nasISCSIEntry }})) { + next if ($oid !~ /^$mapping->{nasISCSIStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $nasISCSIEntry }, instance => $instance); + + next if ($self->check_filter(section => 'iscsi', instance => $instance, name => $result->{nasISCSIName})); + $self->{components}->{iscsi}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("iscsi '%s' status is '%s' [instance: %s].", + $result->{nasISCSIName}, $result->{nasISCSIStatus}, $instance + )); + my $exit = $self->get_severity(section => 'iscsi', value => $result->{nasISCSIStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Iscsi '%s' status is '%s'", + $result->{nasISCSIName}, $result->{nasISCSIStatus})); + } + } +} + +1; diff --git a/centreon-plugins/storage/buffalo/terastation/snmp/mode/components/psu.pm b/centreon-plugins/storage/buffalo/terastation/snmp/mode/components/psu.pm new file mode 100644 index 000000000..88ef41881 --- /dev/null +++ b/centreon-plugins/storage/buffalo/terastation/snmp/mode/components/psu.pm @@ -0,0 +1,67 @@ +# +# 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::buffalo::terastation::snmp::::mode::components::psu; + +use strict; +use warnings; + +my %map_psu_status = ( + -1 => 'unknown', 1 => 'fine', 2 => 'broken', +); + +my $mapping = { + nasRPSUStatus => { oid => '.1.3.6.1.4.1.5227.27.1.8.1.2', map => \%map_psu_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping->{nasRPSUStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking redundant power supplies"); + $self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'psu')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{ $mapping->{nasRPSUStatus}->{oid} }})) { + $oid =~ /^$mapping->{nasRPSUStatus}->{oid}\.(.*)$/; + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{nasRPSUStatus}->{oid} }, instance => $instance); + + next if ($self->check_filter(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("redundant psu '%s' status is '%s' [instance: %s].", + $instance, $result->{nasRPSUStatus}, $instance + )); + my $exit = $self->get_severity(section => 'psu', value => $result->{nasRPSUStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Redundant psu '%s' status is '%s'", + $instance, $result->{nasRPSUStatus})); + } + } +} + +1; diff --git a/centreon-plugins/storage/buffalo/terastation/snmp/mode/hardware.pm b/centreon-plugins/storage/buffalo/terastation/snmp/mode/hardware.pm new file mode 100644 index 000000000..d6c53527e --- /dev/null +++ b/centreon-plugins/storage/buffalo/terastation/snmp/mode/hardware.pm @@ -0,0 +1,121 @@ +# +# 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::buffalo::terastation::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(disk|psu|iscsi)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + disk => [ + ['notSupport', 'WARNING'], + ['normal', 'OK'], + ['array1', 'OK'], + ['array2', 'OK'], + ['standby', 'OK'], + ['degrade', 'WARNING'], + ['remove', 'OK'], + ['standbyRemoved', 'OK'], + ['degradeRemoved', 'WARNING'], + ['removeRemoved', 'OK'], + ['array3', 'OK'], + ['array4', 'OK'], + ['mediaCartridge', 'OK'], + ['array5', 'OK'], + ['array6', 'OK'], + ], + iscsi => [ + ['unknown', 'WARNING'], + ['connected', 'OK'], + ['standing-by', 'OK'], + ], + psu => [ + ['unknown', 'WARNING'], + ['fine', 'OK'], + ['broken', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'storage::buffalo::terastation::snmp::::mode::components'; + $self->{components_module} = ['disk', 'psu', 'iscsi']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, force_new_perfdata => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'disk', 'iscsi', 'psu'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=disk --filter=psu) +Can also exclude specific instance: --filter=psu,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='disk,OK,^(?!(degrade)$)' + +=back + +=cut diff --git a/centreon-plugins/storage/buffalo/terastation/snmp/plugin.pm b/centreon-plugins/storage/buffalo/terastation/snmp/plugin.pm new file mode 100644 index 000000000..e7f7e9125 --- /dev/null +++ b/centreon-plugins/storage/buffalo/terastation/snmp/plugin.pm @@ -0,0 +1,54 @@ +# +# 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::buffalo::terastation::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'array-usage' => 'storage::buffalo::terastation::snmp::mode::arrayusage', + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'hardware' => 'storage::buffalo::terastation::snmp::mode::hardware', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'load' => 'snmp_standard::mode::loadaverage', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'memory' => 'snmp_standard::mode::memory', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Buffalo TeraStation in SNMP. + +=cut