From 576b6c9e712fb9ea217314cf144239dd933a4e9e Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Mon, 8 Dec 2014 09:32:10 +0100 Subject: [PATCH 01/14] fix temperature component --- centreon/common/fastpath/mode/environment.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/centreon/common/fastpath/mode/environment.pm b/centreon/common/fastpath/mode/environment.pm index fc24f2483..40b14b9d3 100644 --- a/centreon/common/fastpath/mode/environment.pm +++ b/centreon/common/fastpath/mode/environment.pm @@ -159,6 +159,8 @@ sub run { $self->check_fan(); } elsif ($self->{option_results}->{component} eq 'psu') { $self->check_psu(); + } elsif ($self->{option_results}->{component} eq 'temperature') { + $self->check_temperature(); } else { $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); $self->{output}->option_exit(); From b6494986c40bf099c292095365561e76e2fce0b4 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Mon, 8 Dec 2014 19:14:08 +0100 Subject: [PATCH 02/14] Fix #6023 --- .../common/violin/snmp/mode/components/ca.pm | 71 ++++ .../common/violin/snmp/mode/components/fan.pm | 73 ++++ .../common/violin/snmp/mode/components/gfc.pm | 78 ++++ .../common/violin/snmp/mode/components/lfc.pm | 78 ++++ .../common/violin/snmp/mode/components/psu.pm | 87 ++++ .../snmp/mode/components/temperature.pm | 93 +++++ .../violin/snmp/mode/components/vimm.pm | 85 ++++ centreon/common/violin/snmp/mode/hardware.pm | 390 ++++++++++++++++++ storage/violin/3000/snmp/plugin.pm | 64 +++ 9 files changed, 1019 insertions(+) create mode 100644 centreon/common/violin/snmp/mode/components/ca.pm create mode 100644 centreon/common/violin/snmp/mode/components/fan.pm create mode 100644 centreon/common/violin/snmp/mode/components/gfc.pm create mode 100644 centreon/common/violin/snmp/mode/components/lfc.pm create mode 100644 centreon/common/violin/snmp/mode/components/psu.pm create mode 100644 centreon/common/violin/snmp/mode/components/temperature.pm create mode 100644 centreon/common/violin/snmp/mode/components/vimm.pm create mode 100644 centreon/common/violin/snmp/mode/hardware.pm create mode 100644 storage/violin/3000/snmp/plugin.pm diff --git a/centreon/common/violin/snmp/mode/components/ca.pm b/centreon/common/violin/snmp/mode/components/ca.pm new file mode 100644 index 000000000..9427e3a9a --- /dev/null +++ b/centreon/common/violin/snmp/mode/components/ca.pm @@ -0,0 +1,71 @@ +################################################################################ +# 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 centreon::common::violin::snmp::mode::components::ca; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_chassisSystemLedAlarm = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.7'; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking chassis alarm"); + $self->{components}->{ca} = {name => 'chassis alarm', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'ca')); + + foreach my $oid (keys %{$self->{results}->{$oid_chassisSystemLedAlarm}}) { + $oid =~ /^$oid_chassisSystemLedAlarm\.(.*)$/; + my ($dummy, $array_name) = $self->convert_index(value => $1); + my $instance = $array_name; + my $ca_state = $self->{results}->{$oid_chassisSystemLedAlarm}->{$oid}; + + next if ($self->check_exclude(section => 'ca', instance => $instance)); + + $self->{components}->{ca}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Chassis alarm '%s' is %s.", + $instance, $ca_state)); + my $exit = $self->get_severity(section => 'ca', value => $ca_state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Chassis alarm '%s' is %s", $instance, $ca_state)); + } + } +} + +1; diff --git a/centreon/common/violin/snmp/mode/components/fan.pm b/centreon/common/violin/snmp/mode/components/fan.pm new file mode 100644 index 000000000..eab65d2bd --- /dev/null +++ b/centreon/common/violin/snmp/mode/components/fan.pm @@ -0,0 +1,73 @@ +################################################################################ +# 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 centreon::common::violin::snmp::mode::components::fan; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_arrayFanEntry_speed = '.1.3.6.1.4.1.35897.1.2.2.3.18.1.3'; + +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')); + + foreach my $oid (keys %{$self->{results}->{$oid_arrayFanEntry_speed}}) { + $oid =~ /^$oid_arrayFanEntry_speed\.(.*)$/; + my ($dummy, $array_name, $fan_name) = $self->convert_index(value => $1); + my $instance = $array_name . '-' . $fan_name; + my $fan_state = $self->{results}->{$oid_arrayFanEntry_speed}->{$oid}; + + next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($fan_state =~ /Absent/i && + $self->absent_problem(section => 'fan', instance => $instance)); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Fan '%s' state is %s.", + $instance, $fan_state)); + my $exit = $self->get_severity(section => 'fan', value => $fan_state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' state is %s", $instance, $fan_state)); + } + } +} + +1; diff --git a/centreon/common/violin/snmp/mode/components/gfc.pm b/centreon/common/violin/snmp/mode/components/gfc.pm new file mode 100644 index 000000000..85977fc1f --- /dev/null +++ b/centreon/common/violin/snmp/mode/components/gfc.pm @@ -0,0 +1,78 @@ +################################################################################ +# 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 centreon::common::violin::snmp::mode::components::gfc; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_globalTargetFcEntry = '.1.3.6.1.4.1.35897.1.2.1.10.1'; +my $oid_wwn = '.1.3.6.1.4.1.35897.1.2.1.10.1.3'; +my $oid_enable = '.1.3.6.1.4.1.35897.1.2.1.10.1.4'; +my $oid_portState = '.1.3.6.1.4.1.35897.1.2.1.10.1.8'; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking global fc"); + $self->{components}->{gfc} = {name => 'global fc', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'gfc')); + + foreach my $oid (keys %{$self->{results}->{$oid_globalTargetFcEntry}}) { + next if ($oid !~ /^$oid_wwn\.(.*)$/); + my $wwn = $self->{results}->{$oid_globalTargetFcEntry}->{$oid}; + my $enable = $self->{results}->{$oid_globalTargetFcEntry}->{$oid_enable . '.' .$1}; + my $state = $self->{results}->{$oid_globalTargetFcEntry}->{$oid_portState . '.' .$1}; + + if ($enable == 2) { + $self->{output}->output_add(long_msg => sprintf("Skipping instance '$wwn' (not enable)")); + next; + } + next if ($self->check_exclude(section => 'gfc', instance => $wwn)); + + $self->{components}->{gfc}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Global FC '%s' is %s.", + $wwn, $state)); + my $exit = $self->get_severity(section => 'gfc', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Global FC '%s' is %s", $wwn, $state)); + } + } +} + +1; diff --git a/centreon/common/violin/snmp/mode/components/lfc.pm b/centreon/common/violin/snmp/mode/components/lfc.pm new file mode 100644 index 000000000..bb0ea17d8 --- /dev/null +++ b/centreon/common/violin/snmp/mode/components/lfc.pm @@ -0,0 +1,78 @@ +################################################################################ +# 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 centreon::common::violin::snmp::mode::components::lfc; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_localTargetFcEntry = '.1.3.6.1.4.1.35897.1.2.1.6.1'; +my $oid_wwn = '.1.3.6.1.4.1.35897.1.2.1.6.1.2'; +my $oid_enable = '.1.3.6.1.4.1.35897.1.2.1.6.1.3'; +my $oid_portState = '.1.3.6.1.4.1.35897.1.2.1.6.1.7'; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking local fc"); + $self->{components}->{lfc} = {name => 'local fc', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'lfc')); + + foreach my $oid (keys %{$self->{results}->{$oid_localTargetFcEntry}}) { + next if ($oid !~ /^$oid_wwn\.(.*)$/); + my $wwn = $self->{results}->{$oid_localTargetFcEntry}->{$oid}; + my $enable = $self->{results}->{$oid_localTargetFcEntry}->{$oid_enable . '.' .$1}; + my $state = $self->{results}->{$oid_localTargetFcEntry}->{$oid_portState . '.' .$1}; + + if ($enable == 2) { + $self->{output}->output_add(long_msg => sprintf("Skipping instance '$wwn' (not enable)")); + next; + } + next if ($self->check_exclude(section => 'lfc', instance => $wwn)); + + $self->{components}->{lfc}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Local FC '%s' is %s.", + $wwn, $state)); + my $exit = $self->get_severity(section => 'lfc', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Local FC '%s' is %s", $wwn, $state)); + } + } +} + +1; diff --git a/centreon/common/violin/snmp/mode/components/psu.pm b/centreon/common/violin/snmp/mode/components/psu.pm new file mode 100644 index 000000000..4fb591c03 --- /dev/null +++ b/centreon/common/violin/snmp/mode/components/psu.pm @@ -0,0 +1,87 @@ +################################################################################ +# 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 centreon::common::violin::snmp::mode::components::psu; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_chassisSystemPowerPSUA = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.17'; +my $oid_chassisSystemPowerPSUB = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.18'; + +sub psu { + my ($self, %options) = @_; + my $oid = $options{oid}; + + $options{oid} =~ /^$options{oid_short}\.(.*)$/; + my ($dummy, $array_name) = $self->convert_index(value => $1); + my $instance = $array_name . '-' . $options{extra_instance}; + + my $psu_state = $options{value}; + + return if ($self->check_exclude(section => 'psu', instance => $instance)); + return if ($psu_state =~ /Absent/i && + $self->absent_problem(section => 'psu', instance => $instance)); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is %s.", + $instance, $psu_state)); + my $exit = $self->get_severity(section => 'psu', value => $psu_state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power Supply '%s' status is %s", $instance, $psu_state)); + } +} + +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')); + + foreach my $oid (keys %{$self->{results}->{$oid_chassisSystemPowerPSUA}}) { + psu($self, oid => $oid, oid_short => $oid_chassisSystemPowerPSUA, value => $self->{results}->{$oid_chassisSystemPowerPSUA}->{$oid}, + extra_instance => 'A'); + } + foreach my $oid (keys %{$self->{results}->{$oid_chassisSystemPowerPSUB}}) { + psu($self, oid => $oid, oid_short => $oid_chassisSystemPowerPSUB, value => $self->{results}->{$oid_chassisSystemPowerPSUB}->{$oid}, + extra_instance => 'B'); + } +} + +1; diff --git a/centreon/common/violin/snmp/mode/components/temperature.pm b/centreon/common/violin/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..00ec7232b --- /dev/null +++ b/centreon/common/violin/snmp/mode/components/temperature.pm @@ -0,0 +1,93 @@ +################################################################################ +# 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 centreon::common::violin::snmp::mode::components::temperature; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_chassisSystemTempAmbient = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21'; +my $oid_chassisSystemTempController = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21'; +my $oid_arrayVimmEntry_temp = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.12'; + +sub temperature { + my ($self, %options) = @_; + my $oid = $options{oid}; + + $options{oid} =~ /^$options{oid_short}\.(.*)$/; + my ($dummy, $array_name, $extra_name) = $self->convert_index(value => $1); + my $instance = $array_name . '-' . (defined($extra_name) ? $extra_name : $options{extra_instance}); + + my $temperature = $options{value}; + + return if ($self->check_exclude(section => 'temperature', instance => $instance)); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is %s degree centigrade.", + $instance, $temperature)); + my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $temperature); + $self->{output}->perfdata_add(label => 'temp_' . $instance, unit => 'C', + value => $temperature, + warning => $warn, + critical => $crit); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power Supply '%s' is %s", $instance, $temperature)); + } +} + +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')); + + foreach my $oid (keys %{$self->{results}->{$oid_chassisSystemTempAmbient}}) { + temperature($self, oid => $oid, oid_short => $oid_chassisSystemTempAmbient, value => $self->{results}->{$oid_chassisSystemTempAmbient}->{$oid}, + extra_instance => 'ambient'); + } + foreach my $oid (keys %{$self->{results}->{$oid_chassisSystemTempController}}) { + temperature($self, oid => $oid, oid_short => $oid_chassisSystemTempController, value => $self->{results}->{$oid_chassisSystemTempController}->{$oid}, + extra_instance => 'controller'); + } + foreach my $oid (keys %{$self->{results}->{$oid_arrayVimmEntry_temp}}) { + temperature($self, oid => $oid, oid_short => $oid_arrayVimmEntry_temp, value => $self->{results}->{$oid_arrayVimmEntry_temp}->{$oid}); + } +} + +1; diff --git a/centreon/common/violin/snmp/mode/components/vimm.pm b/centreon/common/violin/snmp/mode/components/vimm.pm new file mode 100644 index 000000000..d5d4339f3 --- /dev/null +++ b/centreon/common/violin/snmp/mode/components/vimm.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 centreon::common::violin::snmp::mode::components::vimm; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my $oid_arrayVimmEntry_present = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.4'; +my $oid_arrayVimmEntry_failed = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.10'; + +my %map_vimm_state = ( + 1 => 'failed', + 2 => 'not failed', +); + +my %map_vimm_present = ( + 1 => 'present', + 2 => 'absent', +); + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking vimms"); + $self->{components}->{vimm} = {name => 'vimms', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'vimm')); + + foreach my $oid (keys %{$self->{results}->{$oid_arrayVimmEntry_present}}) { + next if ($oid !~ /^$oid_arrayVimmEntry_present\.(.*)$/); + my $state = $self->{results}->{$oid_arrayVimmEntry_failed}->{$oid_arrayVimmEntry_failed . '.' . $1}; + my $present = $self->{results}->{$oid_arrayVimmEntry_present}->{$oid}; + my ($dummy, $array_name, $vimm_name) = $self->convert_index(value => $1); + my $instance = $array_name . '-' . $vimm_name; + + next if ($self->check_exclude(section => 'vimm', instance => $instance)); + next if ($map_vimm_present{$present} =~ /Absent/i && + $self->absent_problem(section => 'vimm', instance => $instance)); + + $self->{components}->{vimm}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Vimm '%s' is %s.", + $instance, $map_vimm_state{$state})); + my $exit = $self->get_severity(section => 'vimm', value => $map_vimm_state{$state}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Vimm '%s' is %s", $instance, $map_vimm_state{$state})); + } + } +} + +1; diff --git a/centreon/common/violin/snmp/mode/hardware.pm b/centreon/common/violin/snmp/mode/hardware.pm new file mode 100644 index 000000000..2d182f5e5 --- /dev/null +++ b/centreon/common/violin/snmp/mode/hardware.pm @@ -0,0 +1,390 @@ +################################################################################ +# 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 centreon::common::violin::snmp::mode::hardware; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::common::violin::snmp::mode::components::ca; +use centreon::common::violin::snmp::mode::components::psu; +use centreon::common::violin::snmp::mode::components::fan; +use centreon::common::violin::snmp::mode::components::vimm; +use centreon::common::violin::snmp::mode::components::temperature; +use centreon::common::violin::snmp::mode::components::lfc; +use centreon::common::violin::snmp::mode::components::gfc; + +my $oid_chassisSystemLedAlarm = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.7'; +my $oid_chassisSystemPowerPSUA = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.17'; +my $oid_chassisSystemPowerPSUB = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.18'; +my $oid_chassisSystemTempAmbient = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21'; +my $oid_chassisSystemTempController = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21'; +my $oid_arrayFanEntry_speed = '.1.3.6.1.4.1.35897.1.2.2.3.18.1.3'; +my $oid_arrayVimmEntry_present = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.4'; +my $oid_arrayVimmEntry_failed = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.10'; +my $oid_arrayVimmEntry_temp = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.12'; +my $oid_globalTargetFcEntry = '.1.3.6.1.4.1.35897.1.2.1.10.1'; +my $oid_localTargetFcEntry = '.1.3.6.1.4.1.35897.1.2.1.6.1'; + +my $thresholds = { + vimm => [ + ['not failed', 'OK'], + ['failed', 'CRITICAL'], + ], + ca => [ + ['ON', 'CRITICAL'], + ['OFF', 'OK'], + ], + psu => [ + ['OFF', 'CRITICAL'], + ['Absent', 'OK'], + ['ON', 'OK'], + ], + fan => [ + ['OFF', 'CRITICAL'], + ['Absent', 'OK'], + ['Low', 'OK'], + ['Medium', 'OK'], + ['High', 'WARNING'], + ], + gfc => [ + ['Online', 'OK'], + ['Unconfigured', 'OK'], + ['Unknown', 'UNKNOWN'], + ['Not\s*Supported', 'WARNING'], + ['Dead', 'CRITICAL'], + ['Lost', 'CRITICAL'], + ['Failover\s*Failed', 'CRITICAL'], + ['Failover', 'WARNING'], + ], + lfc => [ + ['Online', 'OK'], + ['Unconfigured', 'OK'], + ['Unknown', 'UNKNOWN'], + ['Not\s*Supported', 'WARNING'], + ['Dead', 'CRITICAL'], + ['Lost', 'CRITICAL'], + ['Failover\s*Failed', 'CRITICAL'], + ['Failover', 'WARNING'], + ], +}; + +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 => + { + "exclude:s" => { name => 'exclude' }, + "component:s" => { name => 'component', default => 'all' }, + "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; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (defined($self->{option_results}->{no_component})) { + if ($self->{option_results}->{no_component} ne '') { + $self->{no_components} = $self->{option_results}->{no_component}; + } else { + $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) = ('temperature', $1, $2); + 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 { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + $self->{results} = $self->{snmp}->get_multiple_table(oids => [ + { oid => $oid_arrayFanEntry_speed }, + { oid => $oid_arrayVimmEntry_present }, + { oid => $oid_arrayVimmEntry_failed }, + { oid => $oid_arrayVimmEntry_temp }, + { oid => $oid_globalTargetFcEntry }, + { oid => $oid_localTargetFcEntry }, + { oid => $oid_chassisSystemLedAlarm }, + { oid => $oid_chassisSystemPowerPSUA }, + { oid => $oid_chassisSystemPowerPSUB }, + { oid => $oid_chassisSystemTempAmbient }, + { oid => $oid_chassisSystemTempController }, + ]); + if ($self->{option_results}->{component} eq 'all') { + centreon::common::violin::snmp::mode::components::ca::check($self); + centreon::common::violin::snmp::mode::components::psu::check($self); + centreon::common::violin::snmp::mode::components::fan::check($self); + centreon::common::violin::snmp::mode::components::vimm::check($self); + centreon::common::violin::snmp::mode::components::temperature::check($self); + centreon::common::violin::snmp::mode::components::gfc::check($self); + centreon::common::violin::snmp::mode::components::lfc::check($self); + } elsif ($self->{option_results}->{component} eq 'fan') { + centreon::common::violin::snmp::mode::components::fan::check($self); + } elsif ($self->{option_results}->{component} eq 'psu') { + centreon::common::violin::snmp::mode::components::psu::check($self); + } elsif ($self->{option_results}->{component} eq 'vimm') { + centreon::common::violin::snmp::mode::components::vimm::check($self); + } elsif ($self->{option_results}->{component} eq 'temperature') { + centreon::common::violin::snmp::mode::components::psu::check($self); + } elsif ($self->{option_results}->{component} eq 'ca') { + centreon::common::violin::snmp::mode::components::ca::check($self); + } elsif ($self->{option_results}->{component} eq 'gfc') { + centreon::common::violin::snmp::mode::components::gfc::check($self); + } elsif ($self->{option_results}->{component} eq 'lfc') { + centreon::common::violin::snmp::mode::components::lfc::check($self); + } else { + $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); + $self->{output}->option_exit(); + } + + my $total_components = 0; + my $display_by_component = ''; + my $display_by_component_append = ''; + foreach my $comp (sort(keys %{$self->{components}})) { + # Skipping short msg when no components + next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); + $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; + $display_by_component_append = ', '; + } + + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("All %s components are ok [%s].", + $total_components, + $display_by_component) + ); + + if (defined($self->{option_results}->{no_component}) && $total_components == 0) { + $self->{output}->output_add(severity => $self->{no_components}, + short_msg => 'No components are checked.'); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub check_exclude { + my ($self, %options) = @_; + + if (defined($options{instance})) { + if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { + $self->{components}->{$options{section}}->{skip}++; + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); + return 1; + } + } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); + return 1; + } + return 0; +} + +sub absent_problem { + my ($self, %options) = @_; + + 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 get_severity_numeric { + my ($self, %options) = @_; + my $status = 'OK'; # default + my $thresholds = { warning => undef, critical => undef }; + + + 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}); + + } + } + $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); + } + + return ($status, $thresholds->{warning}, $thresholds->{critical}); +} + +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; + } + } + } + foreach (@{$thresholds->{$options{section}}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + + return $status; +} + +sub convert_index { + my ($self, %options) = @_; + + my @results = (); + my $separator = 32; + my $result = ''; + foreach (split /\./, $options{value}) { + if ($_ < $separator) { + push @results, $result; + $result = ''; + } else { + $result .= chr; + } + } + + push @results, $result; + return @results; +} + +1; + +__END__ + +=head1 MODE + +Check components (Fans, Power Supplies, Temperatures, Chassis alarm, vimm, global fc, local fc). + +=over 8 + +=item B<--component> + +Which component to check (Default: 'all'). +Can be: 'psu', 'fan', 'ca', 'vimm', 'lfc', 'gfc', 'temperature'. + +=item B<--exclude> + +Exclude some parts (comma seperated list) (Example: --exclude=psu) +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/storage/violin/3000/snmp/plugin.pm b/storage/violin/3000/snmp/plugin.pm new file mode 100644 index 000000000..d34546ed0 --- /dev/null +++ b/storage/violin/3000/snmp/plugin.pm @@ -0,0 +1,64 @@ +################################################################################ +# 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::violin::3000::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; + # $options->{options} = options object + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'hardware' => 'centreon::common::violin::snmp::mode::hardware', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Violin 3000 series in SNMP. + +=cut From ede58d62fc7c9ba10c10d341a4e74d0bc628d193 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Mon, 8 Dec 2014 19:50:08 +0100 Subject: [PATCH 03/14] Fix #6008 --- .../printers/standard/rfc3805/mode/markersupply.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/hardware/printers/standard/rfc3805/mode/markersupply.pm b/hardware/printers/standard/rfc3805/mode/markersupply.pm index bd88ba2b7..68e31fd56 100644 --- a/hardware/printers/standard/rfc3805/mode/markersupply.pm +++ b/hardware/printers/standard/rfc3805/mode/markersupply.pm @@ -62,6 +62,7 @@ sub new { { "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, + "filter:s" => { name => 'filter' }, }); return $self; @@ -132,6 +133,11 @@ sub run { $self->{output}->output_add(long_msg => "Marker supply '$descr': no level but some space remaining."); next; } + if (defined($self->{option_results}->{filter}) && $self->{option_results}->{filter} ne '' && + $instance !~ /$self->{option_results}->{filter}/) { + $self->{output}->output_add(long_msg => "Skipping marker supply '$descr' (instance: $instance): filter."); + next; + } my $prct_value = $current_value; if ($unit_managed{$unit} == 1) { @@ -139,7 +145,7 @@ sub run { } my $exit = $self->{perfdata}->threshold_check(value => $prct_value, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(long_msg => sprintf("Marker supply '%s': %.2f %%", $descr, $prct_value)); + $self->{output}->output_add(long_msg => sprintf("Marker supply '%s': %.2f %% [instance: '%s']", $descr, $prct_value, $hrDeviceIndex . '.' . $prtMarkerSuppliesIndex)); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Marker supply '%s': %.2f %%", $descr, $prct_value)); @@ -149,7 +155,7 @@ sub run { if ($result->{$oid_prtMarkerSuppliesColorantIndex . '.' . $instance} != 0) { $label = $result2->{$oid_prtMarkerColorantValue . '.' . $hrDeviceIndex . '.' . $result->{$oid_prtMarkerSuppliesColorantIndex . '.' . $instance}}; if (defined($perf_label->{$label})) { - $label .= '#' . $hrDeviceIndex . '#' . $result->{$oid_prtMarkerSuppliesColorantIndex . '.' . $instance}; + $label .= '#' . $hrDeviceIndex . '#' . $prtMarkerSuppliesIndex; } } $perf_label->{$label} = 1; @@ -183,6 +189,10 @@ Threshold warning in percent. Threshold critical in percent. +=item B<--filter> + +Filter maker supply instance. + =back =cut From 6a4bb008eae09dd4a4031363c17e1cd18736ba1c Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Mon, 8 Dec 2014 20:15:21 +0100 Subject: [PATCH 04/14] Refs #5918 --- centreon/plugins/script_custom.pm | 2 +- centreon/plugins/script_simple.pm | 2 +- centreon/plugins/script_snmp.pm | 11 ++++++----- centreon/plugins/script_sql.pm | 2 +- centreon/plugins/script_wsman.pm | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/centreon/plugins/script_custom.pm b/centreon/plugins/script_custom.pm index 9cd912d50..d4537427c 100644 --- a/centreon/plugins/script_custom.pm +++ b/centreon/plugins/script_custom.pm @@ -121,7 +121,7 @@ sub init { } elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') { centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, error_msg => "Cannot load module --dyn-mode."); - $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name}); + $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name}); } else { $self->{output}->add_option_msg(short_msg => "Need to specify '--mode' or '--dyn-mode' option."); $self->{output}->option_exit(); diff --git a/centreon/plugins/script_simple.pm b/centreon/plugins/script_simple.pm index 4abae8c32..8fe717cb7 100644 --- a/centreon/plugins/script_simple.pm +++ b/centreon/plugins/script_simple.pm @@ -100,7 +100,7 @@ sub init { } elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') { centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, error_msg => "Cannot load module --dyn-mode."); - $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name}); + $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name}); } else { $self->{output}->add_option_msg(short_msg => "Need to specify '--mode' or '--dyn-mode' option."); $self->{output}->option_exit(); diff --git a/centreon/plugins/script_snmp.pm b/centreon/plugins/script_snmp.pm index 26ece81f5..273e2aad3 100644 --- a/centreon/plugins/script_snmp.pm +++ b/centreon/plugins/script_snmp.pm @@ -52,7 +52,7 @@ sub new { $self->{options}->add_options( arguments => { - 'mode:s' => { name => 'mode' }, + 'mode:s' => { name => 'mode_name' }, 'dyn-mode:s' => { name => 'dynmode_name' }, 'list-mode' => { name => 'list_mode' }, 'mode-version:s' => { name => 'mode_version' }, @@ -63,9 +63,10 @@ sub new { $self->{default} = undef; $self->{options}->parse_options(); - $self->{mode_name} = $self->{options}->get_option(argument => 'mode'); - $self->{list_mode} = $self->{options}->get_option(argument => 'list_mode'); - $self->{mode_version} = $self->{options}->get_option(argument => 'mode_version'); + $self->{option_results} = $self->{options}->get_options(); + foreach (keys %{$self->{option_results}}) { + $self->{$_} = $self->{option_results}->{$_}; + } $self->{options}->clean(); $self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION'); @@ -105,7 +106,7 @@ sub init { } elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') { centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, error_msg => "Cannot load module --dyn-mode."); - $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name}); + $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name}); } else { $self->{output}->add_option_msg(short_msg => "Need to specify '--mode' or '--dyn-mode' option."); $self->{output}->option_exit(); diff --git a/centreon/plugins/script_sql.pm b/centreon/plugins/script_sql.pm index 6e6a324cb..c8be98bef 100644 --- a/centreon/plugins/script_sql.pm +++ b/centreon/plugins/script_sql.pm @@ -122,7 +122,7 @@ sub init { } elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') { centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, error_msg => "Cannot load module --dyn-mode."); - $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name}); + $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name}); } else { $self->{output}->add_option_msg(short_msg => "Need to specify '--mode' or '--dyn-mode' option."); $self->{output}->option_exit(); diff --git a/centreon/plugins/script_wsman.pm b/centreon/plugins/script_wsman.pm index 151f3ae01..651c9485e 100644 --- a/centreon/plugins/script_wsman.pm +++ b/centreon/plugins/script_wsman.pm @@ -105,7 +105,7 @@ sub init { } elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') { centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, error_msg => "Cannot load module --dyn-mode."); - $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name}); + $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name}); } else { $self->{output}->add_option_msg(short_msg => "Need to specify '--mode' or '--dyn-mode' option."); $self->{output}->option_exit(); From 51161790c6c5463d18729671a329aa938895f48a Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Tue, 9 Dec 2014 19:18:58 +0100 Subject: [PATCH 05/14] Refs #5353 Worked on datadomain plugin --- .../snmp/mode/components/temperature.pm | 2 +- storage/emc/DataDomain/lib/functions.pm | 46 +++ .../emc/DataDomain/mode/components/battery.pm | 101 +++++ .../emc/DataDomain/mode/components/disk.pm | 86 ++++ storage/emc/DataDomain/mode/components/fan.pm | 66 ++-- storage/emc/DataDomain/mode/components/psu.pm | 56 +-- .../DataDomain/mode/components/temperature.pm | 81 ++-- storage/emc/DataDomain/mode/environment.pm | 147 ------- storage/emc/DataDomain/mode/filesystem.pm | 320 +++++++++++++++ storage/emc/DataDomain/mode/hardware.pm | 367 ++++++++++++++++++ storage/emc/DataDomain/mode/nvrambattery.pm | 153 -------- storage/emc/DataDomain/plugin.pm | 4 +- storage/violin/3000/snmp/plugin.pm | 1 + 13 files changed, 1045 insertions(+), 385 deletions(-) create mode 100644 storage/emc/DataDomain/lib/functions.pm create mode 100644 storage/emc/DataDomain/mode/components/battery.pm create mode 100644 storage/emc/DataDomain/mode/components/disk.pm delete mode 100644 storage/emc/DataDomain/mode/environment.pm create mode 100644 storage/emc/DataDomain/mode/filesystem.pm create mode 100644 storage/emc/DataDomain/mode/hardware.pm delete mode 100644 storage/emc/DataDomain/mode/nvrambattery.pm diff --git a/centreon/common/violin/snmp/mode/components/temperature.pm b/centreon/common/violin/snmp/mode/components/temperature.pm index 00ec7232b..a4d6dcef1 100644 --- a/centreon/common/violin/snmp/mode/components/temperature.pm +++ b/centreon/common/violin/snmp/mode/components/temperature.pm @@ -66,7 +66,7 @@ sub temperature { critical => $crit); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Power Supply '%s' is %s", $instance, $temperature)); + short_msg => sprintf("Temperature '%s' is %s degree centigrade", $instance, $temperature)); } } diff --git a/storage/emc/DataDomain/lib/functions.pm b/storage/emc/DataDomain/lib/functions.pm new file mode 100644 index 000000000..fd0f7213f --- /dev/null +++ b/storage/emc/DataDomain/lib/functions.pm @@ -0,0 +1,46 @@ +################################################################################ +# 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::emc::DataDomain::lib::functions; + +sub get_version { + my (%options) = @_; + + return $1 if (defined($options{value}) && $options{value} =~ /(\d+\.\d+\.\d+)/); + return undef; +} + +1; + \ No newline at end of file diff --git a/storage/emc/DataDomain/mode/components/battery.pm b/storage/emc/DataDomain/mode/components/battery.pm new file mode 100644 index 000000000..b552531af --- /dev/null +++ b/storage/emc/DataDomain/mode/components/battery.pm @@ -0,0 +1,101 @@ +################################################################################ +# 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::emc::DataDomain::mode::components::battery; + +use strict; +use warnings; +use centreon::plugins::misc; + +my %map_battery_status = (); +my ($oid_nvramBatteryStatus, $oid_nvramBatteryCharge); +my $oid_nvramBatteryEntry = '.1.3.6.1.4.1.19746.1.2.3.1.1'; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking nvram batteries"); + $self->{components}->{battery} = {name => 'nvram batteries', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'battery')); + + if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { + $oid_nvramBatteryStatus = '.1.3.6.1.4.1.19746.1.2.3.1.1.3'; + $oid_nvramBatteryCharge = '.1.3.6.1.4.1.19746.1.2.3.1.1.4'; + %map_battery_status = (0 => 'ok', 1 => 'disabled', 2 => 'discharged', 4 => 'softdisabled'); + } else { + $oid_nvramBatteryStatus = '.1.3.6.1.4.1.19746.1.2.3.1.1.2'; + $oid_nvramBatteryCharge = '.1.3.6.1.4.1.19746.1.2.3.1.1.3'; + %map_battery_status = (1 => 'ok', 2 => 'disabled', 3 => 'discharged', 4 => 'unknown', + 5 => 'softdisabled'); + } + + foreach my $oid (keys %{$self->{results}->{$oid_nvramBatteryEntry}}) { + next if ($oid !~ /^$oid_nvramBatteryStatus\.(.*)$/); + my $instance = $1; + my $batt_status = defined($map_battery_status{$self->{results}->{$oid_nvramBatteryEntry}->{$oid}}) ? + $map_battery_status{$self->{results}->{$oid_nvramBatteryEntry}->{$oid}} : 'unknown'; + my $batt_value = $self->{results}->{$oid_nvramBatteryEntry}->{$oid_nvramBatteryCharge . '.' . $instance}; + + next if ($self->check_exclude(section => 'battery', instance => $instance)); + next if ($batt_status =~ /disabled/i && + $self->absent_problem(section => 'battery', instance => $instance)); + + $self->{components}->{battery}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Nvram battery '%s' status is '%s'", + $instance, $batt_status)); + my $exit = $self->get_severity(section => 'battery', value => $batt_status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Nvram battery '%s' status is '%s'", $instance, $batt_status)); + } + + if (defined($batt_value) && $batt_value =~ /[0-9]/) { + my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'battery', instance => $instance, value => $batt_value); + $self->{output}->output_add(long_msg => sprintf("Nvram battery '%s' charge is %s %%", $instance, $batt_value)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Nvram battery '%s' charge is %s %%", $instance, $batt_value)); + } + $self->{output}->perfdata_add(label => 'nvram_battery_' . $instance, unit => '%', + value => $batt_value, + warning => $warn, + critical => $crit, + min => 0, max => 100 + ); + } + } +} + +1; \ No newline at end of file diff --git a/storage/emc/DataDomain/mode/components/disk.pm b/storage/emc/DataDomain/mode/components/disk.pm new file mode 100644 index 000000000..ff45efbbf --- /dev/null +++ b/storage/emc/DataDomain/mode/components/disk.pm @@ -0,0 +1,86 @@ +################################################################################ +# 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::emc::DataDomain::mode::components::disk; + +use strict; +use warnings; +use centreon::plugins::misc; + +my $oid_diskPropState; + +my %map_disk_status = ( + 1 => 'ok', + 2 => 'unknown', + 3 => 'absent', + 4 => 'failed', +); + +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_exclude(section => 'disk')); + + my $oid_diskPropState; + if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { + $oid_diskPropState = '.1.3.6.1.4.1.19746.1.6.1.1.1.8'; + } else { + $oid_diskPropState = '.1.3.6.1.4.1.19746.1.6.1.1.1.7'; + } + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_diskPropState}})) { + $oid =~ /^$oid_diskPropState\.(.*)$/; + my $instance = $1; + my $disk_status = defined($map_disk_status{$self->{results}->{$oid_diskPropState}->{$oid}}) ? + $map_disk_status{$self->{results}->{$oid_diskPropState}->{$oid}} : 'unknown'; + + next if ($self->check_exclude(section => 'disk', instance => $instance)); + next if ($disk_status =~ /absent/i && + $self->absent_problem(section => 'disk', instance => $instance)); + + $self->{components}->{disk}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Disk '%s' status is '%s'", + $instance, $disk_status)); + my $exit = $self->get_severity(section => 'fan', value => $disk_status); + 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, $disk_status)); + } + } +} + +1; \ No newline at end of file diff --git a/storage/emc/DataDomain/mode/components/fan.pm b/storage/emc/DataDomain/mode/components/fan.pm index 902292b41..d2d6b0600 100644 --- a/storage/emc/DataDomain/mode/components/fan.pm +++ b/storage/emc/DataDomain/mode/components/fan.pm @@ -39,47 +39,57 @@ use strict; use warnings; use centreon::plugins::misc; -my %conditions = ( - 0 => ['not found', 'UNKNOWN'], - 1 => ['ok', 'OK'], - 2 => ['failed', 'CRITICAL'], +my %map_fan_status = ( + 0 => 'notfound', + 1 => 'ok', + 2 => 'failed', ); -my %level_map = ( +my %level_map = ( 0 => 'unknown', 1 => 'low', 2 => 'normal', 3 => 'high', -); +); + +my ($oid_fanDescription, $oid_fanLevel, $oid_fanStatus); +my $oid_fanPropertiesEntry = '.1.3.6.1.4.1.19746.1.1.3.1.1.1'; sub check { my ($self) = @_; - $self->{components}->{fans} = {name => 'fans', total => 0}; $self->{output}->output_add(long_msg => "Checking fans"); - return if ($self->check_exclude('fans')); + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'fan')); - my $oid_fanPropertiesEntry = '.1.3.6.1.4.1.19746.1.1.3.1.1.1'; - my $oid_fanDescription = '.1.3.6.1.4.1.19746.1.1.3.1.1.1.3'; - my $oid_fanLevel = '.1.3.6.1.4.1.19746.1.1.3.1.1.1.4'; - my $oid_fanStatus = '.1.3.6.1.4.1.19746.1.1.3.1.1.1.5'; - - my $result = $self->{snmp}->get_table(oid => $oid_fanPropertiesEntry); - return if (scalar(keys %$result) <= 0); + if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { + $oid_fanDescription = '.1.3.6.1.4.1.19746.1.1.3.1.1.1.4'; + $oid_fanLevel = '.1.3.6.1.4.1.19746.1.1.3.1.1.1.5'; + $oid_fanStatus = '.1.3.6.1.4.1.19746.1.1.3.1.1.1.6'; + } else { + $oid_fanDescription = '.1.3.6.1.4.1.19746.1.1.3.1.1.1.3'; + $oid_fanLevel = '.1.3.6.1.4.1.19746.1.1.3.1.1.1.4'; + $oid_fanStatus = '.1.3.6.1.4.1.19746.1.1.3.1.1.1.5'; + } - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_fanStatus\.(\d+)\.(\d+)$/); - my ($enclosure_id, $fan_index) = ($1, $2); - - my $fan_descr = centreon::plugins::misc::trim($result->{$oid_fanDescription . '.' . $enclosure_id . '.' . $fan_index}); - my $fan_level = $result->{$oid_fanLevel . '.' . $enclosure_id . '.' . $fan_index}; - my $fan_status = $result->{$oid_fanStatus . '.' . $enclosure_id . '.' . $fan_index}; + foreach my $oid (keys %{$self->{results}->{$oid_fanPropertiesEntry}}) { + next if ($oid !~ /^$oid_fanStatus\.(.*)$/); + my $instance = $1; + my $fan_descr = centreon::plugins::misc::trim($self->{results}->{$oid_fanPropertiesEntry}->{$oid_fanDescription . '.' . $instance}); + my $fan_status = defined($map_fan_status{$self->{results}->{$oid_fanPropertiesEntry}->{$oid}}) ? + $map_fan_status{$self->{results}->{$oid_fanPropertiesEntry}->{$oid}} : 'unknown'; + my $fan_level = $self->{results}->{$oid_fanPropertiesEntry}->{$oid_fanLevel . '.' . $instance}; - $self->{components}->{fans}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is %s [enclosure = %d, index = %d, level = %s].", - $fan_descr, ${$conditions{$fan_status}}[0], $enclosure_id, $fan_index, $level_map{$fan_level})); - if (!$self->{output}->is_status(litteral => 1, value => ${$conditions{$fan_status}}[1], compare => 'ok')) { - $self->{output}->output_add(severity => ${$conditions{$fan_status}}[1], - short_msg => sprintf("Fan '%s' status is %s", $fan_descr, ${$conditions{$fan_status}}[0])); + next if ($self->check_exclude(section => 'fan', instance => $instance)); + next if ($fan_status =~ /notfound/i && + $self->absent_problem(section => 'fan', instance => $instance)); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is '%s' [instance = %s, level = %s]", + $fan_descr, $fan_status, $instance, $level_map{$fan_level})); + my $exit = $self->get_severity(section => 'fan', value => $fan_status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' status is '%s'", $fan_descr, $fan_status)); } } } diff --git a/storage/emc/DataDomain/mode/components/psu.pm b/storage/emc/DataDomain/mode/components/psu.pm index a7aa34828..5b54778d8 100644 --- a/storage/emc/DataDomain/mode/components/psu.pm +++ b/storage/emc/DataDomain/mode/components/psu.pm @@ -38,37 +38,47 @@ package storage::emc::DataDomain::mode::components::psu; use strict; use warnings; -my %conditions = ( - 1 => ['ok', 'OK'], - 2 => ['unknown', 'UNKNOWN'], - 3 => ['fail', 'CRITICAL'], -); +my %map_psu_status = (); +my ($oid_powerModuleDescription, $oid_powerModuleStatus); +my $oid_powerModuleEntry = '.1.3.6.1.4.1.19746.1.1.1.1.1.1'; sub check { my ($self) = @_; - $self->{components}->{psus} = {name => 'power supplies', total => 0}; $self->{output}->output_add(long_msg => "Checking power supplies"); - return if ($self->check_exclude('psu')); + $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'psu')); - my $oid_powerModuleEntry = '.1.3.6.1.4.1.19746.1.1.1.1.1.1'; - my $oid_powerModuleStatus = '.1.3.6.1.4.1.19746.1.1.1.1.1.1.3'; - - my $result = $self->{snmp}->get_table(oid => $oid_powerModuleEntry); - return if (scalar(keys %$result) <= 0); + if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { + $oid_powerModuleDescription = '.1.3.6.1.4.1.19746.1.1.1.1.1.1.3'; + $oid_powerModuleStatus = '.1.3.6.1.4.1.19746.1.1.1.1.1.1.4'; + %map_psu_status = (0 => 'absent', 1 => 'ok', 2 => 'failed', 3 => 'faulty', 4 => 'acnone', + 99 => 'unknown'); + } else { + $oid_powerModuleDescription = ''; # none + $oid_powerModuleStatus = '.1.3.6.1.4.1.19746.1.1.1.1.1.1.4'; + %map_psu_status = (1 => 'ok', 2 => 'unknown', 3 => 'failed'); + } - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_powerModuleStatus\.(\d+)\.(\d+)$/); - my ($enclosure_id, $module_index) = ($1, $2); - - my $psu_status = $result->{$oid_powerModuleStatus . '.' . $enclosure_id . '.' . $module_index}; + foreach my $oid (keys %{$self->{results}->{$oid_powerModuleEntry}}) { + next if ($oid !~ /^$oid_powerModuleStatus\.(.*)$/); + my $instance = $1; + my $psu_descr = defined($self->{results}->{$oid_powerModuleEntry}->{$oid_powerModuleDescription . '.' . $instance}) ? + centreon::plugins::misc::trim($self->{results}->{$oid_powerModuleEntry}->{$oid_powerModuleDescription . '.' . $instance}) : 'unknown'; + my $psu_status = defined($map_psu_status{$self->{results}->{$oid_powerModuleEntry}->{$oid}}) ? + $map_psu_status{$self->{results}->{$oid_powerModuleEntry}->{$oid}} : 'unknown'; - $self->{components}->{psus}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is %s.", - $enclosure_id . '/' . $module_index, ${$conditions{$psu_status}}[0])); - if (!$self->{output}->is_status(litteral => 1, value => ${$conditions{$psu_status}}[1], compare => 'ok')) { - $self->{output}->output_add(severity => ${$conditions{$psu_status}}[1], - short_msg => sprintf("Power Supply '%s' status is %s", $enclosure_id . '/' . $module_index, ${$conditions{$psu_status}}[0])); + next if ($self->check_exclude(section => 'psu', instance => $instance)); + next if ($psu_status =~ /absent/i && + $self->absent_problem(section => 'psu', instance => $instance)); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is '%s' [description = %s]", + $instance, $psu_status, $instance)); + my $exit = $self->get_severity(section => 'psu', value => $psu_status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power Supply '%s' status is '%s'", $instance, $psu_status)); } } } diff --git a/storage/emc/DataDomain/mode/components/temperature.pm b/storage/emc/DataDomain/mode/components/temperature.pm index aea8dacd6..698844e39 100644 --- a/storage/emc/DataDomain/mode/components/temperature.pm +++ b/storage/emc/DataDomain/mode/components/temperature.pm @@ -39,46 +39,65 @@ use strict; use warnings; use centreon::plugins::misc; -my %conditions = ( - 0 => ['absent', 'CRITICAL'], - 1 => ['ok', 'OK'], - 2 => ['not found', 'UNKNOWN'], -); +my %map_temp_status = (); +my ($oid_tempSensorDescription, $oid_tempSensorCurrentValue, $oid_tempSensorStatus); +my $oid_temperatureSensorEntry = '.1.3.6.1.4.1.19746.1.1.2.1.1.1'; sub check { my ($self) = @_; - $self->{components}->{temperatures} = {name => 'temperatures', total => 0}; $self->{output}->output_add(long_msg => "Checking temperatures"); - return if ($self->check_exclude('temperatures')); + $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'temperature')); - my $oid_temperatureSensorEntry = '.1.3.6.1.4.1.19746.1.1.2.1.1.1'; - my $oid_tempSensorDescription = '.1.3.6.1.4.1.19746.1.1.2.1.1.1.3'; - my $oid_tempSensorCurrentValue = '.1.3.6.1.4.1.19746.1.1.2.1.1.1.4'; - my $oid_tempSensorStatus = '.1.3.6.1.4.1.19746.1.1.2.1.1.1.5'; - - my $result = $self->{snmp}->get_table(oid => $oid_temperatureSensorEntry); - return if (scalar(keys %$result) <= 0); + if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { + $oid_tempSensorDescription = '.1.3.6.1.4.1.19746.1.1.2.1.1.1.4'; + $oid_tempSensorCurrentValue = '.1.3.6.1.4.1.19746.1.1.2.1.1.1.5'; + $oid_tempSensorStatus = '.1.3.6.1.4.1.19746.1.1.2.1.1.1.6'; + %map_temp_status = (0 => 'failed', 1 => 'ok', 2 => 'notfound', 3 => 'overheatWarning', + 4 => 'overheatCritical'); + } else { + $oid_tempSensorDescription = '.1.3.6.1.4.1.19746.1.1.2.1.1.1.3'; + $oid_tempSensorCurrentValue = '.1.3.6.1.4.1.19746.1.1.2.1.1.1.4'; + $oid_tempSensorStatus = '.1.3.6.1.4.1.19746.1.1.2.1.1.1.5'; + %map_temp_status = (0 => 'absent', 1 => 'ok', 2 => 'notfound'); + } - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_tempSensorCurrentValue\.(\d+)\.(\d+)$/); - my ($enclosure_id, $sensor_index) = ($1, $2); - - my $temp_descr = centreon::plugins::misc::trim($result->{$oid_tempSensorDescription . '.' . $enclosure_id . '.' . $sensor_index}); - my $temp_value = $result->{$oid_tempSensorCurrentValue . '.' . $enclosure_id . '.' . $sensor_index}; - my $temp_status = $result->{$oid_tempSensorStatus . '.' . $enclosure_id . '.' . $sensor_index}; + foreach my $oid (keys %{$self->{results}->{$oid_temperatureSensorEntry}}) { + next if ($oid !~ /^$oid_tempSensorStatus\.(.*)$/); + my $instance = $1; + my $temp_descr = defined($self->{results}->{$oid_temperatureSensorEntry}->{$oid_tempSensorDescription . '.' . $instance}) ? + centreon::plugins::misc::trim($self->{results}->{$oid_temperatureSensorEntry}->{$oid_tempSensorDescription . '.' . $instance}) : 'unknown'; + my $temp_status = defined($map_temp_status{$self->{results}->{$oid_temperatureSensorEntry}->{$oid}}) ? + $map_temp_status{$self->{results}->{$oid_temperatureSensorEntry}->{$oid}} : 'unknown'; + my $temp_value = $self->{results}->{$oid_temperatureSensorEntry}->{$oid_tempSensorCurrentValue . '.' . $instance}; - $self->{components}->{temperatures}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is %s [enclosure = %d, sensor = %d, current_value = %s].", - $temp_descr, ${$conditions{$temp_status}}[0], $enclosure_id, $sensor_index, $temp_value)); - if (!$self->{output}->is_status(litteral => 1, value => ${$conditions{$temp_status}}[1], compare => 'ok')) { - $self->{output}->output_add(severity => ${$conditions{$temp_status}}[1], - short_msg => sprintf("Temperature '%s' status is %s", $temp_descr, ${$conditions{$temp_status}}[0])); - } + next if ($self->check_exclude(section => 'temperature', instance => $instance)); + next if ($temp_status =~ /absent|notfound/i && + $self->absent_problem(section => 'temperature', instance => $instance)); - $self->{output}->perfdata_add(label => 'temp_' . $enclosure_id . '_' . $sensor_index, unit => 'C', - value => $temp_value, - ); + $self->{components}->{temperature}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is '%s' [instance = %s]", + $temp_descr, $temp_status, $instance)); + my $exit = $self->get_severity(section => 'temperature', value => $temp_status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' status is '%s'", $temp_descr, $temp_status)); + } + + if (defined($temp_value) && $temp_value =~ /[0-9]/) { + my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $temp_value); + $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is %s degree centigrade", $temp_descr, $temp_value)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' is %s degree centigrade", $temp_descr, $temp_value)); + } + $self->{output}->perfdata_add(label => 'temp_' . $instance, unit => 'C', + value => $temp_value, + warning => $warn, + critical => $crit, + ); + } } } diff --git a/storage/emc/DataDomain/mode/environment.pm b/storage/emc/DataDomain/mode/environment.pm deleted file mode 100644 index 7451ed33e..000000000 --- a/storage/emc/DataDomain/mode/environment.pm +++ /dev/null @@ -1,147 +0,0 @@ -################################################################################ -# 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::emc::DataDomain::mode::environment; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -use storage::emc::DataDomain::mode::components::psu; -use storage::emc::DataDomain::mode::components::temperature; -use storage::emc::DataDomain::mode::components::fan; - -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 => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - }); - $self->{components} = {}; - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - -sub global { - my ($self, %options) = @_; - - storage::emc::DataDomain::mode::components::psu::check($self); - storage::emc::DataDomain::mode::components::temperature::check($self); - storage::emc::DataDomain::mode::components::fan::check($self); -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - if ($self->{option_results}->{component} eq 'all') { - $self->global(); - } elsif ($self->{option_results}->{component} eq 'psu') { - storage::emc::DataDomain::mode::components::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'temperature') { - storage::emc::DataDomain::mode::components::temperature::check($self); - } elsif ($self->{option_results}->{component} eq 'fan') { - storage::emc::DataDomain::mode::components::fan::check($self); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0); - $total_components += $self->{components}->{$comp}->{total}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components [%s] are ok.", - $total_components, - $display_by_component - ) - ); - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, $section) = @_; - - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$section(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $section section.")); - return 1; - } - return 0; -} - -1; - -__END__ - -=head1 MODE - -Check environments (Fans, Temperatures, Power Supplies) (DATA-DOMAIN-MIB). - -=over 8 - -=item B<--component> - -Which component to check (Default: 'all'). -Can be: 'fan', 'temperature', 'psu'. - -=item B<--exclude> - -Exclude some parts (comma seperated list) (Example: --exclude=temperatures,fans). - -=back - -=cut - \ No newline at end of file diff --git a/storage/emc/DataDomain/mode/filesystem.pm b/storage/emc/DataDomain/mode/filesystem.pm new file mode 100644 index 000000000..91a35bbe4 --- /dev/null +++ b/storage/emc/DataDomain/mode/filesystem.pm @@ -0,0 +1,320 @@ +################################################################################ +# 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::emc::DataDomain::mode::filesystem; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use storage::emc::DataDomain::lib::functions; +use centreon::plugins::values; + +my $oid_fileSystemSpaceEntry = '.1.3.6.1.4.1.19746.1.3.2.1.1'; +my $oid_sysDescr = '.1.3.6.1.2.1.1.1'; # 'Data Domain OS 5.4.1.1-411752' +my ($oid_fileSystemResourceName, $oid_fileSystemSpaceUsed, $oid_fileSystemSpaceAvail); + +my $maps_counters = { + usage => { class => 'centreon::plugins::values', obj => undef, + set => { + key_values => [ + { name => 'free' }, { name => 'used' }, { name => 'display' }, + ], + closure_custom_calc => \&custom_used_calc, + closure_custom_output => \&custom_used_output, + threshold_use => 'used_prct', + output_error_template => '%s', + perfdatas => [ + { value => 'used', label => 'used', template => '%d', + unit => 'B', min => 0, max => 'total', threshold_total => 'total', + label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, +}; + +sub custom_used_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_free'} + $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{free_prct} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{used_prct} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + return 0; +} + +sub custom_used_output { + my ($self, %options) = @_; + + my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + + return sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_value . " " . $total_unit, + $used_value . " " . $used_unit, $self->{result_values}->{used_prct}, + $free_value . " " . $free_unit, $self->{result_values}->{free_prct}); +} + +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 => + { + "name" => { name => 'use_name' }, + "filesystem:s" => { name => 'filesystem' }, + "regexp" => { name => 'use_regexp' }, + "regexp-isensitive" => { name => 'use_regexpi' }, + }); + + $self->{filesystem_id_selected} = {}; + + 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}); + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + + my $multiple = 1; + if (scalar(keys %{$self->{filesystem_id_selected}}) == 1) { + $multiple = 0; + } + + if ($multiple == 1) { + $self->{output}->output_add(severity => 'OK', + short_msg => 'All filesystems are ok.'); + } + + foreach my $id (sort keys %{$self->{filesystem_id_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->{filesystem_id_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(extra_instance => $multiple); + } + + $self->{output}->output_add(long_msg => "Filesystem '" . $self->{filesystem_id_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 => "Filesystem '" . $self->{filesystem_id_selected}->{$id}->{display} . "' $short_msg" + ); + } + + if ($multiple == 0) { + $self->{output}->output_add(short_msg => "Filesystem '" . $self->{filesystem_id_selected}->{$id}->{display} . "' $long_msg"); + } + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub add_result { + my ($self, %options) = @_; + + $self->{filesystem_id_selected}->{$options{instance}} = {}; + $self->{filesystem_id_selected}->{$options{instance}}->{display} = $self->{results}->{$oid_fileSystemSpaceEntry}->{$oid_fileSystemResourceName . '.' . $options{instance}}; + $self->{filesystem_id_selected}->{$options{instance}}->{free} = int($self->{results}->{$oid_fileSystemSpaceEntry}->{$oid_fileSystemSpaceAvail . '.' . $options{instance}} * 1024 * 1024 * 1024); + $self->{filesystem_id_selected}->{$options{instance}}->{used} = int($self->{results}->{$oid_fileSystemSpaceEntry}->{$oid_fileSystemSpaceUsed . '.' . $options{instance}} * 1024 * 1024 * 1024); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{results} = $self->{snmp}->get_multiple_table(oids => [ + { oid => $oid_sysDescr }, + { oid => $oid_fileSystemSpaceEntry }, + ], + , nothing_quit => 1); + if (!($self->{os_version} = storage::emc::DataDomain::lib::functions::get_version(value => $self->{results}->{$oid_sysDescr}->{$oid_sysDescr . '.0'}))) { + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => 'Cannot get DataDomain OS version.'); + $self->{output}->display(); + $self->{output}->exit(); + } + if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { + $oid_fileSystemResourceName = '.1.3.6.1.4.1.19746.1.3.2.1.1.3'; + $oid_fileSystemSpaceUsed = '.1.3.6.1.4.1.19746.1.3.2.1.1.5'; + $oid_fileSystemSpaceAvail = '.1.3.6.1.4.1.19746.1.3.2.1.1.6'; + } else { + $oid_fileSystemResourceName = '.1.3.6.1.4.1.19746.1.3.2.1.1.2'; + $oid_fileSystemSpaceUsed = '.1.3.6.1.4.1.19746.1.3.2.1.1.4'; + $oid_fileSystemSpaceAvail = '.1.3.6.1.4.1.19746.1.3.2.1.1.5'; + } + + if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{filesystem})) { + if (!defined($self->{results}->{$oid_fileSystemSpaceEntry}->{$oid_fileSystemResourceName . '.' . $self->{option_results}->{filesystem}})) { + $self->{output}->add_option_msg(short_msg => "No filesystem found for id '" . $self->{option_results}->{filesystem} . "'."); + $self->{output}->option_exit(); + } + $self->add_result(instance => $self->{option_results}->{filesystem}); + } else { + foreach my $oid (keys %{$self->{results}->{$oid_fileSystemSpaceEntry}}) { + next if ($oid !~ /^$oid_fileSystemResourceName\.(\d+)$/); + my $instance = $1; + my $filter_name = $self->{results}->{$oid_fileSystemSpaceEntry}->{$oid_fileSystemResourceName . '.' . $instance}; + if (!defined($self->{option_results}->{filesystem})) { + $self->add_result(instance => $instance); + next; + } + if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{filesystem}/i) { + $self->add_result(instance => $instance); + } + if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{filesystem}/) { + $self->add_result(instance => $instance); + } + if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{filesystem}) { + $self->add_result(instance => $instance); + } + } + } + + if (scalar(keys %{$self->{filesystem_id_selected}}) <= 0 && !defined($options{disco})) { + if (defined($self->{option_results}->{device})) { + $self->{output}->add_option_msg(short_msg => "No filesystem found '" . $self->{option_results}->{filesystem} . "'."); + } else { + $self->{output}->add_option_msg(short_msg => "No filesystem found."); + } + $self->{output}->option_exit(); + } +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'deviceid']); +} + +sub disco_show { + my ($self, %options) = @_; + + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + $self->manage_selection(disco => 1); + foreach (sort keys %{$self->{filesystem_id_selected}}) { + $self->{output}->add_disco_entry(name => $self->{filesystem_id_selected}->{$_}->{display}, + deviceid => $_); + } +} + + +1; + +__END__ + +=head1 MODE + +Check filesystem usages. + +=over 8 + +=item B<--warning-usage> + +Threshold warning in percent. + +=item B<--critical-usage> + +Threshold critical in percent + +=item B<--filesystem> + +Set the filesystem (number expected) ex: 1, 2,... (empty means 'check all filesystems'). + +=item B<--name> + +Allows to use filesystem name with option --filesystem instead of devoce oid index. + +=item B<--regexp> + +Allows to use regexp to filter filesystems (with option --name). + +=item B<--regexp-isensitive> + +Allows to use regexp non case-sensitive to filter filesystems (with option --name). + +=back + +=cut diff --git a/storage/emc/DataDomain/mode/hardware.pm b/storage/emc/DataDomain/mode/hardware.pm new file mode 100644 index 000000000..97ed9b2af --- /dev/null +++ b/storage/emc/DataDomain/mode/hardware.pm @@ -0,0 +1,367 @@ +################################################################################ +# 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::emc::DataDomain::mode::hardware; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use storage::emc::DataDomain::lib::functions; +use storage::emc::DataDomain::mode::components::temperature; +use storage::emc::DataDomain::mode::components::psu; +use storage::emc::DataDomain::mode::components::fan; +use storage::emc::DataDomain::mode::components::disk; +use storage::emc::DataDomain::mode::components::battery; + +my $oid_sysDescr = '.1.3.6.1.2.1.1.1'; # 'Data Domain OS 5.4.1.1-411752' +my $oid_powerModuleEntry = '.1.3.6.1.4.1.19746.1.1.1.1.1.1'; +my $oid_temperatureSensorEntry = '.1.3.6.1.4.1.19746.1.1.2.1.1.1'; +my $oid_fanPropertiesEntry = '.1.3.6.1.4.1.19746.1.1.3.1.1.1'; +my $oid_nvramBatteryEntry = '.1.3.6.1.4.1.19746.1.2.3.1.1'; + +my $thresholds = { + fan => [ + ['notfound', 'OK'], + ['ok', 'OK'], + ['failed', 'CRITICAL'], + ], + temperature => [ + ['failed', 'CRITICAL'], + ['ok', 'OK'], + ['notfound', 'OK'], + ['absent', 'OK'], + ['overheatWarning', 'WARNING'], + ['overheatCritical', 'CRITICAL'], + ], + psu => [ + ['absent', 'OK'], + ['ok', 'OK'], + ['failed', 'CRITICAL'], + ['faulty', 'WARNING'], + ['acnone', 'WARNING'], + ['unknown', 'UNKNOWN'], + ], + disk => [ + ['ok', 'OK'], + ['unknown', 'UNKNOWN'], + ['absent', 'OK'], + ['failed', 'CRITICAL'], + ], + battery => [ + ['ok', 'OK'], + ['disabled', 'OK'], + ['discharged', 'WARNING'], + ['softdisabled', 'OK'], + ['UNKNOWN', 'UNKNOWN'], + ], +}; + +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 => + { + "exclude:s" => { name => 'exclude' }, + "component:s" => { name => 'component', default => 'all' }, + "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; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (defined($self->{option_results}->{no_component})) { + if ($self->{option_results}->{no_component} ne '') { + $self->{no_components} = $self->{option_results}->{no_component}; + } else { + $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 !~ /(battery|temperature)/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: battery 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 { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + $self->{results_leef} = $self->{snmp}->get_leef(oids => [ $oid_sysDescr . '.0' ]); + if (!($self->{os_version} = storage::emc::DataDomain::lib::functions::get_version(value => $self->{results_leef}->{$oid_sysDescr . '.0'}))) { + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => 'Cannot get DataDomain OS version.'); + $self->{output}->display(); + $self->{output}->exit(); + } + + my $oid_diskPropState; + if (centreon::plugins::misc::minimal_version($self->{os_version}, '5.x')) { + $oid_diskPropState = '.1.3.6.1.4.1.19746.1.6.1.1.1.8'; + } else { + $oid_diskPropState = '.1.3.6.1.4.1.19746.1.6.1.1.1.7'; + } + + $self->{results} = $self->{snmp}->get_multiple_table(oids => [ + { oid => $oid_powerModuleEntry }, + { oid => $oid_temperatureSensorEntry }, + { oid => $oid_fanPropertiesEntry }, + { oid => $oid_diskPropState }, + { oid => $oid_nvramBatteryEntry }, + ]); + + + $self->{output}->output_add(long_msg => 'DataDomain OS version: ' . $self->{os_version} . '.'); + if ($self->{option_results}->{component} eq 'all') { + storage::emc::DataDomain::mode::components::psu::check($self); + storage::emc::DataDomain::mode::components::fan::check($self); + storage::emc::DataDomain::mode::components::disk::check($self); + storage::emc::DataDomain::mode::components::temperature::check($self); + storage::emc::DataDomain::mode::components::battery::check($self); + } elsif ($self->{option_results}->{component} eq 'fan') { + storage::emc::DataDomain::mode::components::fan::check($self); + } elsif ($self->{option_results}->{component} eq 'psu') { + storage::emc::DataDomain::mode::components::psu::check($self); + } elsif ($self->{option_results}->{component} eq 'disk') { + storage::emc::DataDomain::mode::components::disk::check($self); + } elsif ($self->{option_results}->{component} eq 'temperature') { + storage::emc::DataDomain::mode::components::temperature::check($self); + } elsif ($self->{option_results}->{component} eq 'battery') { + storage::emc::DataDomain::mode::components::battery::check($self); + } else { + $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); + $self->{output}->option_exit(); + } + + my $total_components = 0; + my $display_by_component = ''; + my $display_by_component_append = ''; + foreach my $comp (sort(keys %{$self->{components}})) { + # Skipping short msg when no components + next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); + $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; + $display_by_component_append = ', '; + } + + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("All %s components are ok [%s].", + $total_components, + $display_by_component) + ); + + if (defined($self->{option_results}->{no_component}) && $total_components == 0) { + $self->{output}->output_add(severity => $self->{no_components}, + short_msg => 'No components are checked.'); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub check_exclude { + my ($self, %options) = @_; + + if (defined($options{instance})) { + if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { + $self->{components}->{$options{section}}->{skip}++; + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); + return 1; + } + } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); + return 1; + } + return 0; +} + +sub absent_problem { + my ($self, %options) = @_; + + 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 get_severity_numeric { + my ($self, %options) = @_; + my $status = 'OK'; # default + my $thresholds = { warning => undef, critical => undef }; + + 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}); + + } + } + $status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0); + } + + return ($status, $thresholds->{warning}, $thresholds->{critical}); +} + +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; + } + } + } + foreach (@{$thresholds->{$options{section}}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + + return $status; +} + +1; + +__END__ + +=head1 MODE + +Check components (Fans, Power Supplies, Temperatures, Disks, Nvram Batteries). + +=over 8 + +=item B<--component> + +Which component to check (Default: 'all'). +Can be: 'psu', 'fan', 'disk', 'temperature', 'battery'. + +=item B<--exclude> + +Exclude some parts (comma seperated list) (Example: --exclude=psu) +Can also exclude specific instance: --exclude='psu#3.3#' + +=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#1.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='fan,CRITICAL,^(?!(ok)$)' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: regexp,treshold) +Example: --warning='.*,20' + +=item B<--critical> + +Set critical threshold for temperatures and battery charge (syntax: type,regexp,treshold) +Example: --critical='temperature,1.1,25' --critical='battery,.*,20:' + +=back + +=cut + diff --git a/storage/emc/DataDomain/mode/nvrambattery.pm b/storage/emc/DataDomain/mode/nvrambattery.pm deleted file mode 100644 index 7eae94745..000000000 --- a/storage/emc/DataDomain/mode/nvrambattery.pm +++ /dev/null @@ -1,153 +0,0 @@ -################################################################################ -# 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::emc::DataDomain::mode::nvrambattery; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %conditions = ( - 1 => ['ok', 'OK'], - 2 => ['disabled', 'OK'], - 3 => ['discharged', 'WARNING'], - 4 => ['unknown', 'UNKNOWN'], - 5 => ['soft disabled', 'OK'], -); - -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 => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning (5sec) threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical (5sec) threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $oid_nvramBatteryEntry = '.1.3.6.1.4.1.19746.1.2.3.1.1'; - my $oid_nvramBatteryStatus = '.1.3.6.1.4.1.19746.1.2.3.1.1.2'; - my $oid_nvramBatteryCharge = '.1.3.6.1.4.1.19746.1.2.3.1.1.3'; - my $result = $self->{snmp}->get_table(oid => $oid_nvramBatteryEntry, nothing_quit => 1); - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All nvram batteries are ok.'); - - foreach my $oid (keys %$result) { - next if ($oid !~ /^$oid_nvramBatteryStatus/); - $oid =~ /\.([0-9]+)$/; - my $instance = $1; - - my $status = $result->{$oid_nvramBatteryStatus . '.' . $instance}; - my $charge = $result->{$oid_nvramBatteryCharge . '.' . $instance}; - - $self->{output}->output_add(long_msg => sprintf("nvram battery '%s' status is %s.", - $instance, ${$conditions{$status}}[0])); - if (!$self->{output}->is_status(litteral => 1, value => ${$conditions{$status}}[1], compare => 'ok')) { - $self->{output}->output_add(severity => ${$conditions{$status}}[1], - short_msg => sprintf("nvram battery '%s' status is %s", $instance, ${$conditions{$status}}[0])); - } - - # Check only if ok - if ($status == 1) { - my $exit = $self->{perfdata}->threshold_check(value => $charge, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(long_msg => sprintf("nvram battery '%s' charge is %s %%", $instance, - $charge)); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("nvram battery '%s' charge is %s %%", $instance, - $charge)); - } - - $self->{output}->perfdata_add(label => 'nvram_battery_' . $instance, unit => '%', - value => $charge, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check nvram Batteries status and charge percentage (DATA-DOMAIN-MIB). - -=over 8 - -=item B<--warning> - -Threshold warning in percent (for charge). - -=item B<--critical> - -Threshold critical in percent (for charge). - -=back - -=cut - \ No newline at end of file diff --git a/storage/emc/DataDomain/plugin.pm b/storage/emc/DataDomain/plugin.pm index 857a969f0..751357415 100644 --- a/storage/emc/DataDomain/plugin.pm +++ b/storage/emc/DataDomain/plugin.pm @@ -47,8 +47,8 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'environment' => 'storage::emc::DataDomain::mode::environment', - 'nvram-battery' => 'storage::emc::DataDomain::mode::nvrambattery', + 'hardware' => 'storage::emc::DataDomain::mode::hardware', + 'filesystem-usage' => 'storage::emc::DataDomain::mode::filesystem', ); return $self; diff --git a/storage/violin/3000/snmp/plugin.pm b/storage/violin/3000/snmp/plugin.pm index d34546ed0..4051f4a9f 100644 --- a/storage/violin/3000/snmp/plugin.pm +++ b/storage/violin/3000/snmp/plugin.pm @@ -60,5 +60,6 @@ __END__ =head1 PLUGIN DESCRIPTION Check Violin 3000 series in SNMP. +Please use plugin SNMP Linux for system checks ('cpu', 'memory', 'traffic',...). =cut From f0607ebe0977fc52a541bdfbb258ab632e3bd22f Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Tue, 9 Dec 2014 19:31:52 +0100 Subject: [PATCH 06/14] Fix #6024 --- centreon/plugins/options.pm | 10 ++++++++++ centreon/plugins/script_custom.pm | 16 ++++++++++++++-- centreon/plugins/script_simple.pm | 17 +++++++++++++---- centreon/plugins/script_snmp.pm | 8 ++++++++ centreon/plugins/script_sql.pm | 20 ++++++++++++++------ centreon/plugins/script_wsman.pm | 21 +++++++++++++++------ 6 files changed, 74 insertions(+), 18 deletions(-) diff --git a/centreon/plugins/options.pm b/centreon/plugins/options.pm index 531100cea..27e85c538 100644 --- a/centreon/plugins/options.pm +++ b/centreon/plugins/options.pm @@ -56,6 +56,16 @@ sub new { return $self; } +sub set_sanity { + my ($self, %options) = @_; + + Getopt::Long::Configure('no_pass_through'); + $SIG{__WARN__} = sub { + $self->{output}->add_option_msg(short_msg => $_[0]); + $self->{output}->option_exit(nolabel => 1); + }; +} + sub set_output { my ($self, %options) = @_; diff --git a/centreon/plugins/script_custom.pm b/centreon/plugins/script_custom.pm index d4537427c..a8bd0eca9 100644 --- a/centreon/plugins/script_custom.pm +++ b/centreon/plugins/script_custom.pm @@ -57,6 +57,7 @@ sub new { 'custommode:s' => { name => 'custommode_name' }, 'list-custommode' => { name => 'list_custommode' }, 'multiple' => { name => 'multiple' }, + 'sanity-options' => { name => 'sanity_options' }, } ); $self->{version} = '1.0'; @@ -98,6 +99,9 @@ sub init { if (defined($self->{list_custommode})) { $self->list_custommode(); } + if (defined($self->{sanity_options})) { + $self->{options}->set_sanity(); + } # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -250,17 +254,25 @@ __END__ Choose a mode. +=item B<--dyn-mode> + +Specify a mode with the path (separated by '::'). + =item B<--list-mode> List available modes. +=item B<--mode-version> + +Check minimal version of mode. If not, unknown error. + =item B<--version> Display plugin version. -=item B<--dyn-mode> +=item B<--sanity-options> -Specify a mode with the path (separated by '::'). +Check unknown options (for debug purpose). =item B<--custommode> diff --git a/centreon/plugins/script_simple.pm b/centreon/plugins/script_simple.pm index 8fe717cb7..35ebbc39a 100644 --- a/centreon/plugins/script_simple.pm +++ b/centreon/plugins/script_simple.pm @@ -50,10 +50,11 @@ sub new { $self->{options}->add_options( arguments => { - 'mode:s' => { name => 'mode' }, + 'mode:s' => { name => 'mode_name' }, 'dyn-mode:s' => { name => 'dynmode_name' }, 'list-mode' => { name => 'list_mode' }, 'mode-version:s' => { name => 'mode_version' }, + 'sanity-options' => { name => 'sanity_options' }, } ); $self->{version} = '1.0'; @@ -61,9 +62,10 @@ sub new { $self->{default} = undef; $self->{options}->parse_options(); - $self->{mode_name} = $self->{options}->get_option(argument => 'mode'); - $self->{list_mode} = $self->{options}->get_option(argument => 'list_mode'); - $self->{mode_version} = $self->{options}->get_option(argument => 'mode_version'); + $self->{option_results} = $self->{options}->get_options(); + foreach (keys %{$self->{option_results}}) { + $self->{$_} = $self->{option_results}->{$_}; + } $self->{options}->clean(); $self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION'); @@ -87,6 +89,9 @@ sub init { if (defined($self->{list_mode})) { $self->list_mode(); } + if (defined($self->{sanity_options})) { + $self->{options}->set_sanity(); + } # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -210,6 +215,10 @@ Check minimal version of mode. If not, unknown error. Display plugin version. +=item B<--sanity-options> + +Check unknown options (for debug purpose). + =back =head1 DESCRIPTION diff --git a/centreon/plugins/script_snmp.pm b/centreon/plugins/script_snmp.pm index 273e2aad3..af66c0bfc 100644 --- a/centreon/plugins/script_snmp.pm +++ b/centreon/plugins/script_snmp.pm @@ -56,6 +56,7 @@ sub new { 'dyn-mode:s' => { name => 'dynmode_name' }, 'list-mode' => { name => 'list_mode' }, 'mode-version:s' => { name => 'mode_version' }, + 'sanity-options' => { name => 'sanity_options' }, } ); $self->{version} = '1.0'; @@ -90,6 +91,9 @@ sub init { if (defined($self->{list_mode})) { $self->list_mode(); } + if (defined($self->{sanity_options})) { + $self->{options}->set_sanity(); + } # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -219,6 +223,10 @@ Check minimal version of mode. If not, unknown error. Display plugin version. +=item B<--sanity-options> + +Check unknown options (for debug purpose). + =back =head1 DESCRIPTION diff --git a/centreon/plugins/script_sql.pm b/centreon/plugins/script_sql.pm index c8be98bef..ecf7e9c4a 100644 --- a/centreon/plugins/script_sql.pm +++ b/centreon/plugins/script_sql.pm @@ -58,6 +58,7 @@ sub new { 'sqlmode:s' => { name => 'sqlmode_name', default => 'dbi' }, 'list-sqlmode' => { name => 'list_sqlmode' }, 'multiple' => { name => 'multiple' }, + 'sanity-options' => { name => 'sanity_options' }, } ); $self->{version} = '1.0'; @@ -99,6 +100,9 @@ sub init { if (defined($self->{list_sqlmode})) { $self->list_sqlmode(); } + if (defined($self->{sanity_options})) { + $self->{options}->set_sanity(); + } # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -256,21 +260,25 @@ __END__ Choose a mode. +=item B<--dyn-mode> + +Specify a mode with the path (separated by '::'). + =item B<--list-mode> List available modes. -=item B<--version> - -Display plugin version. - =item B<--mode-version> Check minimal version of mode. If not, unknown error. -=item B<--dyn-mode> +=item B<--version> -Specify a mode with the path (separated by '::'). +Display plugin version. + +=item B<--sanity-options> + +Check unknown options (for debug purpose). =item B<--sqlmode> diff --git a/centreon/plugins/script_wsman.pm b/centreon/plugins/script_wsman.pm index 651c9485e..4cb6ae015 100644 --- a/centreon/plugins/script_wsman.pm +++ b/centreon/plugins/script_wsman.pm @@ -52,10 +52,11 @@ sub new { $self->{options}->add_options( arguments => { - 'mode:s' => { name => 'mode' }, + 'mode:s' => { name => 'mode_name' }, 'dyn-mode:s' => { name => 'dynmode_name' }, 'list-mode' => { name => 'list_mode' }, 'mode-version:s' => { name => 'mode_version' }, + 'sanity-options' => { name => 'sanity_options' }, } ); $self->{version} = '1.0'; @@ -63,9 +64,10 @@ sub new { $self->{default} = undef; $self->{options}->parse_options(); - $self->{mode_name} = $self->{options}->get_option(argument => 'mode'); - $self->{list_mode} = $self->{options}->get_option(argument => 'list_mode'); - $self->{mode_version} = $self->{options}->get_option(argument => 'mode_version'); + $self->{option_results} = $self->{options}->get_options(); + foreach (keys %{$self->{option_results}}) { + $self->{$_} = $self->{option_results}->{$_}; + } $self->{options}->clean(); $self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION'); @@ -89,6 +91,9 @@ sub init { if (defined($self->{list_mode})) { $self->list_mode(); } + if (defined($self->{sanity_options})) { + $self->{options}->set_sanity(); + } # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -206,13 +211,17 @@ Specify a mode with the path (separated by '::'). List available modes. +=item B<--mode-version> + +Check minimal version of mode. If not, unknown error. + =item B<--version> Display plugin version. -=item B<--mode-version> +=item B<--sanity-options> -Check minimal version of mode. If not, unknown error. +Check unknown options (for debug purpose). =back From 2338454c200e81125bbe2c80f67747993ddf7d3a Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Wed, 10 Dec 2014 18:27:29 +0100 Subject: [PATCH 07/14] Fix #6027 --- .../common/violin/snmp/mode/components/ca.pm | 6 + .../common/violin/snmp/mode/components/fan.pm | 6 + .../common/violin/snmp/mode/components/gfc.pm | 6 + .../common/violin/snmp/mode/components/lfc.pm | 6 + .../common/violin/snmp/mode/components/psu.pm | 7 + .../snmp/mode/components/temperature.pm | 8 + .../violin/snmp/mode/components/vimm.pm | 7 + centreon/common/violin/snmp/mode/hardware.pm | 82 ++--- centreon/plugins/snmp.pm | 25 ++ .../sensorip/snmp/mode/components/humidity.pm | 132 ++++++++ .../sensorip/snmp/mode/components/sp.pm | 81 +++++ .../sensorip/snmp/mode/components/switch.pm | 97 ++++++ .../snmp/mode/components/temperature.pm | 131 +++++++ .../sensors/sensorip/snmp/mode/sensors.pm | 319 ++++++++++++++++++ hardware/sensors/sensorip/snmp/plugin.pm | 64 ++++ .../emc/DataDomain/mode/components/disk.pm | 2 + storage/emc/DataDomain/mode/hardware.pm | 2 + 17 files changed, 924 insertions(+), 57 deletions(-) create mode 100644 hardware/sensors/sensorip/snmp/mode/components/humidity.pm create mode 100644 hardware/sensors/sensorip/snmp/mode/components/sp.pm create mode 100644 hardware/sensors/sensorip/snmp/mode/components/switch.pm create mode 100644 hardware/sensors/sensorip/snmp/mode/components/temperature.pm create mode 100644 hardware/sensors/sensorip/snmp/mode/sensors.pm create mode 100644 hardware/sensors/sensorip/snmp/plugin.pm diff --git a/centreon/common/violin/snmp/mode/components/ca.pm b/centreon/common/violin/snmp/mode/components/ca.pm index 9427e3a9a..10b89491f 100644 --- a/centreon/common/violin/snmp/mode/components/ca.pm +++ b/centreon/common/violin/snmp/mode/components/ca.pm @@ -42,6 +42,12 @@ use warnings; my $oid_chassisSystemLedAlarm = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.7'; +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_chassisSystemLedAlarm }; +} + sub check { my ($self) = @_; diff --git a/centreon/common/violin/snmp/mode/components/fan.pm b/centreon/common/violin/snmp/mode/components/fan.pm index eab65d2bd..96ae18dcc 100644 --- a/centreon/common/violin/snmp/mode/components/fan.pm +++ b/centreon/common/violin/snmp/mode/components/fan.pm @@ -42,6 +42,12 @@ use warnings; my $oid_arrayFanEntry_speed = '.1.3.6.1.4.1.35897.1.2.2.3.18.1.3'; +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_arrayFanEntry_speed }; +} + sub check { my ($self) = @_; diff --git a/centreon/common/violin/snmp/mode/components/gfc.pm b/centreon/common/violin/snmp/mode/components/gfc.pm index 85977fc1f..ed32cbbab 100644 --- a/centreon/common/violin/snmp/mode/components/gfc.pm +++ b/centreon/common/violin/snmp/mode/components/gfc.pm @@ -45,6 +45,12 @@ my $oid_wwn = '.1.3.6.1.4.1.35897.1.2.1.10.1.3'; my $oid_enable = '.1.3.6.1.4.1.35897.1.2.1.10.1.4'; my $oid_portState = '.1.3.6.1.4.1.35897.1.2.1.10.1.8'; +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_globalTargetFcEntry }; +} + sub check { my ($self) = @_; diff --git a/centreon/common/violin/snmp/mode/components/lfc.pm b/centreon/common/violin/snmp/mode/components/lfc.pm index bb0ea17d8..d1c71abd2 100644 --- a/centreon/common/violin/snmp/mode/components/lfc.pm +++ b/centreon/common/violin/snmp/mode/components/lfc.pm @@ -45,6 +45,12 @@ my $oid_wwn = '.1.3.6.1.4.1.35897.1.2.1.6.1.2'; my $oid_enable = '.1.3.6.1.4.1.35897.1.2.1.6.1.3'; my $oid_portState = '.1.3.6.1.4.1.35897.1.2.1.6.1.7'; +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_localTargetFcEntry }; +} + sub check { my ($self) = @_; diff --git a/centreon/common/violin/snmp/mode/components/psu.pm b/centreon/common/violin/snmp/mode/components/psu.pm index 4fb591c03..8a0b6a4c2 100644 --- a/centreon/common/violin/snmp/mode/components/psu.pm +++ b/centreon/common/violin/snmp/mode/components/psu.pm @@ -43,6 +43,13 @@ use warnings; my $oid_chassisSystemPowerPSUA = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.17'; my $oid_chassisSystemPowerPSUB = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.18'; +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_chassisSystemPowerPSUA }; + push @{$options{request}}, { oid => $oid_chassisSystemPowerPSUB }; +} + sub psu { my ($self, %options) = @_; my $oid = $options{oid}; diff --git a/centreon/common/violin/snmp/mode/components/temperature.pm b/centreon/common/violin/snmp/mode/components/temperature.pm index a4d6dcef1..4fbc4d79d 100644 --- a/centreon/common/violin/snmp/mode/components/temperature.pm +++ b/centreon/common/violin/snmp/mode/components/temperature.pm @@ -44,6 +44,14 @@ my $oid_chassisSystemTempAmbient = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21'; my $oid_chassisSystemTempController = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21'; my $oid_arrayVimmEntry_temp = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.12'; +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_arrayVimmEntry_temp }; + push @{$options{request}}, { oid => $oid_chassisSystemTempAmbient }; + push @{$options{request}}, { oid => $oid_chassisSystemTempController }; +} + sub temperature { my ($self, %options) = @_; my $oid = $options{oid}; diff --git a/centreon/common/violin/snmp/mode/components/vimm.pm b/centreon/common/violin/snmp/mode/components/vimm.pm index d5d4339f3..8f4348fc0 100644 --- a/centreon/common/violin/snmp/mode/components/vimm.pm +++ b/centreon/common/violin/snmp/mode/components/vimm.pm @@ -53,6 +53,13 @@ my %map_vimm_present = ( 2 => 'absent', ); +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_arrayVimmEntry_present }; + push @{$options{request}}, { oid => $oid_arrayVimmEntry_failed }; +} + sub check { my ($self) = @_; diff --git a/centreon/common/violin/snmp/mode/hardware.pm b/centreon/common/violin/snmp/mode/hardware.pm index 2d182f5e5..da1c67a63 100644 --- a/centreon/common/violin/snmp/mode/hardware.pm +++ b/centreon/common/violin/snmp/mode/hardware.pm @@ -39,25 +39,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::common::violin::snmp::mode::components::ca; -use centreon::common::violin::snmp::mode::components::psu; -use centreon::common::violin::snmp::mode::components::fan; -use centreon::common::violin::snmp::mode::components::vimm; -use centreon::common::violin::snmp::mode::components::temperature; -use centreon::common::violin::snmp::mode::components::lfc; -use centreon::common::violin::snmp::mode::components::gfc; - -my $oid_chassisSystemLedAlarm = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.7'; -my $oid_chassisSystemPowerPSUA = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.17'; -my $oid_chassisSystemPowerPSUB = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.18'; -my $oid_chassisSystemTempAmbient = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21'; -my $oid_chassisSystemTempController = '.1.3.6.1.4.1.35897.1.2.2.3.17.1.21'; -my $oid_arrayFanEntry_speed = '.1.3.6.1.4.1.35897.1.2.2.3.18.1.3'; -my $oid_arrayVimmEntry_present = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.4'; -my $oid_arrayVimmEntry_failed = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.10'; -my $oid_arrayVimmEntry_temp = '.1.3.6.1.4.1.35897.1.2.2.3.16.1.12'; -my $oid_globalTargetFcEntry = '.1.3.6.1.4.1.35897.1.2.1.10.1'; -my $oid_localTargetFcEntry = '.1.3.6.1.4.1.35897.1.2.1.6.1'; +use centreon::plugins::misc; my $thresholds = { vimm => [ @@ -111,7 +93,7 @@ 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' }, @@ -178,46 +160,32 @@ sub run { # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_arrayFanEntry_speed }, - { oid => $oid_arrayVimmEntry_present }, - { oid => $oid_arrayVimmEntry_failed }, - { oid => $oid_arrayVimmEntry_temp }, - { oid => $oid_globalTargetFcEntry }, - { oid => $oid_localTargetFcEntry }, - { oid => $oid_chassisSystemLedAlarm }, - { oid => $oid_chassisSystemPowerPSUA }, - { oid => $oid_chassisSystemPowerPSUB }, - { oid => $oid_chassisSystemTempAmbient }, - { oid => $oid_chassisSystemTempController }, - ]); - if ($self->{option_results}->{component} eq 'all') { - centreon::common::violin::snmp::mode::components::ca::check($self); - centreon::common::violin::snmp::mode::components::psu::check($self); - centreon::common::violin::snmp::mode::components::fan::check($self); - centreon::common::violin::snmp::mode::components::vimm::check($self); - centreon::common::violin::snmp::mode::components::temperature::check($self); - centreon::common::violin::snmp::mode::components::gfc::check($self); - centreon::common::violin::snmp::mode::components::lfc::check($self); - } elsif ($self->{option_results}->{component} eq 'fan') { - centreon::common::violin::snmp::mode::components::fan::check($self); - } elsif ($self->{option_results}->{component} eq 'psu') { - centreon::common::violin::snmp::mode::components::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'vimm') { - centreon::common::violin::snmp::mode::components::vimm::check($self); - } elsif ($self->{option_results}->{component} eq 'temperature') { - centreon::common::violin::snmp::mode::components::psu::check($self); - } elsif ($self->{option_results}->{component} eq 'ca') { - centreon::common::violin::snmp::mode::components::ca::check($self); - } elsif ($self->{option_results}->{component} eq 'gfc') { - centreon::common::violin::snmp::mode::components::gfc::check($self); - } elsif ($self->{option_results}->{component} eq 'lfc') { - centreon::common::violin::snmp::mode::components::lfc::check($self); - } else { + my $snmp_request = []; + my @components = ('ca', 'psu', 'fan', 'vimm', 'temperature', 'gfc', 'lfc'); + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "centreon::common::violin::snmp::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); + } + } + + 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(); } + $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "centreon::common::violin::snmp::mode::components::$_"; + my $func = $mod_name->can('check'); + $func->($self); + } + } + my $total_components = 0; my $display_by_component = ''; my $display_by_component_append = ''; @@ -350,7 +318,7 @@ Check components (Fans, Power Supplies, Temperatures, Chassis alarm, vimm, globa =item B<--component> -Which component to check (Default: 'all'). +Which component to check (Default: '.*'). Can be: 'psu', 'fan', 'ca', 'vimm', 'lfc', 'gfc', 'temperature'. =item B<--exclude> diff --git a/centreon/plugins/snmp.pm b/centreon/plugins/snmp.pm index 49b84a0f8..268cd4d23 100644 --- a/centreon/plugins/snmp.pm +++ b/centreon/plugins/snmp.pm @@ -765,6 +765,31 @@ sub get_port { return $self->{snmp_params}->{RemotePort}; } +sub map_instance { + my ($self, %options) = @_; + + my $results = {}; + foreach my $name (keys %{$options{mapping}}) { + my $entry = $options{mapping}->{$name}->{oid} . '.' . $options{instance}; + if (defined($options{results}->{$entry})) { + $results->{$name} = $options{results}->{$entry}; + } elsif (defined($options{results}->{$options{mapping}->{$name}->{oid}}->{$entry})) { + $results->{$name} = $options{results}->{$options{mapping}->{$name}->{oid}}->{$entry}; + } elsif (defined($options{mapping}->{$name}->{location}) && + defined($options{results}->{$options{mapping}->{$name}->{location}}->{$entry})) { + $results->{$name} = $options{results}->{$options{mapping}->{$name}->{location}}->{$entry}; + } else { + $results->{$name} = defined($options{default}) ? $options{default} : undef; + } + + if (defined($options{mapping}->{$name}->{map})) { + $results->{$name} = defined($options{mapping}->{$name}->{map}->{$results->{$name}}) ? $options{mapping}->{$name}->{map}->{$results->{$name}} : (defined($options{default}) ? $options{default} : 'unknown'); + } + } + + return $results; +} + sub oid_lex_sort { my $self = shift; diff --git a/hardware/sensors/sensorip/snmp/mode/components/humidity.pm b/hardware/sensors/sensorip/snmp/mode/components/humidity.pm new file mode 100644 index 000000000..ab4a4f73e --- /dev/null +++ b/hardware/sensors/sensorip/snmp/mode/components/humidity.pm @@ -0,0 +1,132 @@ +################################################################################ +# 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 hardware::sensors::sensorip::snmp::mode::components::humidity; + +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 = { + sensorProbeHumidityDescription => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.1' }, + sensorProbeHumidityPercent => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.3' }, + sensorProbeHumidityStatus => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.4', map => \%map_hum_status }, + sensorProbeHumidityOnline => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.5', map => \%map_hum_online }, + sensorProbeHumidityHighWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.7' }, + sensorProbeHumidityHighCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.8' }, + sensorProbeHumidityLowWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.9' }, + sensorProbeHumidityLowCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.17.1.10' }, +}; +my $oid_sensorProbeHumidityEntry = '.1.3.6.1.4.1.3854.1.2.2.1.17.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_sensorProbeHumidityEntry, end => $mapping->{sensorProbeHumidityLowCritical}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking humidity"); + $self->{components}->{humidity} = {name => 'humidity', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'humidity')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeHumidityEntry}})) { + next if ($oid !~ /^$mapping->{sensorProbeHumidityPercent}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeHumidityEntry}, instance => $instance); + + next if ($self->check_exclude(section => 'humidity', instance => $instance)); + if ($result->{sensorProbeHumidityOnline} =~ /Offline/i) { + $self->absent_problem(section => 'humidity', instance => $instance); + next; + } + + $self->{components}->{humidity}->{total}++; + if ($result->{sensorProbeHumidityStatus} =~ /sensorError/i) { + my $exit = $self->get_severity(section => 'humidity', value => $result->{sensorProbeHumidityStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Humidity sensor '%s' status is '%s'", $result->{sensorProbeHumidityDescription}, $result->{sensorProbeTempStatus})); + next; + } + } + + $self->{output}->output_add(long_msg => sprintf("Humidity sensor '%s' status is '%s' [instance = %s, value = %s %%]", + $result->{sensorProbeHumidityDescription}, $result->{sensorProbeHumidityStatus}, $instance, $result->{sensorProbeHumidityPercent})); + + if (defined($result->{sensorProbeHumidityPercent}) && $result->{sensorProbeHumidityPercent} =~ /[0-9]/) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{sensorProbeHumidityPercent}); + if ($checked == 0) { + my $warn_th = $result->{sensorProbeHumidityLowWarning} . ':' . $result->{sensorProbeHumidityHighWarning}; + my $crit_th = $result->{sensorProbeHumidityLowCritical} . ':' . $result->{sensorProbeHumidityHighCritical}; + $self->{perfdata}->threshold_validate(label => 'warning-humidity-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-humidity-instance-' . $instance, value => $crit_th); + + $exit = $self->{perfdata}->threshold_check(value => $result->{sensorProbeHumidityPercent}, threshold => [ { label => 'critical-humidity-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-humidity-instance-' . $instance, exit_litteral => 'warning' } ]); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-humidity-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-humidity-instance-' . $instance) + } + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Humidity sensor '%s' is %s %%", $result->{sensorProbeHumidityDescription}, $result->{sensorProbeHumidityPercent})); + } + $self->{output}->perfdata_add(label => 'humdity_' . $instance, unit => '%', + value => $result->{sensorProbeHumidityPercent}, + warning => $warn, + critical => $crit, + min => 0, max => 100 + ); + } + } +} + +1; \ No newline at end of file diff --git a/hardware/sensors/sensorip/snmp/mode/components/sp.pm b/hardware/sensors/sensorip/snmp/mode/components/sp.pm new file mode 100644 index 000000000..efbb2335b --- /dev/null +++ b/hardware/sensors/sensorip/snmp/mode/components/sp.pm @@ -0,0 +1,81 @@ +################################################################################ +# 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 hardware::sensors::sensorip::snmp::mode::components::sp; + +use strict; +use warnings; + +my %map_sp_status = ( + 1 => 'noStatus', + 2 => 'normal', + 3 => 'warning', + 4 => 'critical', + 5 => 'sensorError', +); +my $oid_spStatus = '.1.3.6.1.4.1.3854.1.1.2'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_spStatus }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking sp"); + $self->{components}->{sp} = {name => 'sp', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'sp')); + + my $instance = 0; + my $sp_status = defined($map_sp_status{$self->{results}->{$oid_spStatus}->{$oid_spStatus . '.' . $instance}}) ? + $map_sp_status{$self->{results}->{$oid_spStatus}->{$oid_spStatus . '.' . $instance}} : 'unknown'; + + return if ($self->check_exclude(section => 'sp', instance => $instance)); + return if ($sp_status =~ /noStatus/i && + $self->absent_problem(section => 'sp', instance => $instance)); + + $self->{components}->{sp}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Sensor probe '%s' status is '%s'", + $instance, $sp_status)); + my $exit = $self->get_severity(section => 'sp', value => $sp_status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sensor probe '%s' status is '%s'", $instance, $sp_status)); + } +} + +1; \ No newline at end of file diff --git a/hardware/sensors/sensorip/snmp/mode/components/switch.pm b/hardware/sensors/sensorip/snmp/mode/components/switch.pm new file mode 100644 index 000000000..9831649d9 --- /dev/null +++ b/hardware/sensors/sensorip/snmp/mode/components/switch.pm @@ -0,0 +1,97 @@ +################################################################################ +# 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 hardware::sensors::sensorip::snmp::mode::components::switch; + +use strict; +use warnings; + +my %map_sw_status = ( + 1 => 'noStatus', + 2 => 'normal', + 4 => 'highCritical', + 6 => 'lowCritical', + 7 => 'sensorError', + 8 => 'relayOn', + 9 => 'relayOff', +); +my %map_sw_online = ( + 1 => 'online', + 2 => 'offline', +); + +my $mapping = { + sensorProbeSwitchDescription => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.18.1.1' }, + sensorProbeSwitchStatus => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.18.1.3', map => \%map_sw_status }, + sensorProbeSwitchOnline => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.18.1.4', map => \%map_sw_online }, +}; +my $oid_sensorProbeSwitchEntry = '.1.3.6.1.4.1.3854.1.2.2.1.18.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_sensorProbeSwitchEntry, end => $mapping->{sensorProbeSwitchOnline}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking switch"); + $self->{components}->{switch} = {name => 'switch', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'switch')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeSwitchEntry}})) { + next if ($oid !~ /^$mapping->{sensorProbeSwitchStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeSwitchEntry}, instance => $instance); + + next if ($self->check_exclude(section => 'switch', instance => $instance)); + if ($result->{sensorProbeSwitchOnline} =~ /Offline/i) { + $self->absent_problem(section => 'switch', instance => $instance); + next; + } + + $self->{components}->{switch}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Switch sensor '%s' status is '%s' [instance : %s]", + $result->{sensorProbeSwitchDescription}, $result->{sensorProbeSwitchStatus}, $instance)); + my $exit = $self->get_severity(section => 'switch', value => $result->{sensorProbeSwitchStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Switch sensor '%s' status is '%s'", $result->{sensorProbeSwitchDescription}, $result->{sensorProbeSwitchStatus})); + } + } +} + +1; \ No newline at end of file diff --git a/hardware/sensors/sensorip/snmp/mode/components/temperature.pm b/hardware/sensors/sensorip/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..49c02c4b6 --- /dev/null +++ b/hardware/sensors/sensorip/snmp/mode/components/temperature.pm @@ -0,0 +1,131 @@ +################################################################################ +# 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 hardware::sensors::sensorip::snmp::mode::components::temperature; + +use strict; +use warnings; + +my %map_temp_status = ( + 1 => 'noStatus', + 2 => 'normal', + 3 => 'highWarning', + 4 => 'highCritical', + 5 => 'lowWarning', + 6 => 'lowCritical', + 7 => 'sensorError', +); +my %map_temp_online = ( + 1 => 'online', + 2 => 'offline', +); + +my $mapping = { + sensorProbeTempDescription => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.1' }, + sensorProbeTempDegree => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.3' }, + sensorProbeTempStatus => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.4', map => \%map_temp_status }, + sensorProbeTempOnline => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.5', map => \%map_temp_online }, + sensorProbeTempHighWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.7' }, + sensorProbeTempHighCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.8' }, + sensorProbeTempLowWarning => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.9' }, + sensorProbeTempLowCritical => { oid => '.1.3.6.1.4.1.3854.1.2.2.1.16.1.10' }, +}; +my $oid_sensorProbeTempEntry = '.1.3.6.1.4.1.3854.1.2.2.1.16.1'; + +sub load { + my (%options) = @_; + + push @{$options{request}}, { oid => $oid_sensorProbeTempEntry, end => $mapping->{sensorProbeTempLowCritical}->{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')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sensorProbeTempEntry}})) { + next if ($oid !~ /^$mapping->{sensorProbeTempDegree}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sensorProbeTempEntry}, instance => $instance); + + next if ($self->check_exclude(section => 'temperature', instance => $instance)); + if ($result->{sensorProbeTempOnline} =~ /Offline/i) { + $self->absent_problem(section => 'temperature', instance => $instance); + next; + } + + $self->{components}->{temperature}->{total}++; + if ($result->{sensorProbeTempStatus} =~ /sensorError/i) { + my $exit = $self->get_severity(section => 'temperature', value => $result->{sensorProbeTempStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature sensor '%s' status is '%s'", $result->{sensorProbeTempDescription}, $result->{sensorProbeTempStatus})); + next; + } + } + + $self->{output}->output_add(long_msg => sprintf("Temperature sensor '%s' status is '%s' [instance = %s, value = %s]", + $result->{sensorProbeTempDescription}, $result->{sensorProbeTempStatus}, $instance, $result->{sensorProbeTempDegree})); + + if (defined($result->{sensorProbeTempDegree}) && $result->{sensorProbeTempDegree} =~ /[0-9]/) { + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{sensorProbeTempDegree}); + if ($checked == 0) { + my $warn_th = $result->{sensorProbeTempLowWarning} . ':' . $result->{sensorProbeTempHighWarning}; + my $crit_th = $result->{sensorProbeTempLowCritical} . ':' . $result->{sensorProbeTempHighCritical}; + $self->{perfdata}->threshold_validate(label => 'warning-temperature-instance-' . $instance, value => $warn_th); + $self->{perfdata}->threshold_validate(label => 'critical-temperature-instance-' . $instance, value => $crit_th); + + $exit = $self->{perfdata}->threshold_check(value => $result->{sensorProbeTempDegree}, threshold => [ { label => 'critical-temperature-instance-' . $instance, exit_litteral => 'critical' }, + { label => 'warning-temperature-instance-' . $instance, exit_litteral => 'warning' } ]); + $warn = $self->{perfdata}->get_perfdata_for_output(label => 'warning-temperature-instance-' . $instance); + $crit = $self->{perfdata}->get_perfdata_for_output(label => 'critical-temperature-instance-' . $instance) + } + + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature sensor '%s' is %s degree centigrade", $result->{sensorProbeTempDescription}, $result->{sensorProbeTempDegree})); + } + $self->{output}->perfdata_add(label => 'temp_' . $instance, unit => 'C', + value => $result->{sensorProbeTempDegree}, + warning => $warn, + critical => $crit, + ); + } + } +} + +1; \ No newline at end of file diff --git a/hardware/sensors/sensorip/snmp/mode/sensors.pm b/hardware/sensors/sensorip/snmp/mode/sensors.pm new file mode 100644 index 000000000..7f3ba75e6 --- /dev/null +++ b/hardware/sensors/sensorip/snmp/mode/sensors.pm @@ -0,0 +1,319 @@ +################################################################################ +# 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 hardware::sensors::sensorip::snmp::mode::sensors; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; + +my $thresholds = { + sp => [ + ['noStatus', 'UNKNOWN'], + ['normal', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ['sensorError', 'CRITICAL'], + ], + switch => [ + ['noStatus', 'UNKNOWN'], + ['normal', 'OK'], + ['highCritical', 'CRITICAL'], + ['lowCritical', 'CRITICAL'], + ['sensorError', 'CRITICAL'], + ['relayOn', 'OK'], + ['relayOff', 'OK'], + ], +}; + +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 => + { + "exclude:s" => { name => 'exclude' }, + "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; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (defined($self->{option_results}->{no_component})) { + if ($self->{option_results}->{no_component} ne '') { + $self->{no_components} = $self->{option_results}->{no_component}; + } else { + $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 !~ /(humidity|temperature)/) { + $self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "' (type must be: battery 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 { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my $snmp_request = []; + my @components = ('sp', 'temperature', 'humidity', 'switch'); + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "hardware::sensors::sensorip::snmp::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); + } + } + + 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(); + } + $self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request); + + foreach (@components) { + if (/$self->{option_results}->{component}/) { + my $mod_name = "hardware::sensors::sensorip::snmp::mode::components::$_"; + my $func = $mod_name->can('check'); + $func->($self); + } + } + + my $total_components = 0; + my $display_by_component = ''; + my $display_by_component_append = ''; + foreach my $comp (sort(keys %{$self->{components}})) { + # Skipping short msg when no components + next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); + $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; + $display_by_component_append = ', '; + } + + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("All %s components are ok [%s].", + $total_components, + $display_by_component) + ); + + if (defined($self->{option_results}->{no_component}) && $total_components == 0) { + $self->{output}->output_add(severity => $self->{no_components}, + short_msg => 'No components are checked.'); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +sub check_exclude { + my ($self, %options) = @_; + + if (defined($options{instance})) { + if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { + $self->{components}->{$options{section}}->{skip}++; + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); + return 1; + } + } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); + return 1; + } + return 0; +} + +sub absent_problem { + my ($self, %options) = @_; + + 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 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; + } + } + } + foreach (@{$thresholds->{$options{section}}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + + return $status; +} + +1; + +__END__ + +=head1 MODE + +Check sensor components (Sensor Probe status, Temperatures, Humidity, Switch). + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'sp', 'temperature', 'humidity', 'switch'. + +=item B<--exclude> + +Exclude some parts (comma seperated list) (Example: --exclude=psu) +Can also exclude specific instance: --exclude='humidty#0#' + +=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=temperature#2# + +=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='temperature,CRITICAL,^(?!(normal)$)' + +=item B<--warning> + +Set warning threshold for temperatures and humidity (syntax: type,regexp,treshold) +Example: --warning='temperature,.*,30' --warning='humidity,.*,90' + +=item B<--critical> + +Set critical threshold for temperature and humidity (syntax: type,regexp,treshold) +Example: --critical='temperature,.*,40' + +=back + +=cut + diff --git a/hardware/sensors/sensorip/snmp/plugin.pm b/hardware/sensors/sensorip/snmp/plugin.pm new file mode 100644 index 000000000..c3d3d03be --- /dev/null +++ b/hardware/sensors/sensorip/snmp/plugin.pm @@ -0,0 +1,64 @@ +################################################################################ +# 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 hardware::sensors::sensorip::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; + # $options->{options} = options object + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'sensors' => 'hardware::sensors::sensorip::snmp::mode::sensors', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Sensor-IP sensors in SNMP. + +=cut diff --git a/storage/emc/DataDomain/mode/components/disk.pm b/storage/emc/DataDomain/mode/components/disk.pm index ff45efbbf..8da978b36 100644 --- a/storage/emc/DataDomain/mode/components/disk.pm +++ b/storage/emc/DataDomain/mode/components/disk.pm @@ -46,6 +46,8 @@ my %map_disk_status = ( 2 => 'unknown', 3 => 'absent', 4 => 'failed', + 5 => 'spare', # since OS 5.4 + 6 => 'available', # since OS 5.4 ); sub check { diff --git a/storage/emc/DataDomain/mode/hardware.pm b/storage/emc/DataDomain/mode/hardware.pm index 97ed9b2af..f8c63c5b0 100644 --- a/storage/emc/DataDomain/mode/hardware.pm +++ b/storage/emc/DataDomain/mode/hardware.pm @@ -76,6 +76,8 @@ my $thresholds = { ], disk => [ ['ok', 'OK'], + ['spare', 'OK'], + ['available', 'OK'], ['unknown', 'UNKNOWN'], ['absent', 'OK'], ['failed', 'CRITICAL'], From a8f59c89c820f0153728d0c80f5235170ff81b59 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Fri, 12 Dec 2014 10:10:22 +0100 Subject: [PATCH 08/14] Some fix for clariion, datadomain and violin --- centreon/common/emc/navisphere/mode/hbastate.pm | 2 +- centreon/common/emc/navisphere/mode/portstate.pm | 6 ------ centreon/common/emc/navisphere/mode/sp.pm | 12 ++++++------ .../emc/navisphere/mode/spcomponents/battery.pm | 2 +- .../common/emc/navisphere/mode/spcomponents/cable.pm | 2 +- .../common/emc/navisphere/mode/spcomponents/cpu.pm | 2 +- .../common/emc/navisphere/mode/spcomponents/fan.pm | 2 +- .../emc/navisphere/mode/spcomponents/iomodule.pm | 2 +- .../common/emc/navisphere/mode/spcomponents/lcc.pm | 2 +- .../emc/navisphere/mode/spcomponents/memory.pm | 2 +- .../common/emc/navisphere/mode/spcomponents/psu.pm | 2 +- .../common/emc/navisphere/mode/spcomponents/sp.pm | 2 +- .../violin/snmp/mode/components/temperature.pm | 2 +- storage/emc/DataDomain/mode/components/disk.pm | 2 +- 14 files changed, 18 insertions(+), 24 deletions(-) diff --git a/centreon/common/emc/navisphere/mode/hbastate.pm b/centreon/common/emc/navisphere/mode/hbastate.pm index 76a213192..7cbd65077 100644 --- a/centreon/common/emc/navisphere/mode/hbastate.pm +++ b/centreon/common/emc/navisphere/mode/hbastate.pm @@ -194,7 +194,7 @@ Set hba uid to check (not set, means 'all'). Set how much path must be connected (Can be multiple). Syntax: [WARNING],[CRITICAL],filter_uid,filter_server -Example: ,,@0:1,.* - Means all server must have at least two paths connected. +Example: ,@0:1,.*,.* - Means all server must have at least two paths connected. =back diff --git a/centreon/common/emc/navisphere/mode/portstate.pm b/centreon/common/emc/navisphere/mode/portstate.pm index 56ad8471a..7cf96bb34 100644 --- a/centreon/common/emc/navisphere/mode/portstate.pm +++ b/centreon/common/emc/navisphere/mode/portstate.pm @@ -61,12 +61,6 @@ sub check_options { $self->SUPER::init(%options); } -sub check_logged { - my ($self, %options) = @_; - - -} - sub check_port { my ($self, %options) = @_; diff --git a/centreon/common/emc/navisphere/mode/sp.pm b/centreon/common/emc/navisphere/mode/sp.pm index 624046524..5edd9a4a7 100644 --- a/centreon/common/emc/navisphere/mode/sp.pm +++ b/centreon/common/emc/navisphere/mode/sp.pm @@ -42,12 +42,12 @@ use warnings; use centreon::common::emc::navisphere::mode::spcomponents::fan; use centreon::common::emc::navisphere::mode::spcomponents::lcc; use centreon::common::emc::navisphere::mode::spcomponents::psu; -use centreon::common::emc::navisphere::spcomponents::battery; -use centreon::common::emc::navisphere::spcomponents::memory; -use centreon::common::emc::navisphere::spcomponents::cpu; -use centreon::common::emc::navisphere::spcomponents::iomodule; -use centreon::common::emc::navisphere::spcomponents::cable; -use centreon::common::emc::navisphere::spcomponents::sp; +use centreon::common::emc::navisphere::mode::spcomponents::battery; +use centreon::common::emc::navisphere::mode::spcomponents::memory; +use centreon::common::emc::navisphere::mode::spcomponents::cpu; +use centreon::common::emc::navisphere::mode::spcomponents::iomodule; +use centreon::common::emc::navisphere::mode::spcomponents::cable; +use centreon::common::emc::navisphere::mode::spcomponents::sp; sub new { my ($class, %options) = @_; diff --git a/centreon/common/emc/navisphere/mode/spcomponents/battery.pm b/centreon/common/emc/navisphere/mode/spcomponents/battery.pm index 36c5987da..570a7aa42 100644 --- a/centreon/common/emc/navisphere/mode/spcomponents/battery.pm +++ b/centreon/common/emc/navisphere/mode/spcomponents/battery.pm @@ -33,7 +33,7 @@ # #################################################################################### -package storage::emc::clariion::mode::spcomponents::battery; +package centreon::common::emc::navisphere::mode::spcomponents::battery; use strict; use warnings; diff --git a/centreon/common/emc/navisphere/mode/spcomponents/cable.pm b/centreon/common/emc/navisphere/mode/spcomponents/cable.pm index f2de605e2..56d4fca34 100644 --- a/centreon/common/emc/navisphere/mode/spcomponents/cable.pm +++ b/centreon/common/emc/navisphere/mode/spcomponents/cable.pm @@ -33,7 +33,7 @@ # #################################################################################### -package storage::emc::clariion::mode::spcomponents::cable; +package centreon::common::emc::navisphere::mode::spcomponents::cable; use strict; use warnings; diff --git a/centreon/common/emc/navisphere/mode/spcomponents/cpu.pm b/centreon/common/emc/navisphere/mode/spcomponents/cpu.pm index 5f7a0a212..e867dbddd 100644 --- a/centreon/common/emc/navisphere/mode/spcomponents/cpu.pm +++ b/centreon/common/emc/navisphere/mode/spcomponents/cpu.pm @@ -33,7 +33,7 @@ # #################################################################################### -package storage::emc::clariion::mode::spcomponents::cpu; +package centreon::common::emc::navisphere::mode::spcomponents::cpu; use strict; use warnings; diff --git a/centreon/common/emc/navisphere/mode/spcomponents/fan.pm b/centreon/common/emc/navisphere/mode/spcomponents/fan.pm index 95f4dfcfc..9e6db5c7a 100644 --- a/centreon/common/emc/navisphere/mode/spcomponents/fan.pm +++ b/centreon/common/emc/navisphere/mode/spcomponents/fan.pm @@ -33,7 +33,7 @@ # #################################################################################### -package storage::emc::clariion::mode::spcomponents::fan; +package centreon::common::emc::navisphere::mode::spcomponents::fan; use strict; use warnings; diff --git a/centreon/common/emc/navisphere/mode/spcomponents/iomodule.pm b/centreon/common/emc/navisphere/mode/spcomponents/iomodule.pm index 0c823d01b..261b4a19d 100644 --- a/centreon/common/emc/navisphere/mode/spcomponents/iomodule.pm +++ b/centreon/common/emc/navisphere/mode/spcomponents/iomodule.pm @@ -33,7 +33,7 @@ # #################################################################################### -package storage::emc::clariion::mode::spcomponents::iomodule; +package centreon::common::emc::navisphere::mode::spcomponents::iomodule; use strict; use warnings; diff --git a/centreon/common/emc/navisphere/mode/spcomponents/lcc.pm b/centreon/common/emc/navisphere/mode/spcomponents/lcc.pm index a09128d1d..6eed74ca2 100644 --- a/centreon/common/emc/navisphere/mode/spcomponents/lcc.pm +++ b/centreon/common/emc/navisphere/mode/spcomponents/lcc.pm @@ -33,7 +33,7 @@ # #################################################################################### -package storage::emc::clariion::mode::spcomponents::lcc; +package centreon::common::emc::navisphere::mode::spcomponents::lcc; use strict; use warnings; diff --git a/centreon/common/emc/navisphere/mode/spcomponents/memory.pm b/centreon/common/emc/navisphere/mode/spcomponents/memory.pm index 3098464fb..866a511bd 100644 --- a/centreon/common/emc/navisphere/mode/spcomponents/memory.pm +++ b/centreon/common/emc/navisphere/mode/spcomponents/memory.pm @@ -33,7 +33,7 @@ # #################################################################################### -package storage::emc::clariion::mode::spcomponents::memory; +package centreon::common::emc::navisphere::mode::spcomponents::memory; use strict; use warnings; diff --git a/centreon/common/emc/navisphere/mode/spcomponents/psu.pm b/centreon/common/emc/navisphere/mode/spcomponents/psu.pm index 73f33d02e..f0ca2aa9d 100644 --- a/centreon/common/emc/navisphere/mode/spcomponents/psu.pm +++ b/centreon/common/emc/navisphere/mode/spcomponents/psu.pm @@ -33,7 +33,7 @@ # #################################################################################### -package storage::emc::clariion::mode::spcomponents::psu; +package centreon::common::emc::navisphere::mode::spcomponents::psu; use strict; use warnings; diff --git a/centreon/common/emc/navisphere/mode/spcomponents/sp.pm b/centreon/common/emc/navisphere/mode/spcomponents/sp.pm index bde1e50ff..8766a0048 100644 --- a/centreon/common/emc/navisphere/mode/spcomponents/sp.pm +++ b/centreon/common/emc/navisphere/mode/spcomponents/sp.pm @@ -33,7 +33,7 @@ # #################################################################################### -package storage::emc::clariion::mode::spcomponents::sp; +package centreon::common::emc::navisphere::mode::spcomponents::sp; use strict; use warnings; diff --git a/centreon/common/violin/snmp/mode/components/temperature.pm b/centreon/common/violin/snmp/mode/components/temperature.pm index 4fbc4d79d..7ad8bb9b7 100644 --- a/centreon/common/violin/snmp/mode/components/temperature.pm +++ b/centreon/common/violin/snmp/mode/components/temperature.pm @@ -64,7 +64,7 @@ sub temperature { return if ($self->check_exclude(section => 'temperature', instance => $instance)); - $self->{components}->{psu}->{total}++; + $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is %s degree centigrade.", $instance, $temperature)); my ($exit, $warn, $crit) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $temperature); diff --git a/storage/emc/DataDomain/mode/components/disk.pm b/storage/emc/DataDomain/mode/components/disk.pm index 8da978b36..fa9d19cc5 100644 --- a/storage/emc/DataDomain/mode/components/disk.pm +++ b/storage/emc/DataDomain/mode/components/disk.pm @@ -77,7 +77,7 @@ sub check { $self->{components}->{disk}->{total}++; $self->{output}->output_add(long_msg => sprintf("Disk '%s' status is '%s'", $instance, $disk_status)); - my $exit = $self->get_severity(section => 'fan', value => $disk_status); + my $exit = $self->get_severity(section => 'disk', value => $disk_status); 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, $disk_status)); From 249f8b2cf6702718b1bec42dba2ab7f6df1f1854 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Fri, 12 Dec 2014 10:54:30 +0100 Subject: [PATCH 09/14] Fix #6017 --- network/f5/bigip/mode/listnodes.pm | 2 +- network/f5/bigip/mode/listpools.pm | 2 +- network/f5/bigip/mode/listvirtualservers.pm | 2 +- snmp_standard/mode/diskio.pm | 4 ++-- snmp_standard/mode/listdiskspath.pm | 4 ++-- snmp_standard/mode/listinterfaces.pm | 4 ++-- snmp_standard/mode/liststorages.pm | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/network/f5/bigip/mode/listnodes.pm b/network/f5/bigip/mode/listnodes.pm index ba5a8bcda..6678fc6a6 100644 --- a/network/f5/bigip/mode/listnodes.pm +++ b/network/f5/bigip/mode/listnodes.pm @@ -120,7 +120,7 @@ sub disco_show { # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - $self->manage_selection(); + $self->manage_selection(disco => 1); foreach my $instance (sort @{$self->{node_id_selected}}) { my $name = $self->{result_names}->{$oid_ltmNodeAddrStatusName . '.' . $instance}; diff --git a/network/f5/bigip/mode/listpools.pm b/network/f5/bigip/mode/listpools.pm index df75badff..5887700e6 100644 --- a/network/f5/bigip/mode/listpools.pm +++ b/network/f5/bigip/mode/listpools.pm @@ -120,7 +120,7 @@ sub disco_show { # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - $self->manage_selection(); + $self->manage_selection(disco => 1); foreach my $instance (sort @{$self->{pool_id_selected}}) { my $name = $self->{result_names}->{$oid_ltmPoolStatusName . '.' . $instance}; diff --git a/network/f5/bigip/mode/listvirtualservers.pm b/network/f5/bigip/mode/listvirtualservers.pm index ff1480938..3356bc1ea 100644 --- a/network/f5/bigip/mode/listvirtualservers.pm +++ b/network/f5/bigip/mode/listvirtualservers.pm @@ -120,7 +120,7 @@ sub disco_show { # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - $self->manage_selection(); + $self->manage_selection(disco => 1); foreach my $instance (sort @{$self->{vs_id_selected}}) { my $name = $self->{result_names}->{$oid_ltmVsStatusName . '.' . $instance}; diff --git a/snmp_standard/mode/diskio.pm b/snmp_standard/mode/diskio.pm index a2d424b89..345cee624 100644 --- a/snmp_standard/mode/diskio.pm +++ b/snmp_standard/mode/diskio.pm @@ -279,7 +279,7 @@ sub manage_selection { } } - if (scalar(keys %{$self->{device_id_selected}}) <= 0) { + if (scalar(keys %{$self->{device_id_selected}}) <= 0 && !defined($options{disco})) { if (defined($self->{option_results}->{device})) { $self->{output}->add_option_msg(short_msg => "No device found '" . $self->{option_results}->{device} . "' (or counter values are 0)."); } else { @@ -301,7 +301,7 @@ sub disco_show { # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; $self->{hostname} = $self->{snmp}->get_hostname(); - $self->manage_selection(); + $self->manage_selection(disco => 1); foreach (sort keys %{$self->{device_id_selected}}) { $self->{output}->add_disco_entry(name => $self->{results}->{$oid_diskIODevice}->{$oid_diskIODevice . '.' . $_}, deviceid => $_); diff --git a/snmp_standard/mode/listdiskspath.pm b/snmp_standard/mode/listdiskspath.pm index 010311f21..a71272a1c 100644 --- a/snmp_standard/mode/listdiskspath.pm +++ b/snmp_standard/mode/listdiskspath.pm @@ -166,7 +166,7 @@ sub manage_selection { } } - if (scalar(@{$self->{diskpath_id_selected}}) <= 0) { + if (scalar(@{$self->{diskpath_id_selected}}) <= 0 && !defined($options{disco})) { if (defined($self->{option_results}->{diskpath})) { $self->{output}->add_option_msg(short_msg => "No disk path found for name '" . $self->{option_results}->{diskpath} . "'."); } else { @@ -188,7 +188,7 @@ sub disco_show { # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - $self->manage_selection(); + $self->manage_selection(disco => 1); my $result = $self->get_additional_information(); foreach (sort @{$self->{diskpath_id_selected}}) { if (defined($result)) { diff --git a/snmp_standard/mode/listinterfaces.pm b/snmp_standard/mode/listinterfaces.pm index c1e7c67c0..f9be2b1e9 100644 --- a/snmp_standard/mode/listinterfaces.pm +++ b/snmp_standard/mode/listinterfaces.pm @@ -210,7 +210,7 @@ sub manage_selection { } } - if (scalar(@{$self->{interface_id_selected}}) <= 0) { + if (scalar(@{$self->{interface_id_selected}}) <= 0 && !defined($options{disco})) { if (defined($self->{option_results}->{interface})) { $self->{output}->add_option_msg(short_msg => "No interface found for name '" . $self->{option_results}->{interface} . "'."); } else { @@ -232,7 +232,7 @@ sub disco_show { # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - $self->manage_selection(); + $self->manage_selection(disco => 1); my $result = $self->get_additional_information(); foreach (sort @{$self->{interface_id_selected}}) { my $display_value = $self->get_display_value(id => $_); diff --git a/snmp_standard/mode/liststorages.pm b/snmp_standard/mode/liststorages.pm index d7926e633..843baf1b3 100644 --- a/snmp_standard/mode/liststorages.pm +++ b/snmp_standard/mode/liststorages.pm @@ -224,7 +224,7 @@ sub manage_selection { } } - if (scalar(@{$self->{storage_id_selected}}) <= 0) { + if (scalar(@{$self->{storage_id_selected}}) <= 0 && !defined($options{disco})) { if (defined($self->{option_results}->{storage})) { $self->{output}->add_option_msg(short_msg => "No storage found for name '" . $self->{option_results}->{storage} . "'."); } else { @@ -246,7 +246,7 @@ sub disco_show { # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; - $self->manage_selection(); + $self->manage_selection(disco => 1); my $result = $self->get_additional_information(); foreach (sort @{$self->{storage_id_selected}}) { my $display_value = $self->get_display_value(id => $_); From cbb74c65bfc1e640dfbde807d512357e025c3053 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Fri, 12 Dec 2014 17:27:28 +0100 Subject: [PATCH 10/14] Fix #6029 --- network/checkpoint/mode/components/temperature.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/checkpoint/mode/components/temperature.pm b/network/checkpoint/mode/components/temperature.pm index e9992dc29..ab777086d 100644 --- a/network/checkpoint/mode/components/temperature.pm +++ b/network/checkpoint/mode/components/temperature.pm @@ -74,7 +74,7 @@ sub check { my $exit = $self->get_severity(section => 'temperature', value => $map_states_temperature{$temperature_state}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Temperature '%s' sensor out of range status is '%s'", $voltage_name, $map_states_temperature{$temperature_state})); + short_msg => sprintf("Temperature '%s' sensor out of range status is '%s'", $temperature_name, $map_states_temperature{$temperature_state})); } $self->{output}->perfdata_add(label => $temperature_name , unit => 'C', From edc674ddf42b8f7b1fbefecaf03fadf84c70ed44 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Sat, 13 Dec 2014 19:26:34 +0100 Subject: [PATCH 11/14] Refs #6009 sprintf("%d") ith 32 bits not truncate. prefer 'int()' function to cast int. Do some changes for big numbers (no need for fan number for examples :) --- centreon/plugins/perfdata.pm | 8 ++++---- centreon/plugins/values.pm | 7 ++++--- database/mssql/mode/databasessize.pm | 10 +++++----- database/mysql/mode/databasessize.pm | 6 +++--- database/mysql/mode/queries.pm | 4 ++-- database/postgres/mode/tablespace.pm | 2 +- network/citrix/netscaler/common/mode/memory.pm | 4 ++-- network/citrix/netscaler/common/mode/storage.pm | 2 +- network/juniper/common/junos/mode/memoryforwarding.pm | 2 +- os/aix/snmp/mode/swap.pm | 6 +++--- os/linux/local/mode/filessize.pm | 6 +++--- snmp_standard/mode/storage.pm | 6 +++--- storage/emc/DataDomain/mode/filesystem.pm | 2 +- storage/qnap/snmp/mode/memory.pm | 6 +++--- 14 files changed, 36 insertions(+), 35 deletions(-) diff --git a/centreon/plugins/perfdata.pm b/centreon/plugins/perfdata.pm index 52eac55d0..1a72b1d57 100644 --- a/centreon/plugins/perfdata.pm +++ b/centreon/plugins/perfdata.pm @@ -71,12 +71,12 @@ sub get_perfdata_for_output { if (defined($options{total})) { $perf_value{start} = $perf_value{start} * $options{total} / 100 if ($perf_value{infinite_neg} == 0); $perf_value{end} = $perf_value{end} * $options{total} / 100 if ($perf_value{infinite_pos} == 0); - $perf_value{start} = sprintf("%.2f", $perf_value{start}) if ($perf_value{infinite_neg} == 0 && !defined($options{cast_int})); - $perf_value{end} = sprintf("%.2f", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && !defined($options{cast_int})); + $perf_value{start} = sprintf("%.2f", $perf_value{start}) if ($perf_value{infinite_neg} == 0 && (!defined($options{cast_int}) || $options{cast_int} != 1)); + $perf_value{end} = sprintf("%.2f", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && !defined($options{cast_int}) || $options{cast_int} != 1)); } - $perf_value{start} = sprintf("%d", $perf_value{start}) if ($perf_value{infinite_neg} == 0 && defined($options{cast_int})); - $perf_value{end} = sprintf("%d", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && defined($options{cast_int})); + $perf_value{start} = int($perf_value{start}) if ($perf_value{infinite_neg} == 0 && defined($options{cast_int}) && $options{cast_int} == 1); + $perf_value{end} = int($perf_value{end}) if ($perf_value{infinite_pos} == 0 && defined($options{cast_int}) && $options{cast_int} == 1); my $perf_output = ($perf_value{arobase} == 1 ? "@" : "") . (($perf_value{infinite_neg} == 0) ? $perf_value{start} : "~") . diff --git a/centreon/plugins/values.pm b/centreon/plugins/values.pm index ddba7274f..9b4d7bf3d 100644 --- a/centreon/plugins/values.pm +++ b/centreon/plugins/values.pm @@ -181,6 +181,7 @@ sub perfdata { my $warn = defined($self->{threshold_warn}) ? $self->{threshold_warn} : 'warning-' . $self->{label}; my $crit = defined($self->{threshold_crit}) ? $self->{threshold_crit} : 'critical-' . $self->{label}; + my $cast_int = defined($options{cast_int}) ? $options{cast_int} : 0; foreach my $perf (@{$self->{perfdatas}}) { my ($label, $extra_label, $min, $max, $th_total) = ($self->{label}, ''); @@ -209,9 +210,9 @@ sub perfdata { } $self->{output}->perfdata_add(label => $label . $extra_label, unit => $perf->{unit}, - value => sprintf($template, $self->{result_values}->{$perf->{value}}), - warning => $self->{perfdata}->get_perfdata_for_output(label => $warn, total => $th_total), - critical => $self->{perfdata}->get_perfdata_for_output(label => $crit, total => $th_total), + value => $cast_int == 1 ? int($self->{result_values}->{$perf->{value}}) : sprintf($template, $self->{result_values}->{$perf->{value}}), + warning => $self->{perfdata}->get_perfdata_for_output(label => $warn, total => $th_total, cast_int => $cast_int), + critical => $self->{perfdata}->get_perfdata_for_output(label => $crit, total => $th_total, cast_int => $cast_int), min => $min, max => $max); } } diff --git a/database/mssql/mode/databasessize.pm b/database/mssql/mode/databasessize.pm index b249cc830..4883ab55e 100644 --- a/database/mssql/mode/databasessize.pm +++ b/database/mssql/mode/databasessize.pm @@ -104,18 +104,18 @@ sub run { my ($use_value, $use_unit) = $self->{perfdata}->change_bytes(value => $use); $self->{output}->output_add(long_msg => sprintf("DB '%s' Size: %s Used: %.2f %s (%.2f%%) Free: %s (%.2f%%)", $database, $size_brut, $use_value, $use_unit, $percent_use, $free_brut, $percent_free)); if (defined($self->{option_results}->{free})) { - my $exit_code = $self->{perfdata}->threshold_check(value => $percent_free, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check(value => $percent_free, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit_code, short_msg => sprintf("DB '%s' Size: %s Free: %s (%.2f%%)", $database, $size_brut, $free_brut, $percent_use)); } $self->{output}->perfdata_add(label => sprintf("db_%s_free",$database), unit => 'B', - value => sprintf("%d",$free), + value => int($free), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $size, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $size, cast_int => 1), min => 0, - max => sprintf("%d",$size)); + max => int($size)); } else { my $exit_code = $self->{perfdata}->threshold_check(value => $percent_use, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { @@ -124,11 +124,11 @@ sub run { } $self->{output}->perfdata_add(label => sprintf("db_%s_used",$database), unit => 'B', - value => sprintf("%d",$use), + value => int($use), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $size, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $size, cast_int => 1), min => 0, - max => sprintf("%d",$size)); + max => int($size)); } } } diff --git a/database/mysql/mode/databasessize.pm b/database/mysql/mode/databasessize.pm index 50fad0583..a397f2922 100644 --- a/database/mysql/mode/databasessize.pm +++ b/database/mysql/mode/databasessize.pm @@ -92,13 +92,13 @@ sub run { next if (defined($self->{option_results}->{filter}) && $$row[0] !~ /$self->{option_results}->{filter}/); - my $exit_code = $self->{perfdata}->threshold_check(value => $$row[1], threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check(value => $$row[1], threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my ($value, $value_unit) = $self->{perfdata}->change_bytes(value => $$row[1]); - $self->{output}->output_add(long_msg => sprintf("DB '" . $$row[0] . "' size: %.3f%s", $value, $value_unit)); + $self->{output}->output_add(long_msg => sprintf("DB '" . $$row[0] . "' size: %s%s", $value, $value_unit)); if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("DB '" . $$row[0] . "' size: %.3f%s", $value, $value_unit)); + short_msg => sprintf("DB '" . $$row[0] . "' size: %s%s", $value, $value_unit)); } $self->{output}->perfdata_add(label => $$row[0] . '_size', value => $$row[1], diff --git a/database/mysql/mode/queries.pm b/database/mysql/mode/queries.pm index a5a19a452..723e64f1a 100644 --- a/database/mysql/mode/queries.pm +++ b/database/mysql/mode/queries.pm @@ -114,9 +114,9 @@ sub run { next; } - my $exit_code = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Total requests = %d.", $value)); + short_msg => sprintf("Total requests = %s", $value)); $self->{output}->perfdata_add(label => 'total_requests', value => $value, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), diff --git a/database/postgres/mode/tablespace.pm b/database/postgres/mode/tablespace.pm index 636295aad..1c65cb797 100644 --- a/database/postgres/mode/tablespace.pm +++ b/database/postgres/mode/tablespace.pm @@ -89,7 +89,7 @@ sub run { my $exit_code = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my ($value, $value_unit) = $self->{perfdata}->change_bytes(value => $result); $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf('Tablespace "%s" size is %d %s',$self->{option_results}->{tablespace}, $value, $value_unit)); + short_msg => sprintf('Tablespace "%s" size is %s %s',$self->{option_results}->{tablespace}, $value, $value_unit)); $self->{output}->perfdata_add(label => $self->{option_results}->{tablespace}, value => $result, diff --git a/network/citrix/netscaler/common/mode/memory.pm b/network/citrix/netscaler/common/mode/memory.pm index c5eb78a21..0e035c312 100644 --- a/network/citrix/netscaler/common/mode/memory.pm +++ b/network/citrix/netscaler/common/mode/memory.pm @@ -83,7 +83,7 @@ sub run { my $free = $total_size - $used; my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_resMemUsage}, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $used); @@ -96,7 +96,7 @@ sub run { $free_value . " " . $free_unit, (100 - $result->{$oid_resMemUsage}))); $self->{output}->perfdata_add(label => "used", unit => 'B', - value => sprintf("%d", $used), + value => int($used), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), min => 0, max => $total_size); diff --git a/network/citrix/netscaler/common/mode/storage.pm b/network/citrix/netscaler/common/mode/storage.pm index 2c96cec8e..f78339b86 100644 --- a/network/citrix/netscaler/common/mode/storage.pm +++ b/network/citrix/netscaler/common/mode/storage.pm @@ -91,7 +91,7 @@ sub run { my $prct_used = $total_used * 100 / $total_size; my $prct_free = 100 - $prct_used; - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $total_size); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $total_used); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $total_free); diff --git a/network/juniper/common/junos/mode/memoryforwarding.pm b/network/juniper/common/junos/mode/memoryforwarding.pm index 49c1837fc..d5a8d1038 100644 --- a/network/juniper/common/junos/mode/memoryforwarding.pm +++ b/network/juniper/common/junos/mode/memoryforwarding.pm @@ -89,7 +89,7 @@ sub run { my $mem_usage = $result2->{$oid_jnxJsSPUMonitoringMemoryUsage . '.' . $instance}; my $exit_code = $self->{perfdata}->threshold_check(value => $mem_usage, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit_code, short_msg => sprintf("Memory '%d' usage is: %s%%", $instance, $mem_usage)); $self->{output}->perfdata_add(label => 'mem_' . $instance, unit => '%', diff --git a/os/aix/snmp/mode/swap.pm b/os/aix/snmp/mode/swap.pm index 3faa600c6..217c1f4b2 100644 --- a/os/aix/snmp/mode/swap.pm +++ b/os/aix/snmp/mode/swap.pm @@ -132,16 +132,16 @@ sub run { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $swap_total); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $total_used); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $swap_total - $total_used); - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Page space '%s' Total: %s Used: %s (%.2f%%) Free: %s (%d%%)", $swap_name, + short_msg => sprintf("Page space '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $swap_name, $total_size_value . " " . $total_size_unit, $total_used_value . " " . $total_used_unit, $total_used * 100 / $swap_total, $total_free_value . " " . $total_free_unit, 100 - ($total_used * 100 / $results->{$aix_swap_pool}->{$aix_swap_total . "." . $_}))); } - $self->{output}->output_add(long_msg => sprintf("Page space '%s' Total: %s Used: %s (%.2f%%) Free: %s (%d%%)", $swap_name, + $self->{output}->output_add(long_msg => sprintf("Page space '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $swap_name, $total_size_value . " " . $total_size_unit, $total_used_value . " " . $total_used_unit, $total_used * 100 / $swap_total, $total_free_value . " " . $total_free_unit, 100 - ($total_used * 100 / $swap_total))); diff --git a/os/linux/local/mode/filessize.pm b/os/linux/local/mode/filessize.pm index 3e1dd3431..a31a78fdb 100644 --- a/os/linux/local/mode/filessize.pm +++ b/os/linux/local/mode/filessize.pm @@ -138,12 +138,12 @@ sub run { $total_size += $size; my $exit_code = $self->{perfdata}->threshold_check(value => $size, - threshold => [ { label => 'critical_one', 'exit_litteral' => 'critical' }, { label => 'warning_one', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical_one', exit_litteral => 'critical' }, { label => 'warning_one', exit_litteral => 'warning' } ]); my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $size); $self->{output}->output_add(long_msg => sprintf("%s: %s", $name, $size_value . ' ' . $size_unit)); if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) { $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("'%d' size is %s", $name, $size_value . ' ' . $size_unit)); + short_msg => sprintf("'%s' size is %s", $name, $size_value . ' ' . $size_unit)); } $self->{output}->perfdata_add(label => $name, unit => 'B', value => $size, @@ -154,7 +154,7 @@ sub run { # Total Size my $exit_code = $self->{perfdata}->threshold_check(value => $total_size, - threshold => [ { label => 'critical_total', 'exit_litteral' => 'critical' }, { label => 'warning_total', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical_total', exit_litteral => 'critical' }, { label => 'warning_total', exit_litteral => 'warning' } ]); my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $total_size); $self->{output}->output_add(long_msg => sprintf("Total: %s", $size_value . ' ' . $size_unit)); if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) { diff --git a/snmp_standard/mode/storage.pm b/snmp_standard/mode/storage.pm index e34511d10..8f06c90cf 100644 --- a/snmp_standard/mode/storage.pm +++ b/snmp_standard/mode/storage.pm @@ -183,8 +183,8 @@ sub run { # in bytes hrStorageAllocationUnits my $total_size = $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_}; if ($total_size <= 0) { - $self->{output}->add_option_msg(long_msg => sprintf("Skipping storage '%d': total size is <= 0 (%d)", - $name_storage, $total_size)); + $self->{output}->add_option_msg(long_msg => sprintf("Skipping storage '%d': total size is <= 0 (%s)", + $name_storage, int($total_size))); next; } @@ -247,7 +247,7 @@ sub run { value => $value_perf, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', %total_options), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', %total_options), - min => 0, max => sprintf("%d", $total_size - $reserved_value)); + min => 0, max => int($total_size - $reserved_value)); } if ($num_disk_check == 0) { diff --git a/storage/emc/DataDomain/mode/filesystem.pm b/storage/emc/DataDomain/mode/filesystem.pm index 91a35bbe4..b454d2068 100644 --- a/storage/emc/DataDomain/mode/filesystem.pm +++ b/storage/emc/DataDomain/mode/filesystem.pm @@ -57,7 +57,7 @@ my $maps_counters = { threshold_use => 'used_prct', output_error_template => '%s', perfdatas => [ - { value => 'used', label => 'used', template => '%d', + { value => 'used', label => 'used', cast_int => 1, unit => 'B', min => 0, max => 'total', threshold_total => 'total', label_extra_instance => 1, instance_use => 'display' }, ], diff --git a/storage/qnap/snmp/mode/memory.pm b/storage/qnap/snmp/mode/memory.pm index 01ebd4b2a..fbdbceed9 100644 --- a/storage/qnap/snmp/mode/memory.pm +++ b/storage/qnap/snmp/mode/memory.pm @@ -106,7 +106,7 @@ sub run { my $prct_used = $memory_used * 100 / $total_size; my $prct_free = 100 - $prct_used; - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $memory_used); my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $memory_free); @@ -118,10 +118,10 @@ sub run { $free_value . " " . $free_unit, $prct_free)); $self->{output}->perfdata_add(label => "used", - value => sprintf("%d", $memory_used), + value => int($memory_used), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), - min => 0, max => sprintf("%d", $total_size)); + min => 0, max => int($total_size)); $self->{output}->display(); $self->{output}->exit(); From be6007a38d3795141fddea50d7573fe024d618d7 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Sat, 13 Dec 2014 19:28:25 +0100 Subject: [PATCH 12/14] Fix typo error --- centreon/plugins/perfdata.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon/plugins/perfdata.pm b/centreon/plugins/perfdata.pm index 1a72b1d57..3e15758a8 100644 --- a/centreon/plugins/perfdata.pm +++ b/centreon/plugins/perfdata.pm @@ -72,7 +72,7 @@ sub get_perfdata_for_output { $perf_value{start} = $perf_value{start} * $options{total} / 100 if ($perf_value{infinite_neg} == 0); $perf_value{end} = $perf_value{end} * $options{total} / 100 if ($perf_value{infinite_pos} == 0); $perf_value{start} = sprintf("%.2f", $perf_value{start}) if ($perf_value{infinite_neg} == 0 && (!defined($options{cast_int}) || $options{cast_int} != 1)); - $perf_value{end} = sprintf("%.2f", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && !defined($options{cast_int}) || $options{cast_int} != 1)); + $perf_value{end} = sprintf("%.2f", $perf_value{end}) if ($perf_value{infinite_pos} == 0 && (!defined($options{cast_int}) || $options{cast_int} != 1)); } $perf_value{start} = int($perf_value{start}) if ($perf_value{infinite_neg} == 0 && defined($options{cast_int}) && $options{cast_int} == 1); From e2e13ae596bfbc9aed62f0560d7453da53428474 Mon Sep 17 00:00:00 2001 From: Quentin Delance Date: Mon, 15 Dec 2014 10:20:40 +0100 Subject: [PATCH 13/14] Extra test on parameters --- database/postgres/mode/vacuum.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/database/postgres/mode/vacuum.pm b/database/postgres/mode/vacuum.pm index 754adc888..7e362d047 100644 --- a/database/postgres/mode/vacuum.pm +++ b/database/postgres/mode/vacuum.pm @@ -67,6 +67,10 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } + if (($self->{perfdata}->threshold_validate(label => 'dbname', value => $self->{option_results}->{dbname})) eq 'postgres') { + $self->{output}->add_option_msg(short_msg => "Invalid db."); + $self->{output}->option_exit(); + } } @@ -85,6 +89,9 @@ sub run { if ($1 eq 'postgres') { $self->{output}->add_option_msg(short_msg => "Cannot use system 'postgres' database ; you must use a real database."); $self->{output}->option_exit(); + } elsif ($1 eq '') { + $self->{output}->add_option_msg(short_msg => "Database must be specified."); + $self->{output}->option_exit(); } } else { $self->{output}->add_option_msg(short_msg => "Need to specify database argument."); From 5f8d5a1ed29a41336cf211451b6a1a1837b0b564 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Mon, 15 Dec 2014 16:41:28 +0100 Subject: [PATCH 14/14] Refs #5627 Improve netapp --- .../netapp/mode/components/communication.pm | 85 +++ storage/netapp/mode/components/electronics.pm | 89 +++ storage/netapp/mode/components/fan.pm | 107 ++++ storage/netapp/mode/components/psu.pm | 89 +++ storage/netapp/mode/components/temperature.pm | 152 ++++++ storage/netapp/mode/components/voltage.pm | 147 +++++ storage/netapp/mode/globalstatus.pm | 146 ++++- storage/netapp/mode/shelf.pm | 509 +++++++----------- storage/netapp/plugin.pm | 28 +- 9 files changed, 1006 insertions(+), 346 deletions(-) create mode 100644 storage/netapp/mode/components/communication.pm create mode 100644 storage/netapp/mode/components/electronics.pm create mode 100644 storage/netapp/mode/components/fan.pm create mode 100644 storage/netapp/mode/components/psu.pm create mode 100644 storage/netapp/mode/components/temperature.pm create mode 100644 storage/netapp/mode/components/voltage.pm diff --git a/storage/netapp/mode/components/communication.pm b/storage/netapp/mode/components/communication.pm new file mode 100644 index 000000000..2e37c557c --- /dev/null +++ b/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/storage/netapp/mode/components/electronics.pm b/storage/netapp/mode/components/electronics.pm new file mode 100644 index 000000000..62cf702dc --- /dev/null +++ b/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/storage/netapp/mode/components/fan.pm b/storage/netapp/mode/components/fan.pm new file mode 100644 index 000000000..50567ffd2 --- /dev/null +++ b/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/storage/netapp/mode/components/psu.pm b/storage/netapp/mode/components/psu.pm new file mode 100644 index 000000000..085327531 --- /dev/null +++ b/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/storage/netapp/mode/components/temperature.pm b/storage/netapp/mode/components/temperature.pm new file mode 100644 index 000000000..604a8a9e1 --- /dev/null +++ b/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/storage/netapp/mode/components/voltage.pm b/storage/netapp/mode/components/voltage.pm new file mode 100644 index 000000000..367490a1c --- /dev/null +++ b/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/storage/netapp/mode/globalstatus.pm b/storage/netapp/mode/globalstatus.pm index 48e093ec5..845739c27 100644 --- a/storage/netapp/mode/globalstatus.pm +++ b/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/storage/netapp/mode/shelf.pm b/storage/netapp/mode/shelf.pm index b5b6102d5..4230707ee 100644 --- a/storage/netapp/mode/shelf.pm +++ b/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/storage/netapp/plugin.pm b/storage/netapp/plugin.pm index eb4b5b2da..79efb5d65 100644 --- a/storage/netapp/plugin.pm +++ b/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;