diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/blade.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/blade.pm index 37466b844..ba0c43552 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/blade.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/blade.pm @@ -37,7 +37,7 @@ package hardware::server::cisco::ucs::mode::components::blade; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%presence %operability); +use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); sub check { my ($self) = @_; @@ -70,10 +70,11 @@ sub check { next if ($self->absent_problem(section => 'blade', instance => $blade_dn)); next if ($self->check_exclude(section => 'blade', instance => $blade_dn)); - if (${$presence{$blade_presence}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$presence{$blade_presence}}[1], + my $exit = $self->get_severity(section => 'blade', threshold => 'presence', value => $blade_presence); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("blade '%s' presence is: '%s'", - $blade_dn, ${$presence{$blade_presence}}[0]) + $blade_dn, ${$thresholds->{presence}{$blade_presence}}[0]) ); next; } @@ -81,13 +82,14 @@ sub check { $self->{components}->{blade}->{total}++; $self->{output}->output_add(long_msg => sprintf("blade '%s' state is '%s' [presence: %s].", - $blade_dn, ${$operability{$blade_operstate}}[0], - ${$presence{$blade_presence}}[0] + $blade_dn, ${$thresholds->{operability}->{$blade_operstate}}[0], + ${$thresholds->{presence}->{$blade_presence}}[0] )); - if (${$operability{$blade_operstate}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$operability{$blade_operstate}}[1], + $exit = $self->get_severity(section => 'blade', threshold => 'operability', value => $blade_operstate); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("blade '%s' state is '%s'.", - $blade_dn, ${$operability{$blade_operstate}}[0] + $blade_dn, ${$thresholds->{operability}->{$blade_operstate}}[0] ) ); } diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/chassis.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/chassis.pm index 9077efcfd..74a8ca54d 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/chassis.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/chassis.pm @@ -37,7 +37,7 @@ package hardware::server::cisco::ucs::mode::components::chassis; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%presence %operability); +use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); sub check { my ($self) = @_; @@ -70,12 +70,13 @@ sub check { $self->{components}->{chassis}->{total}++; $self->{output}->output_add(long_msg => sprintf("chassis '%s' state is '%s'.", - $chassis_dn, ${$operability{$chassis_operstate}}[0], + $chassis_dn, ${$thresholds->{presence}->{$chassis_operstate}}[0] )); - if (${$operability{$chassis_operstate}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$operability{$chassis_operstate}}[1], + my $exit = $self->get_severity(section => 'chassis', threshold => 'operability', value => $chassis_operstate); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("chassis '%s' state is '%s'.", - $chassis_dn, ${$operability{$chassis_operstate}}[0] + $chassis_dn, ${$thresholds->{operability}->{$chassis_operstate}}[0] ) ); } diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/fan.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/fan.pm index dd23605ae..de907908b 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/fan.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/fan.pm @@ -37,7 +37,7 @@ package hardware::server::cisco::ucs::mode::components::fan; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%presence %operability); +use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); sub check { my ($self) = @_; @@ -70,24 +70,25 @@ sub check { next if ($self->absent_problem(section => 'fan', instance => $fan_dn)); next if ($self->check_exclude(section => 'fan', instance => $fan_dn)); - if (${$presence{$fan_presence}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$presence{$fan_presence}}[1], + my $exit = $self->get_severity(section => 'fan', threshold => 'presence', value => $fan_presence); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("fan '%s' presence is: '%s'", - $fan_dn, ${$presence{$fan_presence}}[0]) + $fan_dn, ${$thresholds->{presence}->{$fan_presence}}[0]) ); next; } - $self->{components}->{fan}->{total}++; - + $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => sprintf("fan '%s' state is '%s' [presence: %s].", - $fan_dn, ${$operability{$fan_operstate}}[0], - ${$presence{$fan_presence}}[0] + $fan_dn, ${$thresholds->{operability}->{$fan_operstate}}[0], + ${$thresholds->{presence}->{$fan_presence}}[0] )); - if (${$operability{$fan_operstate}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$operability{$fan_operstate}}[1], + $exit = $self->get_severity(section => 'fan', threshold => 'operability', value => $fan_operstate); + 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'.", - $fan_dn, ${$operability{$fan_operstate}}[0] + $fan_dn, ${$thresholds->{operability}->{$fan_operstate}}[0] ) ); } diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/iocard.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/iocard.pm index 9f585a2d9..8e8b86b65 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/iocard.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/iocard.pm @@ -37,7 +37,7 @@ package hardware::server::cisco::ucs::mode::components::iocard; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%presence %operability); +use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); sub check { my ($self) = @_; @@ -70,10 +70,11 @@ sub check { next if ($self->absent_problem(section => 'iocard', instance => $iocard_dn)); next if ($self->check_exclude(section => 'iocard', instance => $iocard_dn)); - if (${$presence{$iocard_presence}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$presence{$iocard_presence}}[1], + my $exit = $self->get_severity(section => 'iocard', threshold => 'presence', value => $iocard_presence); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("IO cards '%s' presence is: '%s'", - $iocard_dn, ${$presence{$iocard_presence}}[0]) + $iocard_dn, ${$thresholds->{presence}->{$iocard_presence}}[0]) ); next; } @@ -81,13 +82,14 @@ sub check { $self->{components}->{iocard}->{total}++; $self->{output}->output_add(long_msg => sprintf("IO cards '%s' state is '%s' [presence: %s].", - $iocard_dn, ${$operability{$iocard_operstate}}[0], - ${$presence{$iocard_presence}}[0] + $iocard_dn, ${$thresholds->{operability}->{$iocard_presence}}[0], + ${$thresholds->{presence}->{$iocard_operstate}}[0] )); - if (${$operability{$iocard_operstate}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$operability{$iocard_operstate}}[1], + $exit = $self->get_severity(section => 'iocard', threshold => 'operability', value => $iocard_operstate); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("IO cards '%s' state is '%s'.", - $iocard_dn, ${$operability{$iocard_operstate}}[0] + $iocard_dn, ${$thresholds->{operability}->{$iocard_operstate}}[0] ) ); } diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/psu.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/psu.pm index dd6162299..e5b1f4ccc 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/psu.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/psu.pm @@ -37,7 +37,7 @@ package hardware::server::cisco::ucs::mode::components::psu; use strict; use warnings; -use hardware::server::cisco::ucs::mode::components::resources qw(%presence %operability); +use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); sub check { my ($self) = @_; @@ -70,10 +70,11 @@ sub check { next if ($self->absent_problem(section => 'psu', instance => $psu_dn)); next if ($self->check_exclude(section => 'psu', instance => $psu_dn)); - if (${$presence{$psu_presence}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$presence{$psu_presence}}[1], + my $exit = $self->get_severity(section => 'psu', threshold => 'presence', value => $psu_presence); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("power supply '%s' presence is: '%s'", - $psu_dn, ${$presence{$psu_presence}}[0]) + $psu_dn, ${$thresholds->{presence}->{$psu_presence}}[0]) ); next; } @@ -81,13 +82,14 @@ sub check { $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("power supply '%s' state is '%s' [presence: %s].", - $psu_dn, ${$operability{$psu_operstate}}[0], - ${$presence{$psu_presence}}[0] + $psu_dn, ${$thresholds->{operability}->{$psu_presence}}[0], + ${$thresholds->{presence}->{$psu_operstate}}[0] )); - if (${$operability{$psu_operstate}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$operability{$psu_operstate}}[1], + $exit = $self->get_severity(section => 'psu', threshold => 'operability', value => $psu_operstate); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, short_msg => sprintf("power supply '%s' state is '%s'.", - $psu_dn, ${$operability{$psu_operstate}}[0] + $psu_dn, ${$thresholds->{operability}->{$psu_operstate}}[0] ) ); } diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/components/resources.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/components/resources.pm index 52d20f264..aa8466260 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/components/resources.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/components/resources.pm @@ -39,54 +39,54 @@ use strict; use warnings; use Exporter; -our %presence; -our %operability; +our $thresholds; our @ISA = qw(Exporter); -our @EXPORT_OK = qw(%presence %operability); +our @EXPORT_OK = qw($thresholds); -%presence = ( - 0 => ['unknown', 'UNKNOWN'], - 1 => ['empty', 'OK'], - 10 => ['equipped', 'OK'], - 11 => ['missing', 'WARNING'], - 12 => ['mismatch', 'WARNING'], - 13 => ['equippedNotPrimary', 'OK'], - 20 => ['equippedIdentityUnestablishable', 'WARNING'], - 21 => ['mismatchIdentityUnestablishable', 'WARNING'], - 30 => ['inaccessible', 'UNKNOWN'], - 40 => ['unauthorized', 'UNKNOWN'], - 100 => ['notSupported', 'WARNING'], -); - -%operability = ( - 0 => ['unknown', 'UNKNOWN'], - 1 => ['operable', 'OK'], - 2 => ['inoperable', 'CRITICAL'], - 3 => ['degraded', 'WARNING'], - 4 => ['poweredOff', 'WARNING'], - 5 => ['powerProblem', 'CRITICAL'], - 6 => ['removed', 'WARNING'], - 7 => ['voltageProblem', 'CRITICAL'], - 8 => ['thermalProblem', 'CRITICAL'], - 9 => ['performanceProblem', 'CRITICAL'], - 10 => ['accessibilityProblem', 'WARNING'], - 11 => ['identityUnestablishable', 'WARNING'], - 12 => ['biosPostTimeout', 'WARNING'], - 13 => ['disabled', 'OK'], - 51 => ['fabricConnProblem', 'WARNING'], - 52 => ['fabricUnsupportedConn', 'WARNING'], - 81 => ['config', 'OK'], - 82 => ['equipmentProblem', 'CRITICAL'], - 83 => ['decomissioning', 'WARNING'], - 84 => ['chassisLimitExceeded', 'WARNING'], - 100 => ['notSupported', 'WARNING'], - 101 => ['discovery', 'OK'], - 102 => ['discoveryFailed', 'WARNING'], - 104 => ['postFailure', 'WARNING'], - 105 => ['upgradeProblem', 'WARNING'], - 106 => ['peerCommProblem', 'WARNING'], - 107 => ['autoUpgrade', 'OK'], -); +$thresholds = { + presence => { + 0 => ['unknown', 'UNKNOWN'], + 1 => ['empty', 'OK'], + 10 => ['equipped', 'OK'], + 11 => ['missing', 'WARNING'], + 12 => ['mismatch', 'WARNING'], + 13 => ['equippedNotPrimary', 'OK'], + 20 => ['equippedIdentityUnestablishable', 'WARNING'], + 21 => ['mismatchIdentityUnestablishable', 'WARNING'], + 30 => ['inaccessible', 'UNKNOWN'], + 40 => ['unauthorized', 'UNKNOWN'], + 100 => ['notSupported', 'WARNING'], + }, + operability => { + 0 => ['unknown', 'UNKNOWN'], + 1 => ['operable', 'OK'], + 2 => ['inoperable', 'CRITICAL'], + 3 => ['degraded', 'WARNING'], + 4 => ['poweredOff', 'WARNING'], + 5 => ['powerProblem', 'CRITICAL'], + 6 => ['removed', 'WARNING'], + 7 => ['voltageProblem', 'CRITICAL'], + 8 => ['thermalProblem', 'CRITICAL'], + 9 => ['performanceProblem', 'CRITICAL'], + 10 => ['accessibilityProblem', 'WARNING'], + 11 => ['identityUnestablishable', 'WARNING'], + 12 => ['biosPostTimeout', 'WARNING'], + 13 => ['disabled', 'OK'], + 51 => ['fabricConnProblem', 'WARNING'], + 52 => ['fabricUnsupportedConn', 'WARNING'], + 81 => ['config', 'OK'], + 82 => ['equipmentProblem', 'CRITICAL'], + 83 => ['decomissioning', 'WARNING'], + 84 => ['chassisLimitExceeded', 'WARNING'], + 100 => ['notSupported', 'WARNING'], + 101 => ['discovery', 'OK'], + 102 => ['discoveryFailed', 'WARNING'], + 104 => ['postFailure', 'WARNING'], + 105 => ['upgradeProblem', 'WARNING'], + 106 => ['peerCommProblem', 'WARNING'], + 107 => ['autoUpgrade', 'OK'], + }, +}; 1; \ No newline at end of file diff --git a/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm b/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm index 086039498..8b06cfa5b 100644 --- a/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm +++ b/centreon-plugins/hardware/server/cisco/ucs/mode/equipment.pm @@ -39,6 +39,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use hardware::server::cisco::ucs::mode::components::resources qw($thresholds); use hardware::server::cisco::ucs::mode::components::fan; use hardware::server::cisco::ucs::mode::components::psu; use hardware::server::cisco::ucs::mode::components::iocard; @@ -55,8 +56,9 @@ sub new { { "exclude:s" => { name => 'exclude' }, "absent-problem:s" => { name => 'absent' }, - "component:s" => { name => 'component', default => 'all' }, - "no-component:s" => { name => 'no_component' }, + "component:s" => { name => 'component', default => 'all' }, + "no-component:s" => { name => 'no_component' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, }); $self->{components} = {}; $self->{no_components} = undef; @@ -74,6 +76,22 @@ 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 treshold-overload option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $type, $status, $filter) = ($1, $2, $3, $4); + 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})); + $self->{overload_th}->{$section}->{$type} = { } if (!defined($self->{overload_th}->{$section}->{$type})); + $self->{overload_th}->{$section}->{$type}->{$filter} = $status; + } } sub global { @@ -158,6 +176,21 @@ sub check_exclude { return 0; } +sub get_severity { + my ($self, %options) = @_; + + my $status = ${$thresholds->{$options{threshold}}->{$options{value}}}[1]; + if (defined($self->{overload_th}->{$options{section}}->{$options{threshold}})) { + foreach (keys %{$self->{overload_th}->{$options{section}}->{$options{threshold}}}) { + if (${$thresholds->{$options{threshold}}->{$options{value}}}[0] =~ /$_/i) { + $status = $self->{overload_th}->{$options{section}}->{$options{threshold}}->{$_}; + last; + } + } + } + return $status; +} + sub absent_problem { my ($self, %options) = @_; @@ -202,6 +235,11 @@ Can be specific or global: --exclude=fan#/sys/chassis-7/fan-module-1-7/fan-1# 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,threshold,status,regexp) +Example: --threshold-overload='fan,operability,OK,poweredOff|removed' + =back =cut