diff --git a/hardware/server/hp/bladechassis/snmp/mode/components/blade.pm b/hardware/server/hp/bladechassis/snmp/mode/components/blade.pm index 6d43fa175..b697fbe54 100644 --- a/hardware/server/hp/bladechassis/snmp/mode/components/blade.pm +++ b/hardware/server/hp/bladechassis/snmp/mode/components/blade.pm @@ -38,11 +38,11 @@ package hardware::server::hp::bladechassis::snmp::mode::components::blade; use strict; use warnings; -my %conditions = ( - 1 => ['other', 'CRITICAL'], - 2 => ['ok', 'OK'], - 3 => ['degraded', 'WARNING'], - 4 => ['failed', 'CRITICAL'], +my %map_conditions = ( + 1 => 'other', + 2 => 'ok', + 3 => 'degraded', + 4 => 'failed', ); my %present_map = ( @@ -55,9 +55,9 @@ my %present_map = ( sub check { my ($self) = @_; - $self->{components}->{blades} = {name => 'blades', total => 0}; + $self->{components}->{blade} = {name => 'blades', total => 0, skip => 0}; $self->{output}->output_add(long_msg => "Checking blades"); - return if ($self->check_exclude('blades')); + return if ($self->check_exclude(section => 'blade')); my $oid_cpqRackServerBladePresent = '.1.3.6.1.4.1.232.22.2.4.1.1.1.12'; my $oid_cpqRackServerBladeIndex = '.1.3.6.1.4.1.232.22.2.4.1.1.1.3'; @@ -72,11 +72,13 @@ sub check { return if (scalar(keys %$result) <= 0); my @get_oids = (); my @oids_end = (); - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($present_map{$result->{$key}} ne 'present'); + foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { $key =~ /\.([0-9]+)$/; my $oid_end = $1; + next if ($present_map{$result->{$key}} ne 'present' && + $self->absent_problem(section => 'blade', instance => $oid_end)); + push @oids_end, $oid_end; push @get_oids, $oid_cpqRackServerBladeIndex . "." . $oid_end, $oid_cpqRackServerBladeName . "." . $oid_end, $oid_cpqRackServerBladePartNumber . "." . $oid_end, $oid_cpqRackServerBladeSparePartNumber . "." . $oid_end, @@ -94,23 +96,27 @@ sub check { my $blade_productid = $result->{$oid_cpqRackServerBladeProductId . '.' . $_}; my $blade_diago = defined($result->{$oid_cpqRackServerBladeFaultDiagnosticString . '.' . $_}) ? $result->{$oid_cpqRackServerBladeFaultDiagnosticString . '.' . $_} : ''; - $self->{components}->{blades}->{total}++; + next if ($self->check_exclude(section => 'blade', instance => $blade_index)); + + $self->{components}->{blade}->{total}++; if ($blade_status eq '') { $self->{output}->output_add(long_msg => sprintf("Skipping Blade %d (%s, %s). Cant get status.", $blade_index, $blade_name, $blade_productid)); next; } + $self->{output}->output_add(long_msg => sprintf("Blade %d (%s, %s) status is %s [part: %s, spare: %s]%s.", $blade_index, $blade_name, $blade_productid, - ${$conditions{$blade_status}}[0], + $map_conditions{$blade_status}, $blade_part, $blade_spare, ($blade_diago ne '') ? " (Diagnostic '$blade_diago')" : '' )); - if ($blade_status != 2) { - $self->{output}->output_add(severity => ${$conditions{$blade_status}}[1], + my $exit = $self->get_severity(section => 'blade', value => $map_conditions{$blade_status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("Blade %d (%s, %s) status is %s", $blade_index, $blade_name, $blade_productid, - ${$conditions{$blade_status}}[0] + $map_conditions{$blade_status} )); } } diff --git a/hardware/server/hp/bladechassis/snmp/mode/components/enclosure.pm b/hardware/server/hp/bladechassis/snmp/mode/components/enclosure.pm index 9093e8e94..38279f06d 100644 --- a/hardware/server/hp/bladechassis/snmp/mode/components/enclosure.pm +++ b/hardware/server/hp/bladechassis/snmp/mode/components/enclosure.pm @@ -38,11 +38,11 @@ package hardware::server::hp::bladechassis::snmp::mode::components::enclosure; use strict; use warnings; -my %conditions = ( - 1 => ['other', 'CRITICAL'], - 2 => ['ok', 'OK'], - 3 => ['degraded', 'WARNING'], - 4 => ['failed', 'CRITICAL'], +my %map_conditions = ( + 1 => 'other', + 2 => 'ok', + 3 => 'degraded', + 4 => 'failed', ); sub check { @@ -59,14 +59,15 @@ sub check { $oid_cpqRackCommonEnclosureCondition], nothing_quit => 1); $self->{output}->output_add(long_msg => sprintf("Enclosure overall health condition is %s [part: %s, spare: %s, sn: %s, fw: %s].", - ${$conditions{$result->{$oid_cpqRackCommonEnclosureCondition}}}[0], + $map_conditions{$result->{$oid_cpqRackCommonEnclosureCondition}}, $result->{$oid_cpqRackCommonEnclosurePartNumber}, $result->{$oid_cpqRackCommonEnclosureSparePartNumber}, $result->{$oid_cpqRackCommonEnclosureSerialNum}, $result->{$oid_cpqRackCommonEnclosureFWRev})); - if ($result->{$oid_cpqRackCommonEnclosureCondition} != 2) { - $self->{output}->output_add(severity => ${$conditions{$result->{$oid_cpqRackCommonEnclosureCondition}}}[1], - short_msg => sprintf("Enclosure overall health condition is %s", ${$conditions{$result->{$oid_cpqRackCommonEnclosureCondition}}}[0])); + my $exit = $self->get_severity(section => 'enclosure', value => $map_conditions{$result->{$oid_cpqRackCommonEnclosureCondition}}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Enclosure overall health condition is %s", $map_conditions{$result->{$oid_cpqRackCommonEnclosureCondition}})); } } diff --git a/hardware/server/hp/bladechassis/snmp/mode/components/fan.pm b/hardware/server/hp/bladechassis/snmp/mode/components/fan.pm index ee94f5c7c..c5e85b01d 100644 --- a/hardware/server/hp/bladechassis/snmp/mode/components/fan.pm +++ b/hardware/server/hp/bladechassis/snmp/mode/components/fan.pm @@ -38,11 +38,11 @@ package hardware::server::hp::bladechassis::snmp::mode::components::fan; use strict; use warnings; -my %conditions = ( - 1 => ['other', 'CRITICAL'], - 2 => ['ok', 'OK'], - 3 => ['degraded', 'WARNING'], - 4 => ['failed', 'CRITICAL'], +my %map_conditions = ( + 1 => 'other', + 2 => 'ok', + 3 => 'degraded', + 4 => 'failed', ); my %present_map = ( @@ -55,9 +55,9 @@ my %present_map = ( sub check { my ($self) = @_; - $self->{components}->{fans} = {name => 'fans', total => 0}; + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; $self->{output}->output_add(long_msg => "Checking fans"); - return if ($self->check_exclude('fans')); + return if ($self->check_exclude(section => 'fan')); my $oid_cpqRackCommonEnclosureFanPresent = '.1.3.6.1.4.1.232.22.2.3.1.3.1.8'; my $oid_cpqRackCommonEnclosureFanIndex = '.1.3.6.1.4.1.232.22.2.3.1.3.1.3'; @@ -70,14 +70,17 @@ 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'); $key =~ /\.([0-9]+)$/; my $oid_end = $1; + next if ($present_map{$result->{$key}} ne 'present' && + $self->absent_problem(section => 'fan', instance => $oid_end)); + push @oids_end, $oid_end; push @get_oids, $oid_cpqRackCommonEnclosureFanIndex . "." . $oid_end, $oid_cpqRackCommonEnclosureFanPartNumber . "." . $oid_end, $oid_cpqRackCommonEnclosureFanSparePartNumber . "." . $oid_end, $oid_cpqRackCommonEnclosureFanCondition . "." . $oid_end; } + $result = $self->{snmp}->get_leef(oids => \@get_oids); foreach (@oids_end) { my $fan_index = $result->{$oid_cpqRackCommonEnclosureFanIndex . '.' . $_}; @@ -85,13 +88,15 @@ sub check { my $fan_part = $result->{$oid_cpqRackCommonEnclosureFanPartNumber . '.' . $_}; my $fan_spare = $result->{$oid_cpqRackCommonEnclosureFanSparePartNumber . '.' . $_}; - $self->{components}->{fans}->{total}++; + next if ($self->check_exclude(section => 'fan', instance => $fan_index)); + $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => sprintf("Fan %d condition is %s [part: %s, spare: %s].", - $fan_index, ${$conditions{$fan_condition}}[0], + $fan_index, $map_conditions{$fan_condition}, $fan_part, $fan_spare)); - if ($fan_condition != 2) { - $self->{output}->output_add(severity => ${$conditions{$fan_condition}}[1], - short_msg => sprintf("Fan %d condition is %s", $fan_index, ${$conditions{$fan_condition}}[0])); + my $exit = $self->get_severity(section => 'fan', value => $map_conditions{$fan_condition}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan %d condition is %s", $fan_index, $map_conditions{$fan_condition})); } } } diff --git a/hardware/server/hp/bladechassis/snmp/mode/components/fuse.pm b/hardware/server/hp/bladechassis/snmp/mode/components/fuse.pm index 130a96865..1245f134f 100644 --- a/hardware/server/hp/bladechassis/snmp/mode/components/fuse.pm +++ b/hardware/server/hp/bladechassis/snmp/mode/components/fuse.pm @@ -38,11 +38,11 @@ package hardware::server::hp::bladechassis::snmp::mode::components::fuse; use strict; use warnings; -my %conditions = ( - 1 => ['other', 'CRITICAL'], - 2 => ['ok', 'OK'], - 3 => ['degraded', 'WARNING'], - 4 => ['failed', 'CRITICAL'], +my %map_conditions = ( + 1 => 'other', + 2 => 'ok', + 3 => 'degraded', + 4 => 'failed', ); my %present_map = ( @@ -55,9 +55,9 @@ my %present_map = ( sub check { my ($self) = @_; - $self->{components}->{fuses} = {name => 'fuses', total => 0}; + $self->{components}->{fuse} = {name => 'fuses', total => 0, skip => 0}; $self->{output}->output_add(long_msg => "Checking fuse"); - return if ($self->check_exclude('fuse')); + return if ($self->check_exclude(section => 'fuse')); my $oid_cpqRackCommonEnclosureFusePresent = '.1.3.6.1.4.1.232.22.2.3.1.4.1.6'; my $oid_cpqRackCommonEnclosureFuseIndex = '.1.3.6.1.4.1.232.22.2.3.1.4.1.3'; @@ -70,10 +70,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'); $key =~ /\.([0-9]+)$/; my $oid_end = $1; + next if ($present_map{$result->{$key}} ne 'present' && + $self->absent_problem(section => 'fuse', instance => $oid_end)); + push @oids_end, $oid_end; push @get_oids, $oid_cpqRackCommonEnclosureFuseIndex . "." . $oid_end, $oid_cpqRackCommonEnclosureFuseEnclosureName . "." . $oid_end, $oid_cpqRackCommonEnclosureFuseLocation . "." . $oid_end, $oid_cpqRackCommonEnclosureFuseCondition . "." . $oid_end; @@ -85,14 +87,17 @@ sub check { my $fuse_location = $result->{$oid_cpqRackCommonEnclosureFuseLocation . '.' . $_}; my $fuse_condition = $result->{$oid_cpqRackCommonEnclosureFuseCondition . '.' . $_}; - $self->{components}->{fuses}->{total}++; + next if ($self->check_exclude(section => 'fuse', instance => $fuse_index)); + + $self->{components}->{fuse}->{total}++; $self->{output}->output_add(long_msg => sprintf("Fuse %d status is %s [name: %s, location: %s].", - $fuse_index, ${$conditions{$fuse_condition}}[0], + $fuse_index, $map_conditions{$fuse_condition}, $fuse_name, $fuse_location)); - if ($fuse_condition != 2) { - $self->{output}->output_add(severity => ${$conditions{$fuse_condition}}[1], + my $exit = $self->get_severity(section => 'fuse', value => $map_conditions{$fuse_condition}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("Fuse %d status is %s", - $fuse_index, ${$conditions{$fuse_condition}}[0])); + $fuse_index, $map_conditions{$fuse_condition})); } } } diff --git a/hardware/server/hp/bladechassis/snmp/mode/components/manager.pm b/hardware/server/hp/bladechassis/snmp/mode/components/manager.pm index 82404697e..512807b44 100644 --- a/hardware/server/hp/bladechassis/snmp/mode/components/manager.pm +++ b/hardware/server/hp/bladechassis/snmp/mode/components/manager.pm @@ -38,6 +38,14 @@ package hardware::server::hp::bladechassis::snmp::mode::components::manager; use strict; use warnings; +my %map_conditions = ( + 0 => 'other', # maybe on standby mode only!! + 1 => 'other', + 2 => 'ok', + 3 => 'degraded', + 4 => 'failed', +); + my %conditions = ( 0 => ['other', 'UNKNOWN'], # maybe on standby mode only!! 1 => ['other', 'CRITICAL'], @@ -45,6 +53,7 @@ my %conditions = ( 3 => ['degraded', 'WARNING'], 4 => ['failed', 'CRITICAL'], ); + my %map_role = ( 1 => 'Standby', 2 => 'Active', @@ -53,8 +62,8 @@ my %map_role = ( sub check { my ($self, %options) = @_; - $self->{components}->{managers} = {name => 'managers', total => 0}; - return if ($self->check_exclude('managers')); + $self->{components}->{manager} = {name => 'managers', total => 0, skip => 0}; + return if ($self->check_exclude(section => 'manager')); # No check if OK if ((!defined($options{force}) || $options{force} != 1) && $self->{output}->is_status(compare => 'ok', litteral => 1)) { @@ -87,14 +96,17 @@ sub check { my $man_role = $result2->{$oid_cpqRackCommonEnclosureManagerRole . '.' . $instance}; my $man_condition = $result2->{$oid_cpqRackCommonEnclosureManagerCondition . '.' . $instance}; - $self->{components}->{managers}->{total}++; + next if ($self->check_exclude(section => 'manager', instance => $instance)); + + $self->{components}->{manager}->{total}++; $self->{output}->output_add(long_msg => sprintf("Enclosure management module %d is %s, status is %s [serial: %s, part: %s, spare: %s].", - $instance, ${$conditions{$man_condition}}[0], $map_role{$man_role}, + $instance, $map_conditions{$man_condition}, $map_role{$man_role}, $man_serial, $man_part, $man_spare)); - if ($man_role == 2 && $man_condition != 2) { - $self->{output}->output_add(severity => ${$conditions{$man_condition}}[1], + my $exit = $self->get_severity(section => 'manager', value => $map_conditions{$man_condition}); + if ($man_role == 2 && !$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("Enclosure management module %d is %s, status is %s", - $instance, ${$conditions{$man_condition}}[0], $map_role{$man_role})); + $instance, $map_conditions{$man_condition}, $map_role{$man_role})); } } } diff --git a/hardware/server/hp/bladechassis/snmp/mode/components/network.pm b/hardware/server/hp/bladechassis/snmp/mode/components/network.pm index 86ef49ac2..36267fbad 100644 --- a/hardware/server/hp/bladechassis/snmp/mode/components/network.pm +++ b/hardware/server/hp/bladechassis/snmp/mode/components/network.pm @@ -57,9 +57,9 @@ my %device_type = ( sub check { my ($self) = @_; - $self->{components}->{network} = {name => 'network connectors', total => 0}; + $self->{components}->{network} = {name => 'network connectors', total => 0, skip => 0}; $self->{output}->output_add(long_msg => "Checking network connectors"); - return if ($self->check_exclude('network')); + return if ($self->check_exclude(section => 'network')); my $oid_cpqRackNetConnectorPresent = '.1.3.6.1.4.1.232.22.2.6.1.1.1.13'; my $oid_cpqRackNetConnectorIndex = '.1.3.6.1.4.1.232.22.2.6.1.1.1.3'; @@ -92,6 +92,8 @@ sub check { my $nc_spare = $result->{$oid_cpqRackNetConnectorSparePartNumber . '.' . $_}; my $nc_device = $result->{$oid_cpqRackNetConnectorDeviceType . '.' . $_}; + next if ($self->check_exclude(section => 'network', instance => $nc_index)); + $self->{components}->{network}->{total}++; $self->{output}->output_add(long_msg => sprintf("Network Connector %d (%s) type '%s' is present [serial: %s, part: %s, spare: %s].", $nc_index, $nc_model, diff --git a/hardware/server/hp/bladechassis/snmp/mode/components/psu.pm b/hardware/server/hp/bladechassis/snmp/mode/components/psu.pm index c7840bc1b..5e13bb6e1 100644 --- a/hardware/server/hp/bladechassis/snmp/mode/components/psu.pm +++ b/hardware/server/hp/bladechassis/snmp/mode/components/psu.pm @@ -38,11 +38,11 @@ package hardware::server::hp::bladechassis::snmp::mode::components::psu; use strict; use warnings; -my %conditions = ( - 1 => ['other', 'CRITICAL'], - 2 => ['ok', 'OK'], - 3 => ['degraded', 'WARNING'], - 4 => ['failed', 'CRITICAL'], +my %map_conditions = ( + 1 => 'other', + 2 => 'ok', + 3 => 'degraded', + 4 => 'failed', ); my %present_map = ( @@ -85,9 +85,9 @@ sub check { # We dont check 'cpqRackPowerEnclosureTable' (the overall power system status) # We check 'cpqRackPowerSupplyTable' (unitary) - $self->{components}->{psu} = {name => 'power supplies', total => 0}; + $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0}; $self->{output}->output_add(long_msg => "Checking power supplies"); - return if ($self->check_exclude('psu')); + return if ($self->check_exclude(section => 'psu')); my $oid_cpqRackPowerSupplyPresent = '.1.3.6.1.4.1.232.22.2.5.1.1.1.16'; my $oid_cpqRackPowerSupplyIndex = '.1.3.6.1.4.1.232.22.2.5.1.1.1.3'; @@ -106,10 +106,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'); $key =~ /\.([0-9]+)$/; my $oid_end = $1; + next if ($present_map{$result->{$key}} ne 'present' && + $self->absent_problem(section => 'psu', instance => $oid_end)); + push @oids_end, $oid_end; push @get_oids, $oid_cpqRackPowerSupplyIndex . "." . $oid_end, $oid_cpqRackPowerSupplySerialNum . "." . $oid_end, $oid_cpqRackPowerSupplyPartNumber . "." . $oid_end, $oid_cpqRackPowerSupplySparePartNumber . "." . $oid_end, @@ -131,18 +133,22 @@ sub check { my $psu_intemp = $result->{$oid_cpqRackPowerSupplyIntakeTemp . '.' . $_}; my $psu_exhtemp = $result->{$oid_cpqRackPowerSupplyExhaustTemp . '.' . $_}; + next if ($self->check_exclude(section => 'psu', instance => $psu_index)); + $total_watts += $psu_pwrout; $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("PSU %d status is %s [serial: %s, part: %s, spare: %s] (input line status %s) (status %s).", - $psu_index, ${$conditions{$psu_condition}}[0], + $psu_index, $map_conditions{$psu_condition}, $psu_serial, $psu_part, $psu_spare, $inputline_status_map{$psu_inputlinestatus}, $psu_status_map{$psu_status} )); - if ($psu_condition != 2) { - $self->{output}->output_add(severity => ${$conditions{$psu_condition}}[1], + + my $exit = $self->get_severity(section => 'psu', value => $map_conditions{$psu_condition}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("PSU %d status is %s", - $psu_index, ${$conditions{$psu_condition}}[0])); + $psu_index, $map_conditions{$psu_condition})); } $self->{output}->perfdata_add(label => "psu_" . $psu_index . "_power", unit => 'W', diff --git a/hardware/server/hp/bladechassis/snmp/mode/components/temperature.pm b/hardware/server/hp/bladechassis/snmp/mode/components/temperature.pm index aa5dc5803..1a5a74e1b 100644 --- a/hardware/server/hp/bladechassis/snmp/mode/components/temperature.pm +++ b/hardware/server/hp/bladechassis/snmp/mode/components/temperature.pm @@ -38,11 +38,11 @@ package hardware::server::hp::bladechassis::snmp::mode::components::temperature; use strict; use warnings; -my %conditions = ( - 1 => ['other', 'CRITICAL'], - 2 => ['ok', 'OK'], - 3 => ['degraded', 'WARNING'], - 4 => ['failed', 'CRITICAL'], +my %map_conditions = ( + 1 => 'other', + 2 => 'ok', + 3 => 'degraded', + 4 => 'failed', ); my %present_map = ( @@ -62,9 +62,9 @@ my %map_temp_type = ( sub check { my ($self) = @_; - $self->{components}->{temperatures} = {name => 'temperatures', total => 0}; + $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; $self->{output}->output_add(long_msg => "Checking temperatures"); - return if ($self->check_exclude('temperatures')); + return if ($self->check_exclude(section => 'temperature')); my $oid_cpqRackCommonEnclosureTempSensorIndex = '.1.3.6.1.4.1.232.22.2.3.1.2.1.3'; my $oid_cpqRackCommonEnclosureTempSensorEnclosureName = '.1.3.6.1.4.1.232.22.2.3.1.2.1.4'; @@ -77,31 +77,40 @@ sub check { my $result = $self->{snmp}->get_table(oid => $oid_cpqRackCommonEnclosureTempSensorIndex); return if (scalar(keys %$result) <= 0); - my $result2 = $self->{snmp}->get_leef(oids => [$oid_cpqRackCommonEnclosureTempSensorEnclosureName, + $self->{snmp}->load(oids => [$oid_cpqRackCommonEnclosureTempSensorEnclosureName, $oid_cpqRackCommonEnclosureTempLocation, $oid_cpqRackCommonEnclosureTempCurrent, $oid_cpqRackCommonEnclosureTempThreshold, $oid_cpqRackCommonEnclosureTempCondition, $oid_cpqRackCommonEnclosureTempType], instances => [keys %$result]); + my $result2 = $self->{snmp}->get_leef(); foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - $key =~ /(\d+)$/; + $key =~ /\.(\d+)$/; my $temp_index = $1; - my $temp_name = $result->{$oid_cpqRackCommonEnclosureTempSensorEnclosureName . '.' . $temp_index}; - my $temp_location = $result->{$oid_cpqRackCommonEnclosureTempLocation . '.' . $temp_index}; - my $temp_current = $result->{$oid_cpqRackCommonEnclosureTempCurrent . '.' . $temp_index}; - my $temp_threshold = $result->{$oid_cpqRackCommonEnclosureTempThreshold . '.' . $temp_index}; - my $temp_condition = $result->{$oid_cpqRackCommonEnclosureTempCondition . '.' . $temp_index}; - my $temp_type = $result->{$oid_cpqRackCommonEnclosureTempType . '.' . $temp_index}; + my $temp_name = $result2->{$oid_cpqRackCommonEnclosureTempSensorEnclosureName . '.' . $temp_index}; + my $temp_location = $result2->{$oid_cpqRackCommonEnclosureTempLocation . '.' . $temp_index}; + my $temp_current = $result2->{$oid_cpqRackCommonEnclosureTempCurrent . '.' . $temp_index}; + my $temp_threshold = $result2->{$oid_cpqRackCommonEnclosureTempThreshold . '.' . $temp_index}; + my $temp_condition = $result2->{$oid_cpqRackCommonEnclosureTempCondition . '.' . $temp_index}; + my $temp_type = $result2->{$oid_cpqRackCommonEnclosureTempType . '.' . $temp_index}; - $self->{components}->{temperatures}->{total}++; + if ($temp_current == -1) { + $self->{output}->output_add(long_msg => sprintf("Skipping instance $temp_index: current -1")); + next; + } + + next if ($self->check_exclude(section => 'temperature', instance => $temp_index)); + + $self->{components}->{temperature}->{total}++; $self->{output}->output_add(long_msg => sprintf("Temperature %d status is %s [name: %s, location: %s] (value = %s, threshold = %s%s).", - $temp_index, ${$conditions{$temp_condition}}[0], + $temp_index, $map_conditions{$temp_condition}, $temp_name, $temp_location, $temp_current, $temp_threshold, defined($map_temp_type{$temp_type}) ? ", status type = " . $map_temp_type{$temp_type} : '')); - if ($temp_condition != 2) { - $self->{output}->output_add(severity => ${$conditions{$temp_condition}}[1], + my $exit = $self->get_severity(section => 'temperature', value => $map_conditions{$temp_condition}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("Temperature %d status is %s", - $temp_index, ${$conditions{$temp_condition}}[0])); + $temp_index, $map_conditions{$temp_condition})); } $self->{output}->perfdata_add(label => "temp_" . $temp_index, unit => 'C', @@ -110,4 +119,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/hardware/server/hp/bladechassis/snmp/mode/hardware.pm b/hardware/server/hp/bladechassis/snmp/mode/hardware.pm index 424851d48..388dd6277 100644 --- a/hardware/server/hp/bladechassis/snmp/mode/hardware.pm +++ b/hardware/server/hp/bladechassis/snmp/mode/hardware.pm @@ -48,6 +48,51 @@ use hardware::server::hp::bladechassis::snmp::mode::components::psu; use hardware::server::hp::bladechassis::snmp::mode::components::temperature; use hardware::server::hp::bladechassis::snmp::mode::components::fuse; +my $thresholds = { + temperature => [ + ['other', 'CRITICAL'], + ['ok', 'OK'], + ['degraded', 'WARNING'], + ['failed', 'CRITICAL'], + ], + blade => [ + ['other', 'CRITICAL'], + ['ok', 'OK'], + ['degraded', 'WARNING'], + ['failed', 'CRITICAL'], + ], + enclosure => [ + ['other', 'CRITICAL'], + ['ok', 'OK'], + ['degraded', 'WARNING'], + ['failed', 'CRITICAL'], + ], + fan => [ + ['other', 'CRITICAL'], + ['ok', 'OK'], + ['degraded', 'WARNING'], + ['failed', 'CRITICAL'], + ], + fuse => [ + ['other', 'CRITICAL'], + ['ok', 'OK'], + ['degraded', 'WARNING'], + ['failed', 'CRITICAL'], + ], + manager => [ + ['other', 'CRITICAL'], + ['ok', 'OK'], + ['degraded', 'WARNING'], + ['failed', 'CRITICAL'], + ], + psu => [ + ['other', 'CRITICAL'], + ['ok', 'OK'], + ['degraded', 'WARNING'], + ['failed', 'CRITICAL'], + ], +}; + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -56,16 +101,42 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, + "exclude:s" => { name => 'exclude' }, + "absent-problem:s" => { name => 'absent' }, + "component:s" => { name => 'component', default => 'all' }, + "no-component:s" => { name => 'no_component' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, }); $self->{components} = {}; + $self->{no_components} = undef; return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); + + $self->{overload_th} = {}; + foreach my $val (@{$self->{option_results}->{threshold_overload}}) { + if ($val !~ /^(.*?),(.*?),(.*)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong treshold-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 treshold-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}; + } + 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 { @@ -114,33 +185,80 @@ sub run { 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 = ', '; } $self->{output}->output_add(severity => 'OK', short_msg => sprintf("All %s components [%s] are ok.", $total_components, - $display_by_component - ) + $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, $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; +} + +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__ @@ -158,7 +276,24 @@ Can be: 'enclosure', 'manager', 'fan', 'blade', 'network', 'psu', 'temperature', =item B<--exclude> -Exclude some parts (comma seperated list) (Example: --exclude=temperatures,psu). +Exclude some parts (comma seperated list) (Example: --exclude=temperature,psu). +Can also exclude specific instance: --exclude=temperature#1# + +=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=blade#12# + +=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,OK,other' =back