From d70cb3a13c8516edf8ec1a0e6c814245e6ddcf43 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Mon, 15 Dec 2014 16:41:28 +0100 Subject: [PATCH] Refs #5627 Improve netapp --- .../netapp/mode/components/communication.pm | 85 +++ .../netapp/mode/components/electronics.pm | 89 +++ .../storage/netapp/mode/components/fan.pm | 107 ++++ .../storage/netapp/mode/components/psu.pm | 89 +++ .../netapp/mode/components/temperature.pm | 152 ++++++ .../storage/netapp/mode/components/voltage.pm | 147 +++++ .../storage/netapp/mode/globalstatus.pm | 146 ++++- centreon-plugins/storage/netapp/mode/shelf.pm | 509 +++++++----------- centreon-plugins/storage/netapp/plugin.pm | 28 +- 9 files changed, 1006 insertions(+), 346 deletions(-) create mode 100644 centreon-plugins/storage/netapp/mode/components/communication.pm create mode 100644 centreon-plugins/storage/netapp/mode/components/electronics.pm create mode 100644 centreon-plugins/storage/netapp/mode/components/fan.pm create mode 100644 centreon-plugins/storage/netapp/mode/components/psu.pm create mode 100644 centreon-plugins/storage/netapp/mode/components/temperature.pm create mode 100644 centreon-plugins/storage/netapp/mode/components/voltage.pm diff --git a/centreon-plugins/storage/netapp/mode/components/communication.pm b/centreon-plugins/storage/netapp/mode/components/communication.pm new file mode 100644 index 000000000..2e37c557c --- /dev/null +++ b/centreon-plugins/storage/netapp/mode/components/communication.pm @@ -0,0 +1,85 @@ +################################################################################ +# Copyright 2005-2014 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package storage::netapp::mode::components::communication; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my %map_com_states = ( + 1 => 'initializing', + 2 => 'transitioning', + 3 => 'active', + 4 => 'inactive', + 5 => 'reconfiguring', + 6 => 'nonexistent', +); +my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3'; +my $oid_enclContactState = '.1.3.6.1.4.1.789.1.21.1.2.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_enclContactState }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking communications"); + $self->{components}->{communication} = {name => 'communications', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'communication')); + + for (my $i = 1; $i <= $self->{number_shelf}; $i++) { + my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; + my $com_state = $map_com_states{$self->{results}->{$oid_enclContactState}->{$oid_enclContactState . '.' . $i}}; + + next if ($self->check_exclude(section => 'communication', instance => $shelf_addr)); + + $self->{components}->{communication}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Shelve '%s' communication state is '%s'", + $shelf_addr, $com_state)); + my $exit = $self->get_severity(section => 'communication', value => $com_state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Shelve '%s' communication state is '%s'", + $shelf_addr, $com_state)); + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/mode/components/electronics.pm b/centreon-plugins/storage/netapp/mode/components/electronics.pm new file mode 100644 index 000000000..62cf702dc --- /dev/null +++ b/centreon-plugins/storage/netapp/mode/components/electronics.pm @@ -0,0 +1,89 @@ +################################################################################ +# Copyright 2005-2014 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package storage::netapp::mode::components::electronics; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3'; +my $oid_enclElectronicsPresent = '.1.3.6.1.4.1.789.1.21.1.2.1.31'; +my $oid_enclElectronicsFailed = '.1.3.6.1.4.1.789.1.21.1.2.1.33'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_enclElectronicsPresent }; + push @{$options{request}}, { oid => $oid_enclElectronicsFailed }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking electronics"); + $self->{components}->{electronics} = {name => 'electronics', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'electronics')); + + for (my $i = 1; $i <= $self->{number_shelf}; $i++) { + my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; + my $present = $self->{results}->{$oid_enclElectronicsPresent}->{$oid_enclElectronicsPresent . '.' . $i}; + my $failed = $self->{results}->{$oid_enclElectronicsFailed}->{$oid_enclElectronicsFailed . '.' . $i}; + + foreach my $num (split /,/, $present) { + $num = centreon::plugins::misc::trim($num); + next if ($num !~ /[0-9]/); + + next if ($self->check_exclude(section => 'electronics', instance => $shelf_addr . '.' . $num)); + $self->{components}->{electronics}->{total}++; + + my $status = 'ok'; + if ($failed =~ /(^|,|\s)$num(,|\s|$)/) { + $status = 'failed'; + } + + $self->{output}->output_add(long_msg => sprintf("Shelve '%s' electronics '%s' is '%s'", + $shelf_addr, $num, $status)); + my $exit = $self->get_severity(section => 'electronics', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Shelve '%s' electronics '%s' is '%s'", $shelf_addr, $num, $status)); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/mode/components/fan.pm b/centreon-plugins/storage/netapp/mode/components/fan.pm new file mode 100644 index 000000000..50567ffd2 --- /dev/null +++ b/centreon-plugins/storage/netapp/mode/components/fan.pm @@ -0,0 +1,107 @@ +################################################################################ +# Copyright 2005-2014 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package storage::netapp::mode::components::fan; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3'; +my $oid_enclFansPresent = '.1.3.6.1.4.1.789.1.21.1.2.1.17'; +my $oid_enclFansFailed = '.1.3.6.1.4.1.789.1.21.1.2.1.18'; +my $oid_enclFansSpeed = '.1.3.6.1.4.1.789.1.21.1.2.1.62'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_enclFansPresent }; + push @{$options{request}}, { oid => $oid_enclFansFailed }; + push @{$options{request}}, { oid => $oid_enclFansSpeed }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fans"); + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'fan')); + + for (my $i = 1; $i <= $self->{number_shelf}; $i++) { + my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; + my $present = $self->{results}->{$oid_enclFansPresent}->{$oid_enclFansPresent . '.' . $i}; + my $failed = $self->{results}->{$oid_enclFansFailed}->{$oid_enclFansFailed . '.' . $i}; + my @current_speed = split /,/, $self->{results}->{$oid_enclFansSpeed}->{$oid_enclFansSpeed . '.' . $i}; + + foreach my $num (split /,/, $present) { + $num = centreon::plugins::misc::trim($num); + next if ($num !~ /[0-9]/); + my $current_value = ($current_speed[$num - 1] =~ /(^|\s)([0-9]+)/) ? $2 : ''; + + next if ($self->check_exclude(section => 'fan', instance => $shelf_addr . '.' . $num)); + $self->{components}->{fan}->{total}++; + + my $status = 'ok'; + if ($failed =~ /(^|,|\s)$num(,|\s|$)/) { + $status = 'failed'; + } + + $self->{output}->output_add(long_msg => sprintf("Shelve '%s' Fan '%s' is '%s'", + $shelf_addr, $num, $status)); + my $exit = $self->get_severity(section => 'fan', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Shelve '%s' Fan '%s' is '%s'", $shelf_addr, $num, $status)); + } + + if ($current_value ne '') { + my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'fan', instance => $shelf_addr . '.' . $num, value => $current_value); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Shelve '%s' Fan '%s' speed is '%s'", $shelf_addr, $num, $current_value)); + } + + $self->{output}->perfdata_add(label => "speed_" . $shelf_addr . "_" . $num, unit => 'rpm', + value => $current_value, + warning => $warn, + critical => $crit, + min => 0); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/mode/components/psu.pm b/centreon-plugins/storage/netapp/mode/components/psu.pm new file mode 100644 index 000000000..085327531 --- /dev/null +++ b/centreon-plugins/storage/netapp/mode/components/psu.pm @@ -0,0 +1,89 @@ +################################################################################ +# Copyright 2005-2014 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package storage::netapp::mode::components::psu; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3'; +my $oid_enclPowerSuppliesPresent = '.1.3.6.1.4.1.789.1.21.1.2.1.13'; +my $oid_enclPowerSuppliesFailed = '.1.3.6.1.4.1.789.1.21.1.2.1.15'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_enclPowerSuppliesPresent }; + push @{$options{request}}, { oid => $oid_enclPowerSuppliesFailed }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'psu')); + + for (my $i = 1; $i <= $self->{number_shelf}; $i++) { + my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; + my $present = $self->{results}->{$oid_enclPowerSuppliesPresent}->{$oid_enclPowerSuppliesPresent . '.' . $i}; + my $failed = $self->{results}->{$oid_enclPowerSuppliesFailed}->{$oid_enclPowerSuppliesFailed . '.' . $i}; + + foreach my $num (split /,/, $present) { + $num = centreon::plugins::misc::trim($num); + next if ($num !~ /[0-9]/); + + next if ($self->check_exclude(section => 'psu', instance => $shelf_addr . '.' . $num)); + $self->{components}->{psu}->{total}++; + + my $status = 'ok'; + if ($failed =~ /(^|,|\s)$num(,|\s|$)/) { + $status = 'failed'; + } + + $self->{output}->output_add(long_msg => sprintf("Shelve '%s' PSU '%s' is '%s'", + $shelf_addr, $num, $status)); + my $exit = $self->get_severity(section => 'psu', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Shelve '%s' PSU '%s' is '%s'", $shelf_addr, $num, $status)); + } + } + } +} + +1; diff --git a/centreon-plugins/storage/netapp/mode/components/temperature.pm b/centreon-plugins/storage/netapp/mode/components/temperature.pm new file mode 100644 index 000000000..604a8a9e1 --- /dev/null +++ b/centreon-plugins/storage/netapp/mode/components/temperature.pm @@ -0,0 +1,152 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package storage::netapp::mode::components::temperature; + +use strict; +use warnings; + +my %map_hum_status = ( + 1 => 'noStatus', + 2 => 'normal', + 3 => 'highWarning', + 4 => 'highCritical', + 5 => 'lowWarning', + 6 => 'lowCritical', + 7 => 'sensorError', +); +my %map_hum_online = ( + 1 => 'online', + 2 => 'offline', +); + +my $mapping = { + enclTempSensorsPresent => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.20' }, + enclTempSensorsOverTempFail => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.21' }, + enclTempSensorsOverTempWarn => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.22' }, + enclTempSensorsUnderTempFail => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.23' }, + enclTempSensorsUnderTempWarn => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.24' }, + enclTempSensorsCurrentTemp => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.25' }, + enclTempSensorsOverTempFailThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.26' }, + enclTempSensorsOverTempWarnThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.27' }, + enclTempSensorsUnderTempFailThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.28' }, + enclTempSensorsUnderTempWarnThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.29' }, +}; +my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3'; +my $oid_enclEntry = '.1.3.6.1.4.1.789.1.21.1.2.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_enclEntry, begin => $mapping->{enclTempSensorsPresent}->{oid}, end => $mapping->{enclTempSensorsUnderTempWarnThr}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'temperature')); + + for (my $i = 1; $i <= $self->{number_shelf}; $i++) { + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_enclEntry}, instance => $i); + my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; + my @current_temp = split /,/, $result->{enclTempSensorsCurrentTemp}; + + my @warn_under_thr = split /,/, $result->{enclTempSensorsUnderTempWarnThr}; + my @crit_under_thr = split /,/, $result->{enclTempSensorsUnderTempFailThr}; + my @warn_over_thr = split /,/, $result->{enclTempSensorsOverTempWarnThr}; + my @crit_over_thr = split /,/, $result->{enclTempSensorsOverTempFailThr}; + + foreach my $num (split /,/, $result->{enclTempSensorsPresent}) { + $num = centreon::plugins::misc::trim($num); + next if ($num !~ /[0-9]/); + + $warn_under_thr[$num - 1] =~ /(-*[0-9]+)C/; + my $wu_thr = $1; + $crit_under_thr[$num - 1] =~ /(-*[0-9]+)C/; + my $cu_thr = $1; + $warn_over_thr[$num - 1] =~ /(-*[0-9]+)C/; + my $wo_thr = $1; + $crit_over_thr[$num - 1] =~ /(-*[0-9]+)C/; + my $co_thr = $1; + $current_temp[$num - 1] =~ /(-*[0-9]+)C/; + my $current_value = $1; + + next if ($self->check_exclude(section => 'temperature', instance => $shelf_addr . '.' . $num)); + $self->{components}->{temperature}->{total}++; + + my $status = 'ok'; + if ($result->{enclTempSensorsUnderTempFailThr} =~ /(^|,|\s)$num(,|\s|$)/) { + $status = 'under critical threshold'; + } elsif ($result->{enclTempSensorsUnderTempWarnThr} =~ /(^|,|\s)$num(,|\s|$)/) { + $status = 'under warning threshold'; + } elsif ($result->{enclTempSensorsOverTempFailThr} =~ /(^|,|\s)$num(,|\s|$)/) { + $status = 'over critical threshold'; + } elsif ($result->{enclTempSensorsOverTempWarnThr} =~ /(^|,|\s)$num(,|\s|$)/) { + $status = 'over warning threshold'; + } + + $self->{output}->output_add(long_msg => sprintf("Shelve '%s' temperature sensor '%s' is %s [current = %s]", + $shelf_addr, $num, $status, $current_value)); + my $exit = $self->get_severity(section => 'temperature', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Shelve '%s' temperature sensor '%s' is %s", + $shelf_addr, $num, $status)); + } + + my $warn = $wu_thr . ':' . $wo_thr; + my $crit = $cu_thr . ':' . $co_thr; + my ($exit2, $warn2, $crit2, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $shelf_addr . '.' . $num, value => $current_value); + if ($checked == 1) { + ($warn, $crit) = ($warn2, $crit2); + } + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Shelve '%s' temperature sensor '%s' is %s degree centigrade", + $shelf_addr, $num, $current_value)); + } + + $self->{output}->perfdata_add(label => "temp_" . $shelf_addr . "_" . $num, unit => 'C', + value => $current_value, + warning => $warn, + critical => $crit); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/netapp/mode/components/voltage.pm b/centreon-plugins/storage/netapp/mode/components/voltage.pm new file mode 100644 index 000000000..367490a1c --- /dev/null +++ b/centreon-plugins/storage/netapp/mode/components/voltage.pm @@ -0,0 +1,147 @@ +################################################################################ +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Quentin Garnier +# +#################################################################################### + +package storage::netapp::mode::components::voltage; + +use strict; +use warnings; + +my %map_hum_status = ( + 1 => 'noStatus', + 2 => 'normal', + 3 => 'highWarning', + 4 => 'highCritical', + 5 => 'lowWarning', + 6 => 'lowCritical', + 7 => 'sensorError', +); +my %map_hum_online = ( + 1 => 'online', + 2 => 'offline', +); + +my $mapping = { + enclVoltSensorsPresent => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.35' }, + enclVoltSensorsOverVoltFail => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.36' }, + enclVoltSensorsOverVoltWarn => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.37' }, + enclVoltSensorsUnderVoltFail => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.38' }, + enclVoltSensorsUnderVoltWarn => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.39' }, + enclVoltSensorsCurrentVolt => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.40' }, + enclVoltSensorsOverVoltFailThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.41' }, + enclVoltSensorsOverVoltWarnThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.42' }, + enclVoltSensorsUnderVoltFailThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.43' }, + enclVoltSensorsUnderVoltWarnThr => { oid => '.1.3.6.1.4.1.789.1.21.1.2.1.44' }, +}; +my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3'; +my $oid_enclTable = '.1.3.6.1.4.1.789.1.21.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_enclTable, begin => $mapping->{enclVoltSensorsPresent}->{oid}, end => $mapping->{enclVoltSensorsUnderVoltWarnThr}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking voltages"); + $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'voltage')); + + for (my $i = 1; $i <= $self->{number_shelf}; $i++) { + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_enclTable}, instance => $i); + my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; + my @current_volt = split /,/, $result->{enclVoltSensorsCurrentVolt}; + + my @warn_under_thr = split /,/, $result->{enclVoltSensorsUnderVoltWarnThr}; + my @crit_under_thr = split /,/, $result->{enclVoltSensorsUnderVoltFailThr}; + my @warn_over_thr = split /,/, $result->{enclVoltSensorsOverVoltWarnThr}; + my @crit_over_thr = split /,/, $result->{enclVoltSensorsOverVoltFailThr}; + + foreach my $num (split /,/, $result->{enclVoltSensorsPresent}) { + $num = centreon::plugins::misc::trim($num); + next if ($num !~ /[0-9]/); + + my $wu_thr = (defined($warn_under_thr[$num - 1]) && $warn_under_thr[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; + my $cu_thr = (defined($crit_under_thr[$num - 1]) && $crit_under_thr[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; + my $wo_thr = (defined($warn_over_thr[$num - 1]) && $warn_over_thr[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; + my $co_thr = (defined($crit_over_thr[$num - 1]) && $crit_over_thr[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; + my $current_value = ($current_volt[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; + + next if ($self->check_exclude(section => 'voltage', instance => $shelf_addr . '.' . $num)); + $self->{components}->{voltage}->{total}++; + + my $status = 'ok'; + if ($result->{enclVoltSensorsUnderVoltFailThr} =~ /(^|,|\s)$num(,|\s|$)/) { + $status = 'under critical threshold'; + } elsif ($result->{enclVoltSensorsUnderVoltWarnThr} =~ /(^|,|\s)$num(,|\s|$)/) { + $status = 'under warning threshold'; + } elsif ($result->{enclVoltSensorsOverVoltFailThr} =~ /(^|,|\s)$num(,|\s|$)/) { + $status = 'over critical threshold'; + } elsif ($result->{enclVoltSensorsOverVoltWarnThr} =~ /(^|,|\s)$num(,|\s|$)/) { + $status = 'over warning threshold'; + } + + $self->{output}->output_add(long_msg => sprintf("Shelve '%s' voltage sensor '%s' is %s [current = %s]", + $shelf_addr, $num, $status, $current_value)); + my $exit = $self->get_severity(section => 'voltage', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Shelve '%s' voltage sensor '%s' is %s", + $shelf_addr, $num, $status)); + } + + my $warn = $wu_thr . ':' . $wo_thr; + my $crit = $cu_thr . ':' . $co_thr; + my ($exit2, $warn2, $crit2, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $shelf_addr . '.' . $num, value => $current_value); + if ($checked == 1) { + ($warn, $crit) = ($warn2, $crit2); + } + + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("Shelve '%s' voltage sensor '%s' is %s mV", + $shelf_addr, $num, $current_value)); + } + + $self->{output}->perfdata_add(label => "volt_" . $shelf_addr . "_" . $num, unit => 'mV', + value => $current_value, + warning => $warn, + critical => $crit); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/netapp/mode/globalstatus.pm b/centreon-plugins/storage/netapp/mode/globalstatus.pm index 48e093ec5..845739c27 100644 --- a/centreon-plugins/storage/netapp/mode/globalstatus.pm +++ b/centreon-plugins/storage/netapp/mode/globalstatus.pm @@ -39,6 +39,39 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use centreon::plugins::statefile; +use centreon::plugins::values; + +my $maps_counters = { + read => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'read', diff => 1 }, + ], + per_second => 1, + output_template => 'Read I/O : %s %s/s', + output_change_bytes => 1, + perfdatas => [ + { value => 'read_per_second', template => '%d', + unit => 'B/s', min => 0 }, + ], + } + }, + write => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'write', diff => 1 }, + ], + per_second => 1, + output_template => 'Write I/O : %s %s/s', + output_change_bytes => 1, + perfdatas => [ + { value => 'write_per_second', template => '%d', + unit => 'B/s', min => 0 }, + ], + } + }, +}; my %states = ( 1 => ['other', 'WARNING'], @@ -49,6 +82,15 @@ my %states = ( 6 => ['nonRecoverable', 'WARNING'], ); +my $oid_miscGlobalStatus = '.1.3.6.1.4.1.789.1.2.2.4.0'; +my $oid_miscGlobalStatusMessage = '.1.3.6.1.4.1.789.1.2.2.25.0'; +my $oid_misc64DiskReadBytes = '.1.3.6.1.4.1.789.1.2.2.32.0'; +my $oid_misc64DiskWriteBytes = '.1.3.6.1.4.1.789.1.2.2.33.0'; +my $oid_miscHighDiskReadBytes = '.1.3.6.1.4.1.789.1.2.2.15.0'; +my $oid_miscLowDiskReadBytes = '.1.3.6.1.4.1.789.1.2.2.16.0'; +my $oid_miscHighDiskWriteBytes = '.1.3.6.1.4.1.789.1.2.2.17.0'; +my $oid_miscLowDiskWriteBytes = '.1.3.6.1.4.1.789.1.2.2.18.0'; + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -59,41 +101,133 @@ sub new { { }); + $self->{statefile_value} = centreon::plugins::statefile->new(%options); + foreach (keys %{$maps_counters}) { + $options{options}->add_options(arguments => { + 'warning-' . $_ . ':s' => { name => 'warning-' . $_ }, + 'critical-' . $_ . ':s' => { name => 'critical-' . $_ }, + }); + my $class = $maps_counters->{$_}->{class}; + $maps_counters->{$_}->{obj} = $class->new(statefile => $self->{statefile_value}, + output => $self->{output}, perfdata => $self->{perfdata}, + label => $_); + $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) = @_; # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; + $self->{hostname} = $self->{snmp}->get_hostname(); + $self->{snmp_port} = $self->{snmp}->get_port(); - my $oid_miscGlobalStatus = '.1.3.6.1.4.1.789.1.2.2.4.0'; - my $oid_miscGlobalStatusMessage = '.1.3.6.1.4.1.789.1.2.2.25.0'; - my $result = $self->{snmp}->get_leef(oids => [$oid_miscGlobalStatus, $oid_miscGlobalStatusMessage], nothing_quit => 1); + $self->manage_selection(); - $self->{output}->output_add(severity => ${$states{$result->{$oid_miscGlobalStatus}}}[1], + $self->{output}->output_add(severity => ${$states{$self->{results}->{$oid_miscGlobalStatus}}}[1], short_msg => sprintf("Overall global status is '%s' [message: '%s']", - ${$states{$result->{$oid_miscGlobalStatus}}}[0], $result->{$oid_miscGlobalStatusMessage})); + ${$states{$self->{results}->{$oid_miscGlobalStatus}}}[0], $self->{results}->{$oid_miscGlobalStatusMessage})); + + $self->{new_datas} = {}; + $self->{statefile_value}->read(statefile => "cache_netapp_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode}); + $self->{new_datas}->{last_timestamp} = time(); + + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits; + foreach (sort keys %{$maps_counters}) { + $maps_counters->{$_}->{obj}->set(instance => 'global'); + + my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{global}, + new_datas => $self->{new_datas}); + 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(); + } + + 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 => "$short_msg" + ); + } else { + $self->{output}->output_add(short_msg => "$long_msg"); + } + + $self->{statefile_value}->write(data => $self->{new_datas}); $self->{output}->display(); $self->{output}->exit(); } +sub manage_selection { + my ($self, %options) = @_; + + my $request = [$oid_miscGlobalStatus, $oid_miscGlobalStatusMessage, + $oid_miscHighDiskReadBytes, $oid_miscLowDiskReadBytes, + $oid_miscHighDiskWriteBytes, $oid_miscLowDiskWriteBytes]; + if (!$self->{snmp}->is_snmpv1()) { + push @{$request}, ($oid_misc64DiskReadBytes, $oid_misc64DiskWriteBytes); + } + + $self->{results} = $self->{snmp}->get_leef(oids => $request, nothing_quit => 1); + + $self->{global} = {}; + $self->{global}->{read} = defined($self->{results}->{$oid_misc64DiskReadBytes}) ? + $self->{results}->{$oid_misc64DiskReadBytes} : + ($self->{results}->{$oid_miscHighDiskReadBytes} << 32) + $self->{results}->{$oid_miscLowDiskReadBytes}; + $self->{global}->{write} = defined($self->{results}->{$oid_misc64DiskWriteBytes}) ? + $self->{results}->{$oid_misc64DiskWriteBytes} : + ($self->{results}->{$oid_miscHighDiskWriteBytes} << 32) + $self->{results}->{$oid_miscLowDiskWriteBytes}; + +} + 1; __END__ =head1 MODE -Check the overall status of the appliance. +Check the overall status of the appliance and some metrics (total read bytes per seconds and total write bytes per seconds). =over 8 +=item B<--warning-*> + +Threshold warning. +Can be: 'read', 'write'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'read', 'write'. + =back =cut diff --git a/centreon-plugins/storage/netapp/mode/shelf.pm b/centreon-plugins/storage/netapp/mode/shelf.pm index b5b6102d5..4230707ee 100644 --- a/centreon-plugins/storage/netapp/mode/shelf.pm +++ b/centreon-plugins/storage/netapp/mode/shelf.pm @@ -41,45 +41,45 @@ use strict; use warnings; use centreon::plugins::misc; -my %com_states = ( - 1 => ['initializing', 'WARNING'], - 2 => ['transitioning', 'WARNING'], - 3 => ['active', 'OK'], - 4 => ['inactive', 'CRITICAL'], - 5 => ['reconfiguring', 'WARNING'], - 6 => ['nonexistent', 'CRITICAL'], -); +my $thresholds = { + communication => [ + ['initializing', 'WARNING'], + ['transitioning', 'WARNING'], + ['inactive', 'CRITICAL'], + ['reconfiguring', 'WARNING'], + ['nonexistent', 'CRITICAL'], + ['active', 'OK'], + ], + fan => [ + ['failed', 'CRITICAL'], + ['ok', 'OK'], + ], + psu => [ + ['failed', 'CRITICAL'], + ['ok', 'OK'], + ], + electronics => [ + ['failed', 'CRITICAL'], + ['ok', 'OK'], + ], + voltage => [ + ['under critical threshold', 'CRITICAL'], + ['under warning threshold', 'WARNING'], + ['over critical threshold', 'CRITICAL'], + ['over warning threshold', 'WARNING'], + ['ok', 'OK'], + ], + temperature => [ + ['under critical threshold', 'CRITICAL'], + ['under warning threshold', 'WARNING'], + ['over critical threshold', 'CRITICAL'], + ['over warning threshold', 'WARNING'], + ['ok', 'OK'], + ], +}; -my $oid_enclNumber = '.1.3.6.1.4.1.789.1.21.1.1.0'; -my $oid_enclContactState = '.1.3.6.1.4.1.789.1.21.1.2.1.2'; +my $oid_enclNumber = '.1.3.6.1.4.1.789.1.21.1.1'; my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3'; -my $oid_enclPowerSuppliesPresent = '.1.3.6.1.4.1.789.1.21.1.2.1.13'; -my $oid_enclPowerSuppliesFailed = '.1.3.6.1.4.1.789.1.21.1.2.1.15'; -my $oid_enclFansPresent = '.1.3.6.1.4.1.789.1.21.1.2.1.17'; -my $oid_enclFansFailed = '.1.3.6.1.4.1.789.1.21.1.2.1.18'; -my $oid_enclFansSpeed = '.1.3.6.1.4.1.789.1.21.1.2.1.62'; -my $oid_enclTempSensorsPresent = '.1.3.6.1.4.1.789.1.21.1.2.1.20'; -my $oid_enclTempSensorsOverTempFail = '.1.3.6.1.4.1.789.1.21.1.2.1.21'; -my $oid_enclTempSensorsOverTempWarn = '.1.3.6.1.4.1.789.1.21.1.2.1.22'; -my $oid_enclTempSensorsUnderTempFail = '.1.3.6.1.4.1.789.1.21.1.2.1.23'; -my $oid_enclTempSensorsUnderTempWarn = '.1.3.6.1.4.1.789.1.21.1.2.1.24'; -my $oid_enclTempSensorsCurrentTemp = '.1.3.6.1.4.1.789.1.21.1.2.1.25'; -my $oid_enclTempSensorsOverTempFailThr = '.1.3.6.1.4.1.789.1.21.1.2.1.26'; -my $oid_enclTempSensorsOverTempWarnThr = '.1.3.6.1.4.1.789.1.21.1.2.1.27'; -my $oid_enclTempSensorsUnderTempFailThr = '.1.3.6.1.4.1.789.1.21.1.2.1.28'; -my $oid_enclTempSensorsUnderTempWarnThr = '.1.3.6.1.4.1.789.1.21.1.2.1.29'; -my $oid_enclElectronicsPresent = '.1.3.6.1.4.1.789.1.21.1.2.1.31'; -my $oid_enclElectronicsFailed = '.1.3.6.1.4.1.789.1.21.1.2.1.33'; -my $oid_enclVoltSensorsPresent = '.1.3.6.1.4.1.789.1.21.1.2.1.35'; -my $oid_enclVoltSensorsOverVoltFail = '.1.3.6.1.4.1.789.1.21.1.2.1.36'; -my $oid_enclVoltSensorsOverVoltWarn = '.1.3.6.1.4.1.789.1.21.1.2.1.37'; -my $oid_enclVoltSensorsUnderVoltFail = '.1.3.6.1.4.1.789.1.21.1.2.1.38'; -my $oid_enclVoltSensorsUnderVoltWarn = '.1.3.6.1.4.1.789.1.21.1.2.1.39'; -my $oid_enclVoltSensorsCurrentVolt = '.1.3.6.1.4.1.789.1.21.1.2.1.40'; -my $oid_enclVoltSensorsOverVoltFailThr = '.1.3.6.1.4.1.789.1.21.1.2.1.41'; -my $oid_enclVoltSensorsOverVoltWarnThr = '.1.3.6.1.4.1.789.1.21.1.2.1.42'; -my $oid_enclVoltSensorsUnderVoltFailThr = '.1.3.6.1.4.1.789.1.21.1.2.1.43'; -my $oid_enclVoltSensorsUnderVoltWarnThr = '.1.3.6.1.4.1.789.1.21.1.2.1.44'; sub new { my ($class, %options) = @_; @@ -90,9 +90,14 @@ sub new { $options{options}->add_options(arguments => { "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, + "component:s" => { name => 'component', default => '.*' }, + "absent-problem:s" => { name => 'absent' }, "no-component:s" => { name => 'no_component' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, + "warning:s@" => { name => 'warning' }, + "critical:s@" => { name => 'critical' }, }); + $self->{components} = {}; $self->{no_components} = undef; return $self; @@ -109,6 +114,46 @@ sub check_options { $self->{no_components} = 'critical'; } } + + $self->{overload_th} = {}; + foreach my $val (@{$self->{option_results}->{threshold_overload}}) { + if ($val !~ /^(.*?),(.*?),(.*)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $status, $filter) = ($1, $2, $3); + if ($self->{output}->is_litteral_status(status => $status) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); + $self->{output}->option_exit(); + } + $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); + push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; + } + + $self->{numeric_threshold} = {}; + foreach my $option (('warning', 'critical')) { + foreach my $val (@{$self->{option_results}->{$option}}) { + if ($val !~ /^(.*?),(.*?),(.*)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $regexp, $value) = ($1, $2, $3); + if ($section !~ /(voltage|temperature|fan)/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: fan, voltage or temperature)."); + $self->{output}->option_exit(); + } + my $position = 0; + if (defined($self->{numeric_threshold}->{$section})) { + $position = scalar(@{$self->{numeric_threshold}->{$section}}); + } + if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'."); + $self->{output}->option_exit(); + } + $self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section})); + push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, regexp => $regexp }; + } + } } sub run { @@ -116,44 +161,36 @@ sub run { # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - my $result = $self->{snmp}->get_leef(oids => [$oid_enclNumber], nothing_quit => 1); - $self->{snmp}->load(oids => [$oid_enclContactState, $oid_enclChannelShelfAddr, $oid_enclPowerSuppliesPresent, $oid_enclPowerSuppliesFailed, - $oid_enclFansPresent, $oid_enclFansFailed, $oid_enclFansSpeed, $oid_enclTempSensorsPresent, $oid_enclTempSensorsOverTempFail, $oid_enclTempSensorsOverTempWarn, - $oid_enclTempSensorsUnderTempFail, $oid_enclTempSensorsUnderTempWarn, $oid_enclTempSensorsCurrentTemp, - $oid_enclTempSensorsOverTempFailThr, $oid_enclTempSensorsOverTempWarnThr, $oid_enclTempSensorsUnderTempFailThr, - $oid_enclTempSensorsUnderTempWarnThr, $oid_enclElectronicsPresent, $oid_enclElectronicsFailed, $oid_enclVoltSensorsPresent, - $oid_enclVoltSensorsOverVoltFail, $oid_enclVoltSensorsOverVoltWarn, $oid_enclVoltSensorsUnderVoltFail, $oid_enclVoltSensorsUnderVoltWarn, - $oid_enclVoltSensorsCurrentVolt, $oid_enclVoltSensorsOverVoltFailThr, $oid_enclVoltSensorsOverVoltWarnThr, $oid_enclVoltSensorsUnderVoltFailThr, - $oid_enclVoltSensorsUnderVoltWarnThr], - begin => 1, end => $result->{$oid_enclNumber}); - $self->{result} = $self->{snmp}->get_leef(); + my $snmp_request = []; + my @components = ('communication', 'psu', 'fan', 'temperature', 'voltage', 'electronics'); + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "storage::netapp::mode::components::$_"; + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, + error_msg => "Cannot load module '$mod_name'."); + my $func = $mod_name->can('load'); + $func->(request => $snmp_request); + } + } - $self->{number_shelf} = $result->{$oid_enclNumber}; - - if ($self->{option_results}->{component} eq 'all') { - $self->check_communication(); - $self->check_fan(); - $self->check_psu(); - $self->check_temperature(); - $self->check_electronics(); - $self->check_voltage(); - } elsif ($self->{option_results}->{component} eq 'communication') { - $self->check_communication(); - } elsif ($self->{option_results}->{component} eq 'psu') { - $self->check_psu(); - } elsif ($self->{option_results}->{component} eq 'fan') { - $self->check_fan(); - } elsif ($self->{option_results}->{component} eq 'temperature') { - $self->check_temperature(); - } elsif ($self->{option_results}->{component} eq 'voltage') { - $self->check_voltage(); - } elsif ($self->{option_results}->{component} eq 'electronics') { - $self->check_electronics(); - } else { + if (scalar(@{$snmp_request}) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); $self->{output}->option_exit(); - } + } + push @{$snmp_request}, ({ oid => $oid_enclNumber }, { oid => $oid_enclChannelShelfAddr }); + $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); + $self->{number_shelf} = defined($self->{results}->{$oid_enclNumber}->{$oid_enclNumber . '.0'}) ? $self->{results}->{$oid_enclNumber}->{$oid_enclNumber . '.0'} : -1; + $self->{shelf_addr} = $self->{results}->{$oid_enclChannelShelfAddr}; + + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "storage::netapp::mode::components::$_"; + my $func = $mod_name->can('check'); + $func->($self); + } + } + my $total_components = 0; my $display_by_component = ''; my $display_by_component_append = ''; @@ -167,10 +204,9 @@ sub run { } $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s] [%s shelves].", + short_msg => sprintf("All %s components are ok [%s].", $total_components, - $display_by_component, - $self->{number_shelf}) + $display_by_component) ); if (defined($self->{option_results}->{no_component}) && $total_components == 0) { @@ -198,262 +234,62 @@ sub check_exclude { return 0; } -sub check_communication { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking communications"); - $self->{components}->{communication} = {name => 'communications', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'communication')); - - for (my $i = 1; $i <= $self->{number_shelf}; $i++) { - my $shelf_addr = $self->{result}->{$oid_enclChannelShelfAddr . '.' . $i}; - my $com_state = $self->{result}->{$oid_enclContactState . '.' . $i}; - - next if ($self->check_exclude(section => 'communication', instance => $shelf_addr)); - $self->{components}->{communication}->{total}++; - - $self->{output}->output_add(long_msg => sprintf("Shelve '%s' communication state is '%s'", - $shelf_addr, ${$com_states{$com_state}}[0])); - if (${$com_states{$com_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$com_states{$com_state}}[0], - short_msg => sprintf("Shelve '%s' communication state is '%s'", - $shelf_addr, ${$com_states{$com_state}}[0])); - } - } -} - -sub check_fan { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking fans"); - $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fan')); - - for (my $i = 1; $i <= $self->{number_shelf}; $i++) { - my $shelf_addr = $self->{result}->{$oid_enclChannelShelfAddr . '.' . $i}; - my $present = $self->{result}->{$oid_enclFansPresent . '.' . $i}; - my $failed = $self->{result}->{$oid_enclFansFailed . '.' . $i}; - my @current_speed = split /,/, $self->{result}->{$oid_enclFansSpeed . '.' . $i}; - - foreach my $num (split /,/, $present) { - $num = centreon::plugins::misc::trim($num); - next if ($num !~ /[0-9]/); - my $current_value = ($current_speed[$num - 1] =~ /(^|\s)([0-9]+)/) ? $2 : ''; - - next if ($self->check_exclude(section => 'fan', instance => $shelf_addr . '.' . $num)); - $self->{components}->{fan}->{total}++; - - if ($failed =~ /(^|,|\s)$num(,|\s|$)/) { - $self->{output}->output_add(severity => 'CRITICAL', - long_msg => sprintf("Shelve '%s' Fan '%s' is failed", - $shelf_addr, $num)); - } else { - $self->{output}->output_add(long_msg => sprintf("Shelve '%s' Fan '%s' is ok", - $shelf_addr, $num)); - } - - if ($current_value ne '') { - $self->{output}->perfdata_add(label => "speed_" . $i . "_" . $num, unit => 'rpm', - value => $current_value, - min => 0); - } - } - } -} - -sub check_psu { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking power supplies"); - $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); - - for (my $i = 1; $i <= $self->{number_shelf}; $i++) { - my $shelf_addr = $self->{result}->{$oid_enclChannelShelfAddr . '.' . $i}; - my $present = $self->{result}->{$oid_enclPowerSuppliesPresent . '.' . $i}; - my $failed = $self->{result}->{$oid_enclPowerSuppliesFailed . '.' . $i}; - - foreach my $num (split /,/, $present) { - $num = centreon::plugins::misc::trim($num); - next if ($num !~ /[0-9]/); - - next if ($self->check_exclude(section => 'psu', instance => $shelf_addr . '.' . $num)); - $self->{components}->{psu}->{total}++; - - if ($failed =~ /(^|,|\s)$num(,|\s|$)/) { - $self->{output}->output_add(severity => 'CRITICAL', - long_msg => sprintf("Shelve '%s' PSU '%s' is failed", - $shelf_addr, $num)); - } else { - $self->{output}->output_add(long_msg => sprintf("Shelve '%s' PSU '%s' is ok", - $shelf_addr, $num)); - } - } - } -} - -sub check_electronics { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking electronics"); - $self->{components}->{electronics} = {name => 'electronics', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'electronics')); - - for (my $i = 1; $i <= $self->{number_shelf}; $i++) { - my $shelf_addr = $self->{result}->{$oid_enclChannelShelfAddr . '.' . $i}; - my $present = $self->{result}->{$oid_enclElectronicsPresent . '.' . $i}; - my $failed = $self->{result}->{$oid_enclElectronicsFailed . '.' . $i}; - - foreach my $num (split /,/, $present) { - $num = centreon::plugins::misc::trim($num); - next if ($num !~ /[0-9]/); - - next if ($self->check_exclude(section => 'electronics', instance => $shelf_addr . '.' . $num)); - $self->{components}->{electronics}->{total}++; - - if ($failed =~ /(^|,|\s)$num(,|\s|$)/) { - $self->{output}->output_add(severity => 'CRITICAL', - long_msg => sprintf("Shelve '%s' electronics '%s' is failed", - $shelf_addr, $num)); - } else { - $self->{output}->output_add(long_msg => sprintf("Shelve '%s' electronics '%s' is ok", - $shelf_addr, $num)); - } - } - } -} - -sub check_voltage { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking voltages"); - $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'voltage')); +sub absent_problem { + my ($self, %options) = @_; - for (my $i = 1; $i <= $self->{number_shelf}; $i++) { - my $shelf_addr = $self->{result}->{$oid_enclChannelShelfAddr . '.' . $i}; - my $present = $self->{result}->{$oid_enclVoltSensorsPresent . '.' . $i}; - my @current_volt = split /,/, $self->{result}->{$oid_enclVoltSensorsCurrentVolt . '.' . $i}; - - my $warn_under = $self->{result}->{$oid_enclVoltSensorsUnderVoltWarn . '.' . $i}; - my $crit_under = $self->{result}->{$oid_enclVoltSensorsUnderVoltFail . '.' . $i}; - my $warn_over = $self->{result}->{$oid_enclVoltSensorsOverVoltWarn . '.' . $i}; - my $crit_over = $self->{result}->{$oid_enclVoltSensorsOverVoltFail . '.' . $i}; - - my @warn_under_thr = split /,/, $self->{result}->{$oid_enclVoltSensorsUnderVoltWarnThr . '.' . $i}; - my @crit_under_thr = split /,/, $self->{result}->{$oid_enclVoltSensorsUnderVoltFailThr . '.' . $i}; - my @warn_over_thr = split /,/, $self->{result}->{$oid_enclVoltSensorsOverVoltWarnThr . '.' . $i}; - my @crit_over_thr = split /,/, $self->{result}->{$oid_enclVoltSensorsOverVoltFailThr . '.' . $i}; - - foreach my $num (split /,/, $present) { - $num = centreon::plugins::misc::trim($num); - next if ($num !~ /[0-9]/); - - my $wu_thr = (defined($warn_under_thr[$num - 1]) && $warn_under_thr[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; - my $cu_thr = (defined($crit_under_thr[$num - 1]) && $crit_under_thr[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; - my $wo_thr = (defined($warn_over_thr[$num - 1]) && $warn_over_thr[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; - my $co_thr = (defined($crit_over_thr[$num - 1]) && $crit_over_thr[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; - my $current_value = ($current_volt[$num - 1] =~ /(^|\s)(-*[0-9]+)/) ? $2 : ''; - - next if ($self->check_exclude(section => 'voltage', instance => $shelf_addr . '.' . $num)); - $self->{components}->{voltage}->{total}++; - - if ($crit_under =~ /(^|,|\s)$num(,|\s|$)/) { - $self->{output}->output_add(severity => 'CRITICAL', - long_msg => sprintf("Shelve '%s' voltage sensor '%s' is under critical threshold [current = %s < %s]", - $shelf_addr, $num, $current_value, $cu_thr)); - } elsif ($warn_under =~ /(^|,|\s)$num(,|\s|$)/) { - $self->{output}->output_add(severity => 'WARNING', - long_msg => sprintf("Shelve '%s' voltage sensor '%s' is under warning threshold [current = %s < %s]", - $shelf_addr, $num, $current_value, $wu_thr)); - } elsif ($crit_over =~ /(^|,|\s)$num(,|\s|$)/) { - $self->{output}->output_add(severity => 'CRITICAL', - long_msg => sprintf("Shelve '%s' voltage sensor '%s' is over critical threshold [current = %s > %s]", - $shelf_addr, $num, $current_value, $co_thr)); - } elsif ($warn_over =~ /(^|,|\s)$num(,|\s|$)/) { - $self->{output}->output_add(severity => 'WARNING', - long_msg => sprintf("Shelve '%s' voltage sensor '%s' is over warning threshold [current = %s > %s]", - $shelf_addr, $num, $current_value, $wo_thr)); - } else { - $self->{output}->output_add(long_msg => sprintf("Shelve '%s' voltage sensor '%s' is ok [current = %s]", - $shelf_addr, $num, $current_value)); - } - - $self->{output}->perfdata_add(label => "volt_" . $i . "_" . $num, unit => 'mV', - value => $current_value, - warning => ($wu_thr ne '' || $wo_thr ne '') ? ($wu_thr . ':' . $wo_thr) : '', - critical => ($cu_thr ne '' || $co_thr ne '') ? ($cu_thr . ':' . $co_thr) : ''); - } + if (defined($self->{option_results}->{absent}) && + $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Component '%s' instance '%s' is not present", + $options{section}, $options{instance})); } + + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance (not present)")); + $self->{components}->{$options{section}}->{skip}++; + return 1; } -sub check_temperature { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking temperatures"); - $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'temperature')); - - for (my $i = 1; $i <= $self->{number_shelf}; $i++) { - my $shelf_addr = $self->{result}->{$oid_enclChannelShelfAddr . '.' . $i}; - my $present = $self->{result}->{$oid_enclTempSensorsPresent . '.' . $i}; - my @current_temp = split /,/, $self->{result}->{$oid_enclTempSensorsCurrentTemp . '.' . $i}; - - my $warn_under = $self->{result}->{$oid_enclTempSensorsUnderTempWarn . '.' . $i}; - my $crit_under = $self->{result}->{$oid_enclTempSensorsUnderTempFail . '.' . $i}; - my $warn_over = $self->{result}->{$oid_enclTempSensorsOverTempWarn . '.' . $i}; - my $crit_over = $self->{result}->{$oid_enclTempSensorsOverTempFail . '.' . $i}; - - my @warn_under_thr = split /,/, $self->{result}->{$oid_enclTempSensorsUnderTempWarnThr . '.' . $i}; - my @crit_under_thr = split /,/, $self->{result}->{$oid_enclTempSensorsUnderTempFailThr . '.' . $i}; - my @warn_over_thr = split /,/, $self->{result}->{$oid_enclTempSensorsOverTempWarnThr . '.' . $i}; - my @crit_over_thr = split /,/, $self->{result}->{$oid_enclTempSensorsOverTempFailThr . '.' . $i}; - - foreach my $num (split /,/, $present) { - $num = centreon::plugins::misc::trim($num); - next if ($num !~ /[0-9]/); - - $warn_under_thr[$num - 1] =~ /(-*[0-9]+)C/; - my $wu_thr = $1; - $crit_under_thr[$num - 1] =~ /(-*[0-9]+)C/; - my $cu_thr = $1; - $warn_over_thr[$num - 1] =~ /(-*[0-9]+)C/; - my $wo_thr = $1; - $crit_over_thr[$num - 1] =~ /(-*[0-9]+)C/; - my $co_thr = $1; - $current_temp[$num - 1] =~ /(-*[0-9]+)C/; - my $current_value = $1; - - next if ($self->check_exclude(section => 'temperature', instance => $shelf_addr . '.' . $num)); - $self->{components}->{temperature}->{total}++; - - if ($crit_under =~ /(^|,|\s)$num(,|\s|$)/) { - $self->{output}->output_add(severity => 'CRITICAL', - long_msg => sprintf("Shelve '%s' temperature sensor '%s' is under critical threshold [current = %s < %s]", - $shelf_addr, $num, $current_value, $cu_thr)); - } elsif ($warn_under =~ /(^|,|\s)$num(,|\s|$)/) { - $self->{output}->output_add(severity => 'WARNING', - long_msg => sprintf("Shelve '%s' temperature sensor '%s' is under warning threshold [current = %s < %s]", - $shelf_addr, $num, $current_value, $wu_thr)); - } elsif ($crit_over =~ /(^|,|\s)$num(,|\s|$)/) { - $self->{output}->output_add(severity => 'CRITICAL', - long_msg => sprintf("Shelve '%s' temperature sensor '%s' is over critical threshold [current = %s > %s]", - $shelf_addr, $num, $current_value, $co_thr)); - } elsif ($warn_over =~ /(^|,|\s)$num(,|\s|$)/) { - $self->{output}->output_add(severity => 'WARNING', - long_msg => sprintf("Shelve '%s' temperature sensor '%s' is over warning threshold [current = %s > %s]", - $shelf_addr, $num, $current_value, $wo_thr)); - } else { - $self->{output}->output_add(long_msg => sprintf("Shelve '%s' temperature sensor '%s' is ok [current = %s]", - $shelf_addr, $num, $current_value)); +sub get_severity_numeric { + my ($self, %options) = @_; + my $status = 'OK'; # default + my $thresholds = { warning => undef, critical => undef }; + my $checked = 0; + + if (defined($self->{numeric_threshold}->{$options{section}})) { + my $exits = []; + foreach (@{$self->{numeric_threshold}->{$options{section}}}) { + if ($options{instance} =~ /$_->{regexp}/) { + push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]); + $thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label}); + $checked = 1; + } + } + $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); + } + + return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked); +} + +sub get_severity { + my ($self, %options) = @_; + my $status = 'UNKNOWN'; # default + + if (defined($self->{overload_th}->{$options{section}})) { + foreach (@{$self->{overload_th}->{$options{section}}}) { + if ($options{value} =~ /$_->{filter}/i) { + $status = $_->{status}; + return $status; } - - $self->{output}->perfdata_add(label => "temp_" . $i . "_" . $num, unit => 'C', - value => $current_value, - warning => $wu_thr . ':' . $wo_thr, - critical => $cu_thr . ':' . $co_thr); } } + foreach (@{$thresholds->{$options{section}}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + + return $status; } 1; @@ -468,19 +304,40 @@ Check Shelves hardware (temperatures, voltages, electronics, fan, power supplies =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'psu', 'fan', 'communication', 'voltage', 'temperature', 'electronics'. =item B<--exclude> Exclude some parts (comma seperated list) (Example: --exclude=psu) -Can also exclude specific instance: --exclude='psu#0b.00.99.1#' +Can also exclude specific instance: --exclude='psu#41239F00647-A#' + +=item B<--absent-problem> + +Return an error if an entity is not 'present' (default is skipping) (comma seperated list) +Can be specific or global: --absent-problem=fan#41239F00647-fan02# =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='gfc,CRITICAL,^(?!(Online)$)' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: regexp,treshold) +Example: --warning='41239F00647-vimm46,20' --warning='41239F00647-vimm5.*,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: regexp,treshold) +Example: --critical='41239F00647-vimm46,25' --warning='41239F00647-vimm5.*,35' + =back =cut diff --git a/centreon-plugins/storage/netapp/plugin.pm b/centreon-plugins/storage/netapp/plugin.pm index eb4b5b2da..79efb5d65 100644 --- a/centreon-plugins/storage/netapp/plugin.pm +++ b/centreon-plugins/storage/netapp/plugin.pm @@ -47,20 +47,20 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpuload' => 'storage::netapp::mode::cpuload', - 'diskfailed' => 'storage::netapp::mode::diskfailed', - 'fan' => 'storage::netapp::mode::fan', - 'filesys' => 'storage::netapp::mode::filesys', - 'globalstatus' => 'storage::netapp::mode::globalstatus', - 'list-filesys' => 'storage::netapp::mode::listfilesys', - 'ndmpsessions' => 'storage::netapp::mode::ndmpsessions', - 'nvram' => 'storage::netapp::mode::nvram', - 'partnerstatus' => 'storage::netapp::mode::partnerstatus', - 'psu' => 'storage::netapp::mode::psu', - 'shelf' => 'storage::netapp::mode::shelf', - 'snapmirrorlag' => 'storage::netapp::mode::snapmirrorlag', - 'temperature' => 'storage::netapp::mode::temperature', - 'volumeoptions' => 'storage::netapp::mode::volumeoptions', + 'cpuload' => 'storage::netapp::mode::cpuload', + 'diskfailed' => 'storage::netapp::mode::diskfailed', + 'fan' => 'storage::netapp::mode::fan', + 'filesys' => 'storage::netapp::mode::filesys', + 'global-status' => 'storage::netapp::mode::globalstatus', + 'list-filesys' => 'storage::netapp::mode::listfilesys', + 'ndmpsessions' => 'storage::netapp::mode::ndmpsessions', + 'nvram' => 'storage::netapp::mode::nvram', + 'partnerstatus' => 'storage::netapp::mode::partnerstatus', + 'psu' => 'storage::netapp::mode::psu', + 'shelf' => 'storage::netapp::mode::shelf', + 'snapmirrorlag' => 'storage::netapp::mode::snapmirrorlag', + 'temperature' => 'storage::netapp::mode::temperature', + 'volumeoptions' => 'storage::netapp::mode::volumeoptions', ); return $self;