This commit is contained in:
garnier-quentin 2014-08-08 20:24:23 +02:00
parent 24899ba786
commit 3fecc09641
4 changed files with 146 additions and 50 deletions

View File

@ -58,16 +58,16 @@ $thresholds = {
['^OK|NOT PRESENT$', 'OK'], ['^OK|NOT PRESENT$', 'OK'],
], ],
fan => [ fan => [
['^(?!(OK)$)', 'CRITICAL'], ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'],
['^OK$', 'OK'], ['^OK|NOT PRESENT$', 'OK'],
], ],
voltage => [ voltage => [
['^(?!(OK)$)', 'CRITICAL'], ['^(?!(OK)$)', 'CRITICAL'],
['^OK$', 'OK'], ['^OK$', 'OK'],
], ],
psu => [ psu => [
['^(?!(OK)$)', 'CRITICAL'], ['^(?!(OK|NOT PRESENT)$)', 'CRITICAL'],
['^OK$', 'OK'], ['^OK|NOT PRESENT$', 'OK'],
], ],
sensors => [ sensors => [
['^(?!(OK)$)', 'CRITICAL'], ['^(?!(OK)$)', 'CRITICAL'],

View File

@ -45,22 +45,39 @@ sub check {
$self->{components}->{si} = {name => 'system indicator', total => 0, skip => 0}; $self->{components}->{si} = {name => 'system indicator', total => 0, skip => 0};
return if ($self->check_exclude(section => 'si')); return if ($self->check_exclude(section => 'si'));
if ($self->{stdout} =~ /^System Indicator Status.*?\n.*?\n.*?\n.*?\n(.*?)\n\n/ims && defined($1)) { #--------------------------------------------------------
#MB.LOCATE MB.SERVICE MB.ACT #System Indicator Status:
#-------------------------------------------------------- #--------------------------------------------------------
#OFF OFF ON #MB.LOCATE MB.SERVICE MB.ACT
#--------------------------------------------------------
#OFF OFF ON
#--------------------------------------------------------
#System Indicator Status:
#--------------------------------------------------------
#SYS/LOCATE SYS/SERVICE SYS/ACT
#OFF OFF ON
#--------------------------------------------------------
#SYS/REAR_FAULT SYS/TEMP_FAULT SYS/TOP_FAN_FAULT
#OFF OFF OFF
#--------------------------------------------------------
if ($self->{stdout} =~ /^System Indicator Status.*?\n(.*?)\n\n/ims && defined($1)) {
my $match = $1;
if ($1 =~ /^([^\s]+)\s+([^\s].*?)\s{2}/) { if ($match =~ /^.*(MB\.SERVICE).*?\n---+\n\s*\S+\s*(\S+)/ims ||
my $mbservice_status = defined($2) ? $2 : 'unknown'; $match =~ /^.*(SYS\/SERVICE).*?\n\s*\S+\s*(\S+)/ims) {
my $si_name = defined($1) ? $1 : 'unknown';
my $si_status = defined($2) ? $2 : 'unknown';
next if ($self->check_exclude(section => 'si', instance => 'MB.SERVICE')); next if ($self->check_exclude(section => 'si', instance => $si_name));
$self->{components}->{si}->{total}++; $self->{components}->{si}->{total}++;
$self->{output}->output_add(long_msg => "System Indicator Status 'MB.SERVICE' is " . $mbservice_status); $self->{output}->output_add(long_msg => "System Indicator Status '$si_name' is " . $si_status);
my $exit = $self->get_severity(section => 'si', value => $mbservice_status); my $exit = $self->get_severity(section => 'si', value => $si_status);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => "System Indicator Status 'MB.SERVICE' is " . $mbservice_status); short_msg => "System Indicator Status '$si_name' is " . $si_status);
} }
} }
} }

View File

@ -42,9 +42,11 @@ use warnings;
use centreon::plugins::misc; use centreon::plugins::misc;
my $thresholds = [ my $thresholds = [
['access denied', 'UNKNOWN'], ['Faulted', 'CRITICAL'],
['(?!(No failures))', 'CRITICAL'], ['Degraded', 'WARNING'],
['No failures', 'OK'], ['Deconfigured', 'WARNING'],
['Maintenance', 'OK'],
['Normal', 'OK'],
]; ];
sub new { sub new {
@ -61,6 +63,7 @@ sub new {
"timeout:s" => { name => 'timeout', default => 30 }, "timeout:s" => { name => 'timeout', default => 30 },
"command-plink:s" => { name => 'command_plink', default => 'plink' }, "command-plink:s" => { name => 'command_plink', default => 'plink' },
"threshold-overload:s@" => { name => 'threshold_overload' }, "threshold-overload:s@" => { name => 'threshold_overload' },
"exclude:s@" => { name => 'exclude' },
}); });
return $self; return $self;
} }
@ -117,60 +120,93 @@ sub get_severity {
return $status; return $status;
} }
sub run { sub check_exclude {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (@{$self->{option_results}->{exclude}}) {
if ($options{value} =~ /$_/i) {
$self->{output}->output_add(long_msg => sprintf("Skip Component '%s'",
$options{value}));
return 1;
}
}
return 0;
}
sub check_tree {
my ($self) = @_;
my $total_components = 0;
my @stack = ({ indent => 0, long_instance => '', long_status => ''});
while ($self->{stdout} =~ /^([* \t]+)(.*)\s+Status:(.+?);/mg) {
my ($indent, $unit_number, $status) = (length($1), $2, $3);
my ($long_instance, $long_status);
while ($indent <= $stack[$#stack]->{indent}) {
pop @stack;
}
$long_instance = $stack[$#stack]->{long_instance} . '>' . $unit_number;
$long_status = $stack[$#stack]->{long_status} . ' > ' . $unit_number . ' Status:' . $status;
if ($indent > $stack[$#stack]->{indent}) {
push @stack, { indent => $indent,
long_instance => $stack[$#stack]->{long_instance} . '>' . $unit_number,
long_status => $stack[$#stack]->{long_status} . ' > ' . $unit_number . ' Status:' . $status };
}
next if ($self->check_exclude(value => $long_instance));
my $exit = $self->get_severity(value => $status);
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Component '%s' status is '%s'",
$unit_number, $status));
}
$self->{output}->output_add(long_msg => sprintf("Component '%s' status is '%s' [%s] [%s]",
$unit_number, $status, $long_instance, $long_status));
$total_components++;
}
$self->{output}->output_add(severity => 'OK',
short_msg => sprintf("All %s components are ok.",
$total_components)
);
}
sub run {
my ($self, %options) = @_;
my ($lerror, $exit_code);
###### ######
# Command execution # Command execution
###### ######
($lerror, $self->{stdout}, $exit_code) = centreon::plugins::misc::backtick(
my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick(
command => $self->{option_results}->{command_plink}, command => $self->{option_results}->{command_plink},
timeout => $self->{option_results}->{timeout}, timeout => $self->{option_results}->{timeout},
arguments => ['-batch', '-l', $self->{option_results}->{username}, arguments => ['-batch', '-l', $self->{option_results}->{username},
'-pw', $self->{option_results}->{password}, '-pw', $self->{option_results}->{password},
$self->{option_results}->{hostname}, 'showstatus'], $self->{option_results}->{hostname}, 'showhardconf'],
wait_exit => 1, wait_exit => 1,
redirect_stderr => 1 redirect_stderr => 1
); );
$stdout =~ s/\r//g; $self->{stdout} =~ s/\r//g;
if ($lerror <= -1000) { if ($lerror <= -1000) {
$self->{output}->output_add(severity => 'UNKNOWN', $self->{output}->output_add(severity => 'UNKNOWN',
short_msg => $stdout); short_msg => $self->{stdout});
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
if ($exit_code != 0) { if ($exit_code != 0) {
$stdout =~ s/\n/ - /g; $self->{stdout} =~ s/\n/ - /g;
$self->{output}->output_add(severity => 'UNKNOWN', $self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Command error: $stdout"); short_msg => "Command error: $self->{stdout}");
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
######
# Command treatment
######
my $long_msg = $stdout;
$long_msg =~ s/\|/~/mg;
if (!defined($stdout)) {
$self->{output}->output_add(long_msg => $stdout);
$self->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Command '$stdout' problems (see additional info).");
$self->{output}->display();
$self->{output}->exit();
}
$self->{output}->output_add(long_msg => $long_msg);
my $exit = $self->get_severity(value => $stdout); $self->check_tree();
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit,
short_msg => "Some errors on system (see additional info).");
} else {
$self->{output}->output_add(severity => 'OK',
short_msg => "No problems on system.");
}
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
@ -210,7 +246,12 @@ Timeout in seconds for the command (Default: 30).
Set to overload default threshold values (syntax: status,regexp) Set to overload default threshold values (syntax: status,regexp)
It used before default thresholds (order stays). It used before default thresholds (order stays).
Example: --threshold-overload='UNKNOWN,access denied' Example: --threshold-overload='UNKNOWN,Normal'
=item B<--exclude>
Filter components (multiple) (can be a regexp).
Example: --exclude='MEM#2B' --exclude='MBU_A>MEM#0B'.
=back =back

View File

@ -63,8 +63,10 @@ sub new {
"command-path:s" => { name => 'command_path', default => '/usr/platform/`/sbin/uname -i`/sbin' }, "command-path:s" => { name => 'command_path', default => '/usr/platform/`/sbin/uname -i`/sbin' },
"command-options:s" => { name => 'command_options', default => '-v 2>&1' }, "command-options:s" => { name => 'command_options', default => '-v 2>&1' },
"config-file:s" => { name => 'config_file' }, "config-file:s" => { name => 'config_file' },
"exclude:s@" => { name => 'exclude' },
}); });
$self->{conf} = {}; $self->{conf} = {};
$self->{excludes} = {};
$self->{syst} = undef; $self->{syst} = undef;
return $self; return $self;
} }
@ -77,6 +79,33 @@ sub check_options {
} else { } else {
$self->{config_file} = dirname(__FILE__) . '/../conf/prtdiag.conf'; $self->{config_file} = dirname(__FILE__) . '/../conf/prtdiag.conf';
} }
foreach (@{$self->{option_results}->{exclude}}) {
next if (! /^(.*?),(.*?),(.*)$/);
my ($section, $tpl, $filter) = ($1, $2, $3);
$self->{excludes}->{$section} = [] if (!defined($self->{excludes}->{$section}));
push @{$self->{excludes}->{$section}}, { template => $tpl, filter => $filter };
}
}
sub check_exclude {
my ($self, %options) = @_;
return 0 if (!defined($self->{excludes}->{$options{section}}));
foreach my $exclude (@{$self->{excludes}->{$options{section}}}) {
my ($template, $filter) = ($exclude->{template}, $exclude->{filter});
foreach my $label (keys %{$options{dataset}}) {
$template =~ s/%$label%/$options{dataset}->{$label}/g;
}
if ($template =~ /$filter/) {
$self->{output}->output_add(long_msg => " INF - Skipping $template");
return 1;
}
}
return 0;
} }
sub prtdiag { sub prtdiag {
@ -225,10 +254,12 @@ sub prtdiag {
my $ok_condition = $self->{conf}->{$self->{syst}}->{"checks.$check.ok_condition"}; my $ok_condition = $self->{conf}->{$self->{syst}}->{"checks.$check.ok_condition"};
my $output_string = $self->{conf}->{$self->{syst}}->{"checks.$check.output_string"}; my $output_string = $self->{conf}->{$self->{syst}}->{"checks.$check.output_string"};
next if ($self->check_exclude(dataset => $data{$dataset}, section => $check));
# Substitute labels in condition and output string # Substitute labels in condition and output string
foreach my $label ( keys( %{ $data{$dataset} } ) ) { foreach my $label ( keys( %{ $data{$dataset} } ) ) {
$ok_condition =~ s/%$label%/$data{$dataset}->{$label}/g; $ok_condition =~ s/%$label%/$data{$dataset}->{$label}/g;
$output_string =~ s/%$label%/$data{$dataset}->{$label}/g; $output_string =~ s/%$label%/$data{$dataset}->{$label}/g;
} }
# Test condition # Test condition
@ -357,6 +388,13 @@ Command options (Default: '-v 2>&1').
Config file with prtdiag output description (Default: Directory 'conf/prtdiag.conf' under absolute mode path). Config file with prtdiag output description (Default: Directory 'conf/prtdiag.conf' under absolute mode path).
=item B<--exclude>
Exclude some components (multiple) (Syntax: SECTION,INSTANCE,FILTER).
SECTION = component type in prtdiag.conf (Example: temperature, fan,...
INSTANCE = Set the instance (Example: %Location%)
FILTER = regexp to filter
=back =back
=cut =cut