diff --git a/apps/protocols/imap/lib/imap.pm b/apps/protocols/imap/lib/imap.pm new file mode 100644 index 000000000..60702a5d9 --- /dev/null +++ b/apps/protocols/imap/lib/imap.pm @@ -0,0 +1,115 @@ +############################################################################### +# 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 timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable 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 +# Author : Simon BOMM +# +#################################################################################### + +package apps::protocols::imap::lib::imap; + +use strict; +use warnings; +use centreon::plugins::misc; +use Net::IMAP::Simple; + +my $imap_handle; + +sub quit { + $imap_handle->quit; +} + +sub search { + my ($self, %options) = @_; + + if (!defined($imap_handle->select($self->{option_results}->{folder}))) { + my $output = $imap_handle->errstr; + $output =~ s/\r//g; + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => 'Folder Select Error: ' . $output); + quit(); + $self->{output}->display(); + $self->{output}->exit(); + } + + my @ids = $imap_handle->search($self->{option_results}->{search}); + + if (defined($self->{option_results}->{delete})) { + foreach my $msg_num (@ids) { + $imap_handle->delete($msg_num); + } + $imap_handle->expunge_mailbox(); + } + + return scalar(@ids); +} + +sub connect { + my ($self, %options) = @_; + my %imap_options = (); + + my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown'; + $imap_options{port} = $self->{option_results}->{port} if (defined($self->{option_results}->{port})); + $imap_options{use_ssl} = 1 if (defined($self->{option_results}->{use_ssl})); + $imap_options{timeout} = $self->{option_results}->{timeout} if (defined($self->{option_results}->{timeout})); + + if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '' && + !defined($self->{option_results}->{password})) { + $self->{output}->add_option_msg(short_msg => "Please set --password option."); + $self->{output}->option_exit(); + } + + $imap_handle = Net::IMAP::Simple->new($self->{option_results}->{hostname}, + %imap_options + ); + + + if (!defined($imap_handle)) { + $self->{output}->output_add(severity => $connection_exit, + short_msg => 'Unable to connect to IMAP: ' . $Net::IMAP::Simple::errstr); + $self->{output}->display(); + $self->{output}->exit(); + } + + if (defined($self->{option_results}->{username}) && $self->{option_results}->{username} ne '') { + if (!$imap_handle->login($self->{option_results}->{username}, $self->{option_results}->{password})) { + # Exchange put '\r'... + my $output = $imap_handle->errstr; + $output =~ s/\r//g; + $self->{output}->output_add(severity => $connection_exit, + short_msg => 'Login failed: ' . $output); + quit(); + $self->{output}->display(); + $self->{output}->exit(); + } + } +} + +1; diff --git a/apps/protocols/imap/mode/login.pm b/apps/protocols/imap/mode/login.pm new file mode 100644 index 000000000..3349fb19d --- /dev/null +++ b/apps/protocols/imap/mode/login.pm @@ -0,0 +1,152 @@ +############################################################################### +# 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 timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable 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 +# Author : Quentin Garnier +# +#################################################################################### + +package apps::protocols::imap::mode::login; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use Time::HiRes qw(gettimeofday tv_interval); +use apps::protocols::imap::lib::imap; + +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 => + { + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port', }, + "ssl" => { name => 'use_ssl' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "timeout:s" => { name => 'timeout', default => '30' }, + }); + 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 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 threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + + if (!defined($self->{option_results}->{hostname})) { + $self->{output}->add_option_msg(short_msg => "Please set the hostname option"); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + + my $timing0 = [gettimeofday]; + + apps::protocols::imap::lib::imap::connect($self, connection_exit => 'critical'); + apps::protocols::imap::lib::imap::quit(); + + my $timeelapsed = tv_interval ($timing0, [gettimeofday]); + + my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Response time %.3f ", $timeelapsed)); + $self->{output}->perfdata_add(label => "time", + value => sprintf('%.3f', $timeelapsed), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check Connection (also login) to an IMAP Server. + +=over 8 + +=item B<--hostname> + +IP Addr/FQDN of the imap host + +=item B<--port> + +Port used + +=item B<--ssl> + +Use SSL connection. +(no attempt is made to check the certificate validity by default). + +=item B<--username> + +Specify username for authentification + +=item B<--password> + +Specify password for authentification + +=item B<--timeout> + +Connection timeout in seconds (Default: 30) + +=item B<--warning> + +Threshold warning in seconds + +=item B<--critical> + +Threshold critical in seconds + +=back + +=cut diff --git a/apps/protocols/imap/mode/searchmessage.pm b/apps/protocols/imap/mode/searchmessage.pm new file mode 100644 index 000000000..3e1ffa109 --- /dev/null +++ b/apps/protocols/imap/mode/searchmessage.pm @@ -0,0 +1,168 @@ +############################################################################### +# 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 timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable 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 +# Author : Quentin Garnier +# +#################################################################################### + +package apps::protocols::imap::mode::searchmessage; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use apps::protocols::imap::lib::imap; + +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 => + { + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port', }, + "ssl" => { name => 'use_ssl' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + "timeout:s" => { name => 'timeout', default => '30' }, + "search:s" => { name => 'search' }, + "delete" => { name => 'delete' }, + "folder:s" => { name => 'folder', default => 'INBOX' }, + }); + 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 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 threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + + if (!defined($self->{option_results}->{hostname})) { + $self->{output}->add_option_msg(short_msg => "Please set the --hostname option"); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{search})) { + $self->{output}->add_option_msg(short_msg => "Please set the --search option"); + $self->{output}->option_exit(); + } +} + +sub run { + my ($self, %options) = @_; + + apps::protocols::imap::lib::imap::connect($self); + my ($num) = apps::protocols::imap::lib::imap::search($self); + apps::protocols::imap::lib::imap::quit(); + + my $exit = $self->{perfdata}->threshold_check(value => $num, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%d message found(s)", $num)); + $self->{output}->perfdata_add(label => "numbers", + value => $num, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')); + + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check Connection (also login) to an IMAP Server. + +=over 8 + +=item B<--hostname> + +IP Addr/FQDN of the imap host + +=item B<--port> + +Port used + +=item B<--ssl> + +Use SSL connection. +(no attempt is made to check the certificate validity by default). + +=item B<--username> + +Specify username for authentification + +=item B<--password> + +Specify password for authentification + +=item B<--timeout> + +Connection timeout in seconds (Default: 30) + +=item B<--search> + +Set the search string (Required) + +=item B<--delete> + +Delete messages found + +=item B<--folder> + +Set IMAP folder (Default: 'INBOX') + +=item B<--warning> + +Threshold warning of number messages found + +=item B<--critical> + +Threshold critical of number message found + +=back + +=cut diff --git a/apps/protocols/imap/plugin.pm b/apps/protocols/imap/plugin.pm new file mode 100644 index 000000000..c9c378718 --- /dev/null +++ b/apps/protocols/imap/plugin.pm @@ -0,0 +1,64 @@ +################################################################################ +# 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 apps::protocols::imap::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_simple); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'login' => 'apps::protocols::imap::mode::login', + 'search-message' => 'apps::protocols::imap::mode::searchmessage', + ); + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check an IMAP server. + +=cut diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm index f3d91d5d6..21c74b911 100644 --- a/centreon/plugins/output.pm +++ b/centreon/plugins/output.pm @@ -35,7 +35,6 @@ package centreon::plugins::output; -use Encode; use centreon::plugins::misc; use strict; use warnings; @@ -79,6 +78,8 @@ sub new { $self->{explode_perfdata_total} = 0; $self->{range_perfdata} = 0; $self->{global_status} = 0; + $self->{encode_utf8_import} = 0; + $self->{perlqq} = 0; $self->{disco_elements} = []; $self->{disco_entries} = []; @@ -669,7 +670,18 @@ sub display_disco_show { sub to_utf8 { my ($self, $value) = @_; - return centreon::plugins::misc::trim(Encode::decode('UTF-8', $value, Encode::PERLQQ)); + if ($self->{encode_utf8_import} == 0) { + + + # Some Perl version dont have the following module (like Perl 5.6.x) + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Encode', + error_msg => "Cannot load module 'Encode'."); + + $self->{encode_utf8_import} = 1; + eval '$self->{perlqq} = Encode::PERLQQ'; + } + + return centreon::plugins::misc::trim(Encode::decode('UTF-8', $value, $self->{perlqq})); } sub add_disco_entry { diff --git a/centreon/plugins/script.pm b/centreon/plugins/script.pm index 465992fb4..4f184b2e0 100644 --- a/centreon/plugins/script.pm +++ b/centreon/plugins/script.pm @@ -77,8 +77,7 @@ sub class_handle_DIE { sub handle_DIE { my ($self, $msg) = @_; - # For 'mod_perl' - die $msg if $^S; + return unless defined $^S and $^S == 0; # Ignore errors in eval $self->{output}->add_option_msg(short_msg => $msg); $self->{output}->die_exit(); } diff --git a/hardware/server/hpproliant/mode/components/cpu.pm b/hardware/server/hpproliant/mode/components/cpu.pm index 3ce002c41..29edbea17 100644 --- a/hardware/server/hpproliant/mode/components/cpu.pm +++ b/hardware/server/hpproliant/mode/components/cpu.pm @@ -51,8 +51,8 @@ sub check { # In MIB 'CPQSTDEQ-MIB.mib' $self->{output}->output_add(long_msg => "Checking cpu"); - $self->{components}->{cpu} = {name => 'cpus', total => 0}; - return if ($self->check_exclude('cpu')); + $self->{components}->{cpu} = {name => 'cpus', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'cpu')); my $oid_cpqSeCpuUnitIndex = '.1.3.6.1.4.1.232.1.2.2.1.1.1'; my $oid_cpqSeCpuSlot = '.1.3.6.1.4.1.232.1.2.2.1.1.2'; @@ -76,7 +76,9 @@ sub check { my $cpu_status = $result2->{$oid_cpqSeCpuStatus . '.' . $instance}; my $cpu_socket_number = $result2->{$oid_cpqSeCpuSocketNumber . '.' . $instance}; + next if ($self->check_exclude(section => 'cpu', instance => $instance)); $self->{components}->{cpu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("cpu [slot: %s, unit: %s, name: %s, socket: %s] status is %s.", $cpu_slot, $result->{$key}, $cpu_name, $cpu_socket_number, ${$cpustatus{$cpu_status}}[0])); diff --git a/hardware/server/hpproliant/mode/components/fan.pm b/hardware/server/hpproliant/mode/components/fan.pm index 88b30b24e..12ba019d5 100644 --- a/hardware/server/hpproliant/mode/components/fan.pm +++ b/hardware/server/hpproliant/mode/components/fan.pm @@ -84,8 +84,8 @@ sub check { # In MIB 'CPQHLTH-MIB.mib' $self->{output}->output_add(long_msg => "Checking fans"); - $self->{components}->{fan} = {name => 'fans', total => 0}; - return if ($self->check_exclude('fan')); + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'fan')); my $oid_cpqHeFltTolFanPresent = '.1.3.6.1.4.1.232.6.2.6.7.1.4'; my $oid_cpqHeFltTolFanChassis = '.1.3.6.1.4.1.232.6.2.6.7.1.1'; @@ -102,10 +102,13 @@ sub check { my @get_oids = (); my @oids_end = (); foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($present_map{$result->{$key}} ne 'present'); # Chassis + index - $key =~ /(\d+\.\d+)$/; - my $oid_end = $1; + $key =~ /(\d+)\.(\d+)$/; + my $oid_end = $1 . '.' . $2; + + next if ($present_map{$result->{$key}} ne 'present' && + $self->absent_problem(section => 'fans', instance => $1 . '.' . $2)); + push @oids_end, $oid_end; push @get_oids, $oid_cpqHeFltTolFanLocale . "." . $oid_end, $oid_cpqHeFltTolFanCondition . "." . $oid_end, @@ -122,7 +125,9 @@ sub check { my $fan_redundant = $result->{$oid_cpqHeFltTolFanRedundant . '.' . $_}; my $fan_redundantpartner = $result->{$oid_cpqHeFltTolFanRedundantPartner . '.' . $_}; + next if ($self->check_exclude(section => 'fans', instance => $fan_chassis . '.' . $fan_index)); $self->{components}->{fan}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fan %d status is %s, speed is %s [chassis: %s, location: %s, redundance: %s, redundant partner: %s].", $fan_index, ${$conditions{$fan_condition}}[0], $fanspeed{$fan_speed}, $fan_chassis, $location_map{$fan_locale}, diff --git a/hardware/server/hpproliant/mode/components/fca.pm b/hardware/server/hpproliant/mode/components/fca.pm index 7d164d1e8..91d91de49 100644 --- a/hardware/server/hpproliant/mode/components/fca.pm +++ b/hardware/server/hpproliant/mode/components/fca.pm @@ -182,8 +182,8 @@ sub host_array_controller { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking fca host controller"); - $self->{components}->{fcahostctl} = {name => 'fca host controllers', total => 0}; - return if ($self->check_exclude('fcahostctl')); + $self->{components}->{fcahostctl} = {name => 'fca host controllers', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'fcahostctl')); my $oid_cpqFcaHostCntlrIndex = '.1.3.6.1.4.1.232.16.2.7.1.1.1'; my $oid_cpqFcaHostCntlrSlot = '.1.3.6.1.4.1.232.16.2.7.1.1.2'; @@ -208,7 +208,9 @@ sub host_array_controller { my $fca_slot = $result2->{$oid_cpqFcaHostCntlrSlot . '.' . $instance}; my $fca_condition = $result2->{$oid_cpqFcaHostCntlrCondition . '.' . $instance}; + next if ($self->check_exclude(section => 'fcahostctl', instance => $instance)); $self->{components}->{fcahostctl}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fca host controller %s [slot: %s, model: %s, status: %s] condition is %s.", $fca_index, $fca_slot, $model_map{$fca_model}, $hostctlstatus_map{$fca_status}, ${$conditions{$fca_condition}}[0])); @@ -224,8 +226,8 @@ sub external_array_controller { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking fca external controller"); - $self->{components}->{fcaexternalctl} = {name => 'fca external controllers', total => 0}; - return if ($self->check_exclude('fcaexternalctl')); + $self->{components}->{fcaexternalctl} = {name => 'fca external controllers', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'fcaexternalctl')); my $oid_cpqFcaCntlrCondition = '.1.3.6.1.4.1.232.16.2.2.1.1.6'; my $oid_cpqFcaCntlrModel = '.1.3.6.1.4.1.232.16.2.2.1.1.3'; @@ -251,7 +253,9 @@ sub external_array_controller { my $fca_role = $result2->{$oid_cpqFcaCntlrCurrentRole . '.' . $instance}; my $fca_condition = $result->{$key}; + next if ($self->check_exclude(section => 'fcaexternalctl', instance => $instance)); $self->{components}->{fcaexternalctl}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fca external controller %s [model: %s, status: %s, role: %s] condition is %s.", $fca_box_index . ':' . $fca_box_slot, $external_model_map{$fca_model}, $externalctlstatus_map{$fca_status}, $externalrole_map{$fca_role}, @@ -268,8 +272,8 @@ sub external_array_accelerator { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking fca external accelerator boards"); - $self->{components}->{fcaexternalacc} = {name => 'fca external accelerator boards', total => 0}; - return if ($self->check_exclude('fcaexternalacc')); + $self->{components}->{fcaexternalacc} = {name => 'fca external accelerator boards', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'fcaexternalacc')); my $oid_cpqFcaAccelCondition = '.1.3.6.1.4.1.232.16.2.2.2.1.9'; my $oid_cpqFcaAccelStatus = '.1.3.6.1.4.1.232.16.2.2.2.1.3'; @@ -292,7 +296,9 @@ sub external_array_accelerator { my $accel_condition = $result->{$key}; my $accel_battery = $result2->{$oid_cpqFcaAccelBatteryStatus . '.' . $instance}; + next if ($self->check_exclude(section => 'fcaexternalacc', instance => $instance)); $self->{components}->{fcaexternalacc}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fca external accelerator boards %s [status: %s, battery status: %s] condition is %s.", $fca_box_index . ':' . $fca_box_slot, $accelstatus_map{$accel_status}, ${$conditionsbattery{$accel_battery}}[0], @@ -314,8 +320,8 @@ sub logical_drive { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking fca logical drives"); - $self->{components}->{fcaldrive} = {name => 'fca logical drives', total => 0}; - return if ($self->check_exclude('fcaldrive')); + $self->{components}->{fcaldrive} = {name => 'fca logical drives', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'fcaldrive')); my $oid_cpqFcaLogDrvCondition = '.1.3.6.1.4.1.232.16.2.3.1.1.11'; my $oid_cpqFcaLogDrvStatus = '.1.3.6.1.4.1.232.16.2.3.1.1.4'; @@ -339,7 +345,9 @@ sub logical_drive { my $ldrive_condition = $result->{$key}; my $ldrive_faultol = $result2->{$oid_cpqFcaLogDrvFaultTol . '.' . $instance}; + next if ($self->check_exclude(section => 'fcaldrive', instance => $instance)); $self->{components}->{fcaldrive}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fca logical drive %s [fault tolerance: %s, status: %s] condition is %s.", $box_index . ':' . $drive_index, $ldrive_fault_tolerance_map{$ldrive_faultol}, @@ -363,8 +371,8 @@ sub physical_drive { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking fca physical drives"); - $self->{components}->{fcapdrive} = {name => 'fca physical drives', total => 0}; - return if ($self->check_exclude('fcapdrive')); + $self->{components}->{fcapdrive} = {name => 'fca physical drives', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'fcapdrive')); my $oid_cpqFcaPhyDrvCondition = '.1.3.6.1.4.1.232.16.2.5.1.1.31'; my $oid_cpqFcaPhyDrvStatus = '.1.3.6.1.4.1.232.16.2.5.1.1.6'; @@ -385,7 +393,9 @@ sub physical_drive { my $pdrive_status = $result2->{$oid_cpqFcaPhyDrvStatus . '.' . $instance}; my $pdrive_condition = $result->{$key}; + next if ($self->check_exclude(section => 'fcapdrive', instance => $instance)); $self->{components}->{fcapdrive}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fca physical drive %s [status: %s] condition is %s.", $box_index . ':' . $drive_index, $pdrive_status_map{$pdrive_status}, diff --git a/hardware/server/hpproliant/mode/components/ida.pm b/hardware/server/hpproliant/mode/components/ida.pm index 231cdea8f..c7c009577 100644 --- a/hardware/server/hpproliant/mode/components/ida.pm +++ b/hardware/server/hpproliant/mode/components/ida.pm @@ -154,8 +154,8 @@ sub array_controller { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking da controller"); - $self->{components}->{dactl} = {name => 'da controllers', total => 0}; - return if ($self->check_exclude('dactl')); + $self->{components}->{dactl} = {name => 'da controllers', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'dactl')); my $oid_cpqDaCntlrIndex = '.1.3.6.1.4.1.232.3.2.2.1.1.1'; my $oid_cpqDaCntlrModel = '.1.3.6.1.4.1.232.3.2.2.1.1.2'; @@ -176,8 +176,10 @@ sub array_controller { my $da_model = $result2->{$oid_cpqDaCntlrModel . '.' . $instance}; my $da_slot = $result2->{$oid_cpqDaCntlrSlot . '.' . $instance}; my $da_condition = $result2->{$oid_cpqDaCntlrCondition . '.' . $instance}; - + + next if ($self->check_exclude(section => 'dactl', instance => $instance)); $self->{components}->{dactl}->{total}++; + $self->{output}->output_add(long_msg => sprintf("da controller %s [slot: %s, model: %s] status is %s.", $instance, $da_slot, $model_map{$da_model}, ${$conditions{$da_condition}}[0])); @@ -193,8 +195,8 @@ sub array_accelerator { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking da accelerator boards"); - $self->{components}->{daacc} = {name => 'da accelerator boards', total => 0}; - return if ($self->check_exclude('daacc')); + $self->{components}->{daacc} = {name => 'da accelerator boards', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'daacc')); my $oid_cpqDaAccelCntlrIndex = '.1.3.6.1.4.1.232.3.2.2.2.1.1'; my $oid_cpqDaAccelStatus = '.1.3.6.1.4.1.232.3.2.2.2.1.2'; @@ -215,8 +217,10 @@ sub array_accelerator { my $accel_status = $result2->{$oid_cpqDaAccelStatus . '.' . $instance}; my $accel_condition = $result2->{$oid_cpqDaAccelCondition . '.' . $instance}; my $accel_battery = $result2->{$oid_cpqDaAccelBattery . '.' . $instance}; - + + next if ($self->check_exclude(section => 'daacc', instance => $instance)); $self->{components}->{daacc}->{total}++; + $self->{output}->output_add(long_msg => sprintf("da controller accelerator %s [status: %s, battery status: %s] condition is %s.", $instance, $accelstatus_map{$accel_status}, ${$conditionsbattery{$accel_battery}}[0], ${$conditions{$accel_condition}}[0])); @@ -237,8 +241,8 @@ sub logical_drive { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking da logical drives"); - $self->{components}->{daldrive} = {name => 'da logical drives', total => 0}; - return if ($self->check_exclude('daldrive')); + $self->{components}->{daldrive} = {name => 'da logical drives', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'daldrive')); my $oid_cpqDaLogDrvCondition = '.1.3.6.1.4.1.232.3.2.3.1.1.11'; my $oid_cpqDaLogDrvStatus = '.1.3.6.1.4.1.232.3.2.3.1.1.4'; @@ -261,8 +265,10 @@ sub logical_drive { my $ldrive_status = $result2->{$oid_cpqDaLogDrvStatus . '.' . $instance}; my $ldrive_condition = $result->{$key}; my $ldrive_faultol = $result2->{$oid_cpqDaLogDrvFaultTol . '.' . $instance}; - + + next if ($self->check_exclude(section => 'daldrive', instance => $instance)); $self->{components}->{daldrive}->{total}++; + $self->{output}->output_add(long_msg => sprintf("da logical drive %s [fault tolerance: %s, status: %s] condition is %s.", $controller_index . ':' . $drive_index, $ldrive_fault_tolerance_map{$ldrive_faultol}, @@ -286,8 +292,8 @@ sub physical_drive { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking da physical drives"); - $self->{components}->{dapdrive} = {name => 'da physical drives', total => 0}; - return if ($self->check_exclude('dapdrive')); + $self->{components}->{dapdrive} = {name => 'da physical drives', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'dapdrive')); my $oid_cpqDaPhyDrvCondition = '.1.3.6.1.4.1.232.3.2.5.1.1.37'; my $oid_cpqDaPhyDrvStatus = '.1.3.6.1.4.1.232.3.2.5.1.1.6'; @@ -307,8 +313,10 @@ sub physical_drive { my $pdrive_status = $result2->{$oid_cpqDaPhyDrvStatus . '.' . $instance}; my $pdrive_condition = $result->{$key}; - + + next if ($self->check_exclude(section => 'dapdrive', instance => $instance)); $self->{components}->{dapdrive}->{total}++; + $self->{output}->output_add(long_msg => sprintf("da physical drive %s [status: %s] condition is %s.", $controller_index . ':' . $drive_index, $pdrive_status_map{$pdrive_status}, diff --git a/hardware/server/hpproliant/mode/components/ide.pm b/hardware/server/hpproliant/mode/components/ide.pm index 87191af13..4e56ec71a 100644 --- a/hardware/server/hpproliant/mode/components/ide.pm +++ b/hardware/server/hpproliant/mode/components/ide.pm @@ -73,8 +73,8 @@ sub controller { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking ide controllers"); - $self->{components}->{idectl} = {name => 'ide controllers', total => 0}; - return if ($self->check_exclude('idectl')); + $self->{components}->{idectl} = {name => 'ide controllers', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'idectl')); my $oid_cpqIdeControllerIndex = '.1.3.6.1.4.1.232.14.2.3.1.1.1'; my $oid_cpqIdeControllerCondition = '.1.3.6.1.4.1.232.14.2.3.1.1.7'; @@ -97,8 +97,10 @@ sub controller { my $ide_slot = $result2->{$oid_cpqIdeControllerSlot . '.' . $instance}; my $ide_condition = $result2->{$oid_cpqIdeControllerCondition . '.' . $instance}; my $ide_status = $result2->{$oid_cpqIdeControllerStatus . '.' . $instance}; - + + next if ($self->check_exclude(section => 'idectl', instance => $instance)); $self->{components}->{idectl}->{total}++; + $self->{output}->output_add(long_msg => sprintf("ide controller %s [slot: %s, model: %s, status: %s] condition is %s.", $instance, $ide_slot, $ide_model, $controllerstatus_map{$ide_status}, ${$conditions{$ide_condition}}[0])); @@ -114,8 +116,8 @@ sub logical_drive { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking ide logical drives"); - $self->{components}->{ideldrive} = {name => 'ide logical drives', total => 0}; - return if ($self->check_exclude('ideldrive')); + $self->{components}->{ideldrive} = {name => 'ide logical drives', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'ideldrive')); my $oid_cpqIdeLogicalDriveCondition = '.1.3.6.1.4.1.232.14.2.6.1.1.6'; my $oid_cpqIdeLogicalDriveStatus = '.1.3.6.1.4.1.232.14.2.6.1.1.5'; @@ -135,8 +137,10 @@ sub logical_drive { my $ldrive_status = $result2->{$oid_cpqIdeLogicalDriveStatus . '.' . $instance}; my $ldrive_condition = $result->{$key}; - + + next if ($self->check_exclude(section => 'ideldrive', instance => $instance)); $self->{components}->{ideldrive}->{total}++; + $self->{output}->output_add(long_msg => sprintf("ide logical drive %s [status: %s] condition is %s.", $controller_index . ':' . $drive_index, $ldrive_status_map{$ldrive_status}, @@ -159,8 +163,8 @@ sub physical_drive { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking ide physical drives"); - $self->{components}->{idepdrive} = {name => 'ide physical drives', total => 0}; - return if ($self->check_exclude('idepdrive')); + $self->{components}->{idepdrive} = {name => 'ide physical drives', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'idepdrive')); my $oid_cpqIdeAtaDiskCondition = '.1.3.6.1.4.1.232.14.2.4.1.1.7'; my $oid_cpqIdeAtaDiskStatus = '.1.3.6.1.4.1.232.14.2.4.1.1.6'; @@ -180,8 +184,10 @@ sub physical_drive { my $pdrive_status = $result2->{$oid_cpqIdeAtaDiskStatus . '.' . $instance}; my $pdrive_condition = $result->{$key}; - + + next if ($self->check_exclude(section => 'idepdrive', instance => $instance)); $self->{components}->{idepdrive}->{total}++; + $self->{output}->output_add(long_msg => sprintf("ide physical drive %s [status: %s] condition is %s.", $controller_index . ':' . $drive_index, $pdrive_status_map{$pdrive_status}, diff --git a/hardware/server/hpproliant/mode/components/network.pm b/hardware/server/hpproliant/mode/components/network.pm index 0d2f6eefa..7e9773682 100644 --- a/hardware/server/hpproliant/mode/components/network.pm +++ b/hardware/server/hpproliant/mode/components/network.pm @@ -88,8 +88,8 @@ sub physical_nic { # In MIB 'CPQNIC-MIB.mib' $self->{output}->output_add(long_msg => "Checking physical nics"); - $self->{components}->{pnic} = {name => 'physical nics', total => 0}; - return if ($self->check_exclude('pnic')); + $self->{components}->{pnic} = {name => 'physical nics', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'pnic')); my $oid_cpqNicIfPhysAdapterIndex = '.1.3.6.1.4.1.232.18.2.3.1.1.1'; my $oid_cpqNicIfPhysAdapterRole = '.1.3.6.1.4.1.232.18.2.3.1.1.3'; @@ -110,6 +110,9 @@ sub physical_nic { $key =~ /(\d+)$/; my $instance = $1; + next if ($self->check_exclude(section => 'pnic', instance => $instance)); + $self->{components}->{pnic}->{total}++; + my $nic_index = $result->{$key}; my $nic_role = $result2->{$oid_cpqNicIfPhysAdapterRole . '.' . $instance}; my $nic_condition = $result2->{$oid_cpqNicIfPhysAdapterCondition . '.' . $instance}; @@ -117,7 +120,6 @@ sub physical_nic { my $nic_status = $result2->{$oid_cpqNicIfPhysAdapterStatus . '.' . $instance}; my $nic_duplex = $result2->{$oid_cpqNicIfPhysAdapterDuplexState . '.' . $instance}; - $self->{components}->{pnic}->{total}++; $self->{output}->output_add(long_msg => sprintf("physical nic %s [duplex: %s, role: %s, state: %s, status: %s] condition is %s.", $nic_index, $map_nic_duplex{$nic_duplex}, $map_pnic_role{$nic_role}, $map_nic_state{$nic_state}, $map_pnic_status{$nic_status}, @@ -135,8 +137,8 @@ sub logical_nic { # In MIB 'CPQNIC-MIB.mib' $self->{output}->output_add(long_msg => "Checking logical nics"); - $self->{components}->{lnic} = {name => 'logical nics', total => 0}; - return if ($self->check_exclude('lnic')); + $self->{components}->{lnic} = {name => 'logical nics', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'lnic')); my $oid_cpqNicIfLogMapIndex = '.1.3.6.1.4.1.232.18.2.2.1.1.1'; my $oid_cpqNicIfLogMapDescription = '.1.3.6.1.4.1.232.18.2.2.1.1.3'; @@ -155,13 +157,15 @@ sub logical_nic { $key =~ /(\d+)$/; my $instance = $1; + next if ($self->check_exclude(section => 'lnic', instance => $instance)); + $self->{components}->{lnic}->{total}++; + my $nic_index = $result->{$key}; my $nic_description = centreon::plugins::misc::trim($result2->{$oid_cpqNicIfLogMapDescription . '.' . $instance}); my $nic_count = $result2->{$oid_cpqNicIfLogMapAdapterCount . '.' . $instance}; my $nic_condition = $result2->{$oid_cpqNicIfLogMapCondition . '.' . $instance}; my $nic_status = $result2->{$oid_cpqNicIfLogMapStatus . '.' . $instance}; - $self->{components}->{lnic}->{total}++; $self->{output}->output_add(long_msg => sprintf("logical nic %s [adapter count: %s, description: %s, status: %s] condition is %s.", $nic_index, $nic_count, $nic_description, $map_lnic_status{$nic_status}, diff --git a/hardware/server/hpproliant/mode/components/pc.pm b/hardware/server/hpproliant/mode/components/pc.pm index f12c2d0dc..a84f67bed 100644 --- a/hardware/server/hpproliant/mode/components/pc.pm +++ b/hardware/server/hpproliant/mode/components/pc.pm @@ -62,8 +62,8 @@ sub check { # In MIB 'CPQHLTH-MIB.mib' $self->{output}->output_add(long_msg => "Checking power converters"); - $self->{components}->{pc} = {name => 'power converters', total => 0}; - return if ($self->check_exclude('pc')); + $self->{components}->{pc} = {name => 'power converters', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'pc')); my $oid_cpqHePwrConvPresent = '.1.3.6.1.4.1.232.6.2.13.3.1.3'; my $oid_cpqHePwrConvIndex = '.1.3.6.1.4.1.232.6.2.13.3.1.2'; @@ -77,10 +77,12 @@ sub check { my @get_oids = (); my @oids_end = (); foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($present_map{$result->{$key}} ne 'present'); # Chassis + index - $key =~ /(\d+\.\d+)$/; - my $oid_end = $1; + $key =~ /(\d+)\.(\d+)$/; + my $oid_end = $1 . '.' . $2; + + next if ($present_map{$result->{$key}} ne 'present' && + $self->absent_problem(section => 'pc', instance => $1 . '.' . $2)); push @oids_end, $oid_end; push @get_oids, $oid_cpqHePwrConvCondition . "." . $oid_end, $oid_cpqHePwrConvRedundant . "." . $oid_end, @@ -93,7 +95,9 @@ sub check { my $pc_redundant = $result->{$oid_cpqHePwrConvRedundant . '.' . $_}; my $pc_redundantgroup = defined($result->{$oid_cpqHePwrConvRedundantGroupId . '.' . $_}) ? $result->{$oid_cpqHePwrConvRedundantGroupId . '.' . $_} : 'undefined'; + next if ($self->check_exclude(section => 'pc', instance => $pc_chassis . '.' . $pc_index)); $self->{components}->{pc}->{total}++; + $self->{output}->output_add(long_msg => sprintf("powerconverter %d status is %s [chassis: %s, redundance: %s, redundant group: %s].", $pc_index, ${$conditions{$pc_condition}}[0], $pc_chassis, $redundant_map{$pc_redundant}, $pc_redundantgroup diff --git a/hardware/server/hpproliant/mode/components/psu.pm b/hardware/server/hpproliant/mode/components/psu.pm index 53c57dc64..d60e46398 100644 --- a/hardware/server/hpproliant/mode/components/psu.pm +++ b/hardware/server/hpproliant/mode/components/psu.pm @@ -81,8 +81,8 @@ sub check { # In MIB 'CPQHLTH-MIB.mib' $self->{output}->output_add(long_msg => "Checking power supplies"); - $self->{components}->{psu} = {name => 'power supplies', total => 0}; - return if ($self->check_exclude('psu')); + $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'psu')); my $oid_cpqHeFltTolPowerSupplyPresent = '.1.3.6.1.4.1.232.6.2.9.3.1.3'; my $oid_cpqHeFltTolPowerSupplyChassis = '.1.3.6.1.4.1.232.6.2.9.3.1.1'; @@ -100,10 +100,12 @@ sub check { my @get_oids = (); my @oids_end = (); foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($present_map{$result->{$key}} ne 'present'); # Chassis + Bay - $key =~ /(\d+\.\d+)$/; - my $oid_end = $1; + $key =~ /(\d+)\.(\d+)$/; + my $oid_end = $1 . '.' . $2; + + next if ($present_map{$result->{$key}} ne 'present' && + $self->absent_problem(section => 'psu', instance => $1 . '.' . $2)); push @oids_end, $oid_end; push @get_oids, @@ -123,7 +125,9 @@ sub check { my $psu_capacitymaximum = $result->{$oid_cpqHeFltTolPowerSupplyCapacityMaximum . '.' . $_}; my $psu_voltage = $result->{$oid_cpqHeFltTolPowerSupplyMainVoltage . '.' . $_}; + next if ($self->check_exclude(section => 'psu', instance => $psu_chassis . '.' . $psu_bay)); $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("powersupply %d status is %s [chassis: %s, redundance: %s, redundant partner: %s] (status %s).", $psu_bay, ${$conditions{$psu_condition}}[0], $psu_chassis, $redundant_map{$psu_redundant}, $psu_redundantpartner, diff --git a/hardware/server/hpproliant/mode/components/sas.pm b/hardware/server/hpproliant/mode/components/sas.pm index 4f19f90f0..d38f3b71f 100644 --- a/hardware/server/hpproliant/mode/components/sas.pm +++ b/hardware/server/hpproliant/mode/components/sas.pm @@ -79,8 +79,8 @@ sub controller { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking sas controllers"); - $self->{components}->{sasctl} = {name => 'sas controllers', total => 0}; - return if ($self->check_exclude('sasctl')); + $self->{components}->{sasctl} = {name => 'sas controllers', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'sasctl')); my $oid_cpqSasHbaIndex = '.1.3.6.1.4.1.232.5.5.1.1.1.1'; my $oid_cpqSasHbaCondition = '.1.3.6.1.4.1.232.5.5.1.1.1.5'; @@ -101,8 +101,10 @@ sub controller { my $sas_slot = $result2->{$oid_cpqSasHbaSlot . '.' . $instance}; my $sas_condition = $result2->{$oid_cpqSasHbaCondition . '.' . $instance}; my $sas_status = $result2->{$oid_cpqSasHbaStatus . '.' . $instance}; - + + next if ($self->check_exclude(section => 'sasctl', instance => $instance)); $self->{components}->{sasctl}->{total}++; + $self->{output}->output_add(long_msg => sprintf("sas controller %s [slot: %s, status: %s] condition is %s.", $instance, $sas_slot, $controllerstatus_map{$sas_status}, ${$conditions{$sas_condition}}[0])); @@ -118,8 +120,8 @@ sub logical_drive { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking sas logical drives"); - $self->{components}->{sasldrive} = {name => 'sas logical drives', total => 0}; - return if ($self->check_exclude('sasldrive')); + $self->{components}->{sasldrive} = {name => 'sas logical drives', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'sasldrive')); my $oid_cpqSasLogDrvCondition = '.1.3.6.1.4.1.232.5.5.3.1.1.5'; my $oid_cpqSasLogDrvStatusValue = '.1.3.6.1.4.1.232.5.5.3.1.1.4'; @@ -140,7 +142,9 @@ sub logical_drive { my $ldrive_status = $result2->{$oid_cpqSasLogDrvStatusValue . '.' . $instance}; my $ldrive_condition = $result->{$key}; + next if ($self->check_exclude(section => 'sasldrive', instance => $instance)); $self->{components}->{sasldrive}->{total}++; + $self->{output}->output_add(long_msg => sprintf("sas logical drive %s [status: %s] condition is %s.", $controller_index . ':' . $drive_index, $ldrive_status_map{$ldrive_status}, @@ -163,8 +167,8 @@ sub physical_drive { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking sas physical drives"); - $self->{components}->{saspdrive} = {name => 'sas physical drives', total => 0}; - return if ($self->check_exclude('saspdrive')); + $self->{components}->{saspdrive} = {name => 'sas physical drives', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'saspdrive')); my $oid_cpqSasPhyDrvCondition = '.1.3.6.1.4.1.232.5.5.2.1.1.6'; my $oid_cpqSasPhyDrvStatus = '.1.3.6.1.4.1.232.5.5.2.1.1.5'; @@ -184,8 +188,10 @@ sub physical_drive { my $pdrive_status = $result2->{$oid_cpqSasPhyDrvStatus . '.' . $instance}; my $pdrive_condition = $result->{$key}; - + + next if ($self->check_exclude(section => 'saspdrive', instance => $instance)); $self->{components}->{saspdrive}->{total}++; + $self->{output}->output_add(long_msg => sprintf("sas physical drive %s [status: %s] condition is %s.", $controller_index . ':' . $drive_index, $pdrive_status_map{$pdrive_status}, diff --git a/hardware/server/hpproliant/mode/components/scsi.pm b/hardware/server/hpproliant/mode/components/scsi.pm index 0de3be227..febb750f7 100644 --- a/hardware/server/hpproliant/mode/components/scsi.pm +++ b/hardware/server/hpproliant/mode/components/scsi.pm @@ -85,8 +85,8 @@ sub controller { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking scsi controllers"); - $self->{components}->{scsictl} = {name => 'scsi controllers', total => 0}; - return if ($self->check_exclude('scsictl')); + $self->{components}->{scsictl} = {name => 'scsi controllers', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'scsictl')); my $oid_cpqScsiCntlrCondition = '.1.3.6.1.4.1.232.5.2.2.1.1.12'; my $oid_cpqScsiCntlrSlot = '.1.3.6.1.4.1.232.5.2.2.1.1.6'; @@ -109,7 +109,9 @@ sub controller { my $scsi_condition = $result->{$key}; my $scsi_status = $result2->{$oid_cpqScsiCntlrStatus . '.' . $instance}; + next if ($self->check_exclude(section => 'scsictl', instance => $instance)); $self->{components}->{scsictl}->{total}++; + $self->{output}->output_add(long_msg => sprintf("scsi controller %s [slot: %s, status: %s] condition is %s.", $controller_index . ':' . $bus_index, $scsi_slot, $controllerstatus_map{$scsi_status}, ${$conditions{$scsi_condition}}[0])); @@ -125,8 +127,8 @@ sub logical_drive { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking scsi logical drives"); - $self->{components}->{scsildrive} = {name => 'scsi logical drives', total => 0}; - return if ($self->check_exclude('scsildrive')); + $self->{components}->{scsildrive} = {name => 'scsi logical drives', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'scsildrive')); my $oid_cpqScsiLogDrvCondition = '.1.3.6.1.4.1.232.5.2.3.1.1.8'; my $oid_cpqScsiLogDrvStatus = '.1.3.6.1.4.1.232.5.2.3.1.1.5'; @@ -147,8 +149,10 @@ sub logical_drive { my $ldrive_status = $result2->{$oid_cpqScsiLogDrvStatus . '.' . $instance}; my $ldrive_condition = $result->{$key}; - + + next if ($self->check_exclude(section => 'scsildrive', instance => $instance)); $self->{components}->{scsildrive}->{total}++; + $self->{output}->output_add(long_msg => sprintf("scsi logical drive %s [status: %s] condition is %s.", $controller_index . ':' . $bus_index . ':' . $drive_index, $ldrive_status_map{$ldrive_status}, @@ -171,8 +175,8 @@ sub physical_drive { my ($self) = @_; $self->{output}->output_add(long_msg => "Checking scsi physical drives"); - $self->{components}->{scsipdrive} = {name => 'scsi physical drives', total => 0}; - return if ($self->check_exclude('scsipdrive')); + $self->{components}->{scsipdrive} = {name => 'scsi physical drives', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'scsipdrive')); my $oid_cpqScsiPhyDrvCondition = '.1.3.6.1.4.1.232.5.2.4.1.1.26'; my $oid_cpqScsiPhyDrvStatus = '.1.3.6.1.4.1.232.5.2.4.1.1.9'; @@ -193,8 +197,10 @@ sub physical_drive { my $pdrive_status = $result2->{$oid_cpqScsiPhyDrvStatus . '.' . $instance}; my $pdrive_condition = $result->{$key}; - + + next if ($self->check_exclude(section => 'scsipdrive', instance => $instance)); $self->{components}->{scsipdrive}->{total}++; + $self->{output}->output_add(long_msg => sprintf("scsi physical drive %s [status: %s] condition is %s.", $controller_index . ':' . $bus_index . ':' . $drive_index, $pdrive_status_map{$pdrive_status}, diff --git a/hardware/server/hpproliant/mode/components/temperature.pm b/hardware/server/hpproliant/mode/components/temperature.pm index 42ddfb676..fd224454f 100644 --- a/hardware/server/hpproliant/mode/components/temperature.pm +++ b/hardware/server/hpproliant/mode/components/temperature.pm @@ -66,8 +66,8 @@ sub check { # In MIB 'CPQSTDEQ-MIB.mib' $self->{output}->output_add(long_msg => "Checking temperatures"); - $self->{components}->{temperature} = {name => 'temperatures', total => 0}; - return if ($self->check_exclude('temperature')); + $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'temperature')); my $oid_cpqHeTemperatureEntry = '.1.3.6.1.4.1.232.6.2.6.8.1'; my $oid_cpqHeTemperatureCondition = '.1.3.6.1.4.1.232.6.2.6.8.1.6'; @@ -92,7 +92,9 @@ sub check { my $temp_threshold = $result->{$oid_cpqHeTemperatureThreshold . '.' . $instance}; my $temp_locale = $result->{$oid_cpqHeTemperatureLocale . '.' . $instance}; + next if ($self->check_exclude(section => 'temperature', instance => $temp_chassis . '.' . $temp_index)); $self->{components}->{temperature}->{total}++; + $self->{output}->output_add(long_msg => sprintf("%s %s temperature is %dC (%d max) (status is %s).", $temp_index, $location_map{$temp_locale}, $temp_current, $temp_threshold, diff --git a/hardware/server/hpproliant/mode/hardware.pm b/hardware/server/hpproliant/mode/hardware.pm index 49bbd461a..1aa9104d3 100644 --- a/hardware/server/hpproliant/mode/hardware.pm +++ b/hardware/server/hpproliant/mode/hardware.pm @@ -61,19 +61,31 @@ sub new { $options{options}->add_options(arguments => { "exclude:s" => { name => 'exclude' }, + "absent-problem:s" => { name => 'absent' }, "component:s" => { name => 'component', default => 'all' }, + "no-component:s" => { name => 'no_component' }, }); $self->{product_name} = undef; $self->{serial} = undef; $self->{romversion} = undef; $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'; + } + } } sub global { @@ -111,9 +123,9 @@ sub global { 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}; + next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); + $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name}; $display_by_component_append = ', '; } @@ -123,6 +135,11 @@ sub global { $display_by_component, $self->{product_name}, $self->{serial}, $self->{romversion}) ); + + if (defined($self->{option_results}->{no_component}) && $total_components == 0) { + $self->{output}->output_add(severity => $self->{no_components}, + short_msg => 'No components are checked.'); + } } sub component { @@ -170,9 +187,9 @@ sub 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}; + next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); + $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; + $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name}; $display_by_component_append = ', '; } @@ -181,6 +198,11 @@ sub component { $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.'); + } } sub run { @@ -214,15 +236,36 @@ sub get_system_information { } sub check_exclude { - my ($self, $section) = @_; + my ($self, %options) = @_; - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$section(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $section section.")); + 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; +} + 1; __END__ @@ -240,9 +283,19 @@ Can be: 'cpu', 'psu', 'pc', 'fan', 'network', 'temperature', 'storage'. =item B<--exclude> -Exclude some parts (comma seperated list) (Example: --exclude=psu,pc). +Exclude some parts (comma seperated list) (Example: --exclude=fans,modules) +Can also exclude specific instance: --exclude=fans#1.2#,lnic#1#,psus + +=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=fans#1.2#,psus + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). =back -=cut - \ No newline at end of file +=cut \ No newline at end of file diff --git a/os/solaris/local/mode/svmdisks.pm b/os/solaris/local/mode/svmdisks.pm index 0df3d9313..32f86e1fe 100644 --- a/os/solaris/local/mode/svmdisks.pm +++ b/os/solaris/local/mode/svmdisks.pm @@ -58,7 +58,7 @@ sub new { "sudo1" => { name => 'sudo1' }, "command1:s" => { name => 'command1', default => 'metastat' }, "command1-path:s" => { name => 'command1_path', default => '/usr/sbin' }, - "command1-options:s" => { name => 'command1_options', default => '-c 2>&1' }, + "command1-options:s" => { name => 'command1_options', default => '2>&1' }, "sudo2" => { name => 'sudo2' }, "command2:s" => { name => 'command2', default => 'metadb' }, "command2-path:s" => { name => 'command2_path', default => '/usr/sbin' }, @@ -108,20 +108,43 @@ sub run { my $num_metastat_errors = 0; my $metastat_name = ''; - foreach (split(/\n/, $stdout)) { - #d1 m 10.0GB d11 d12 (maint) - # d11 s 10.0GB /dev/dsk/c5t600A0B80002929FC0000842E5251EE71d0s6 - # d12 s 10.0GB /dev/dsk/c5t600A0B800011978E000026D95251FEF1d0s6 (maint) - #d5 r 4.0GB /dev/dsk/c5t600A0B80002929FC000084305251EFADd0s6 /dev/dsk/c5t600A0B800011978E000026DC52520043d0s6 /dev/dsk/c5t600A0B800011978E000026E25252811Ad0s6 + foreach my $disk_info (split(/(?=d\d+:)/, $stdout)) { + #d5: Mirror + # Submirror 0: d15 + # State: Okay + # Submirror 1: d25 + # State: Okay + # Pass: 1 + # Read option: roundrobin (default) + # Write option: parallel (default) + # Size: 525798 blocks # - # Only need to check 's' (stripping) and 'r' (raid). 'm' (mirror) is (maint) because of 's' is (maint) + #d15: Submirror of d5 + # State: Okay + # Size: 525798 blocks + # Stripe 0: + # Device Start Block Dbase State Reloc Hot Spare + # c0t0d0s5 0 No Okay Yes + # + # + #d25: Submirror of d5 + # State: Okay + # Size: 525798 blocks + # Stripe 0: + # Device Start Block Dbase State Reloc Hot Spare + # c0t1d0s5 0 No Okay Yes - if (/^\s*(\S+)\s+(s|r)\s+\S+\s+(.*?)\(maint\)/i ) { - my $name = $1; - my $disks = $3; - $disks = trim($disks); - $num_metastat_errors++; - $metastat_name .= ' [' . $name . ' (' . $disks . ')]'; + my @lines = split("\n",$disk_info); + my @line1 = split(/:/, $lines[0]); + my $disk = $line1[0]; + my $type = $line1[1]; + $type =~ s/^\s*(.*)\s*$/$1/; + #$type =~ s/\s+//g; + foreach my $line (@lines) { + if ($line =~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s+Maint\S*\s+(.*?)$/i) { + $num_metastat_errors++; + $metastat_name .= ' [' . $1 . ' (' . $disk . ')][' . $type . ']'; + } } } @@ -238,7 +261,7 @@ Command path (Default: '/usr/sbin'). =item B<--command1-options> -Command options (Default: '-c 2>&1'). +Command options (Default: '2>&1'). =item B<--sudo2>