+ Add option to overload
This commit is contained in:
Quentin Garnier 2014-08-04 14:59:57 +02:00
parent 0e7a147ed6
commit 73235b02f1
7 changed files with 137 additions and 91 deletions

View File

@ -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]
)
);
}

View File

@ -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]
)
);
}

View File

@ -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->{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]
)
);
}

View File

@ -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]
)
);
}

View File

@ -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]
)
);
}

View File

@ -39,13 +39,13 @@ 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 = (
$thresholds = {
presence => {
0 => ['unknown', 'UNKNOWN'],
1 => ['empty', 'OK'],
10 => ['equipped', 'OK'],
@ -57,9 +57,8 @@ our @EXPORT_OK = qw(%presence %operability);
30 => ['inaccessible', 'UNKNOWN'],
40 => ['unauthorized', 'UNKNOWN'],
100 => ['notSupported', 'WARNING'],
);
%operability = (
},
operability => {
0 => ['unknown', 'UNKNOWN'],
1 => ['operable', 'OK'],
2 => ['inoperable', 'CRITICAL'],
@ -87,6 +86,7 @@ our @EXPORT_OK = qw(%presence %operability);
105 => ['upgradeProblem', 'WARNING'],
106 => ['peerCommProblem', 'WARNING'],
107 => ['autoUpgrade', 'OK'],
);
},
};
1;

View File

@ -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;
@ -57,6 +58,7 @@ sub new {
"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;
@ -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