mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-28 08:04:36 +02:00
+ Fix #151
This commit is contained in:
parent
3cc76cb000
commit
8fea0666da
@ -25,37 +25,42 @@ use warnings;
|
||||
|
||||
my %map_status = (
|
||||
1 => 'active',
|
||||
2 => 'inactive'
|
||||
2 => 'inactive',
|
||||
);
|
||||
|
||||
my $mapping = {
|
||||
nsFanStatus => { oid => '.1.3.6.1.4.1.3224.21.2.1.2', map => \%map_status },
|
||||
};
|
||||
my $oid_nsFanEntry = '.1.3.6.1.4.1.3224.21.2.1';
|
||||
|
||||
sub load {
|
||||
my (%options) = @_;
|
||||
|
||||
push @{$options{request}}, { oid => $oid_nsFanEntry };
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{components}->{fans} = {name => 'fans', total => 0};
|
||||
|
||||
$self->{output}->output_add(long_msg => "Checking fans");
|
||||
return if ($self->check_exclude(section => 'fans'));
|
||||
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
|
||||
return if ($self->check_filter(section => 'fan'));
|
||||
|
||||
my $oid_nsFanEntry = '.1.3.6.1.4.1.3224.21.2.1';
|
||||
my $oid_nsFanStatus = '.1.3.6.1.4.1.3224.21.2.1.2';
|
||||
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_nsFanEntry);
|
||||
return if (scalar(keys %$result) <= 0);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /^$oid_nsFanStatus\.(\d+)$/);
|
||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nsFanEntry}})) {
|
||||
next if ($oid !~ /^$mapping->{nsFanStatus}->{oid}\.(.*)$/);
|
||||
my $instance = $1;
|
||||
|
||||
next if ($self->check_exclude(section => 'fans', instance => $instance));
|
||||
|
||||
my $status = $result->{$oid_nsFanStatus . '.' . $instance};
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_nsFanEntry}, instance => $instance);
|
||||
|
||||
next if ($self->check_filter(section => 'fan', instance => $instance));
|
||||
$self->{components}->{fan}->{total}++;
|
||||
|
||||
$self->{components}->{fans}->{total}++;
|
||||
$self->{output}->output_add(long_msg => sprintf("Fan '%s' status is %s.",
|
||||
$instance, $map_status{$status}));
|
||||
if ($status != 1) {
|
||||
$self->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => sprintf("Fan '%s' status is %s",
|
||||
$instance, $map_status{$status}));
|
||||
$self->{output}->output_add(long_msg => sprintf("Fan '%s' status is '%s' [instance: %s]",
|
||||
$instance, $result->{nsFanStatus}, $instance));
|
||||
my $exit = $self->get_severity(section => 'fan', value => $result->{nsFanStatus});
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Fan '%s' status is '%s'",
|
||||
$instance, $result->{nsFanStatus}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,39 +25,43 @@ use warnings;
|
||||
|
||||
my %map_status = (
|
||||
1 => 'active',
|
||||
2 => 'inactive'
|
||||
2 => 'inactive',
|
||||
);
|
||||
|
||||
my $mapping = {
|
||||
nsSlotType => { oid => '.1.3.6.1.4.1.3224.21.5.1.2' },
|
||||
nsSlotStatus => { oid => '.1.3.6.1.4.1.3224.21.5.1.3', map => \%map_status },
|
||||
};
|
||||
my $oid_nsSlotEntry = '.1.3.6.1.4.1.3224.21.5.1';
|
||||
|
||||
sub load {
|
||||
my (%options) = @_;
|
||||
|
||||
push @{$options{request}}, { oid => $oid_nsSlotEntry };
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{components}->{modules} = {name => 'modules', total => 0};
|
||||
|
||||
$self->{output}->output_add(long_msg => "Checking modules");
|
||||
return if ($self->check_exclude(section => 'modules'));
|
||||
$self->{components}->{module} = {name => 'module', total => 0, skip => 0};
|
||||
return if ($self->check_filter(section => 'module'));
|
||||
|
||||
my $oid_nsSlotEntry = '.1.3.6.1.4.1.3224.21.5.1';
|
||||
my $oid_nsSlotType = '.1.3.6.1.4.1.3224.21.5.1.2';
|
||||
my $oid_nsSlotStatus = '.1.3.6.1.4.1.3224.21.5.1.3';
|
||||
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_nsSlotEntry);
|
||||
return if (scalar(keys %$result) <= 0);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /^$oid_nsSlotStatus\.(\d+)$/);
|
||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nsSlotEntry}})) {
|
||||
next if ($oid !~ /^$mapping->{nsSlotStatus}->{oid}\.(.*)$/);
|
||||
my $instance = $1;
|
||||
|
||||
next if ($self->check_exclude(section => 'modules', instance => $instance));
|
||||
|
||||
my $type = $result->{$oid_nsSlotType . '.' . $instance};
|
||||
my $status = $result->{$oid_nsSlotStatus . '.' . $instance};
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_nsSlotEntry}, instance => $instance);
|
||||
|
||||
next if ($self->check_filter(section => 'module', instance => $instance));
|
||||
$self->{components}->{module}->{total}++;
|
||||
|
||||
$self->{components}->{modules}->{total}++;
|
||||
$self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s].",
|
||||
$type, $map_status{$status}, $instance));
|
||||
if ($status != 1) {
|
||||
$self->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => sprintf("Module '%s' status is %s",
|
||||
$type, $map_status{$status}));
|
||||
$self->{output}->output_add(long_msg => sprintf("Module '%s' status is '%s' [instance: %s]",
|
||||
$result->{nsSlotType}, $result->{nsSlotStatus}, $instance));
|
||||
my $exit = $self->get_severity(section => 'module', value => $result->{nsSlotStatus});
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Module '%s' status is '%s'",
|
||||
$result->{nsSlotType}, $result->{nsSlotStatus}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,37 +25,42 @@ use warnings;
|
||||
|
||||
my %map_status = (
|
||||
1 => 'active',
|
||||
2 => 'inactive'
|
||||
2 => 'inactive',
|
||||
);
|
||||
|
||||
my $mapping = {
|
||||
nsPowerStatus => { oid => '.1.3.6.1.4.1.3224.21.1.1.2', map => \%map_status },
|
||||
};
|
||||
my $oid_nsPowerEntry = '.1.3.6.1.4.1.3224.21.1.1';
|
||||
|
||||
sub load {
|
||||
my (%options) = @_;
|
||||
|
||||
push @{$options{request}}, { oid => $oid_nsPowerEntry };
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{components}->{psus} = {name => 'psus', total => 0};
|
||||
|
||||
$self->{output}->output_add(long_msg => "Checking power supplies");
|
||||
return if ($self->check_exclude(section => 'psus'));
|
||||
$self->{components}->{psu} = {name => 'psus', total => 0, skip => 0};
|
||||
return if ($self->check_filter(section => 'psu'));
|
||||
|
||||
my $oid_nsPowerEntry= '.1.3.6.1.4.1.3224.21.1.1';
|
||||
my $oid_nsPowerStatus = '.1.3.6.1.4.1.3224.21.1.1.2';
|
||||
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_nsPowerEntry);
|
||||
return if (scalar(keys %$result) <= 0);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /^$oid_nsPowerStatus\.(\d+)$/);
|
||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nsPowerEntry}})) {
|
||||
next if ($oid !~ /^$mapping->{nsPowerStatus}->{oid}\.(.*)$/);
|
||||
my $instance = $1;
|
||||
|
||||
next if ($self->check_exclude(section => 'psus', instance => $instance));
|
||||
|
||||
my $status = $result->{$oid_nsPowerStatus . '.' . $instance};
|
||||
|
||||
$self->{components}->{psus}->{total}++;
|
||||
$self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is %s.",
|
||||
$instance, $map_status{$status}));
|
||||
if ($status != 1) {
|
||||
$self->{output}->output_add(severity => 'CRITICAL',
|
||||
short_msg => sprintf("Power Supply '%s' status is %s",
|
||||
$instance, $map_status{$status}));
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_nsPowerEntry}, instance => $instance);
|
||||
|
||||
next if ($self->check_filter(section => 'psu', instance => $instance));
|
||||
$self->{components}->{psu}->{total}++;
|
||||
|
||||
$self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s' [instance: %s]",
|
||||
$instance, $result->{nsPowerStatus}, $instance));
|
||||
my $exit = $self->get_severity(section => 'psu', value => $result->{nsPowerStatus});
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Power supply '%s' status is '%s'",
|
||||
$instance, $result->{nsPowerStatus}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,45 +23,47 @@ package network::juniper::common::screenos::mode::components::temperature;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $mapping = {
|
||||
nsTemperatureCur => { oid => '.1.3.6.1.4.1.3224.21.4.1.3' },
|
||||
nsTemperatureDesc => { oid => '.1.3.6.1.4.1.3224.21.4.1.4' },
|
||||
};
|
||||
my $oid_nsTemperatureEntry = '.1.3.6.1.4.1.3224.21.4.1';
|
||||
|
||||
sub load {
|
||||
my (%options) = @_;
|
||||
|
||||
push @{$options{request}}, { oid => $oid_nsTemperatureEntry };
|
||||
}
|
||||
|
||||
sub check {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->{output}->output_add(long_msg => "Checking temperatures");
|
||||
$self->{components}->{temperatures} = {name => 'temperatures', total => 0};
|
||||
return if ($self->check_exclude('temperatures'));
|
||||
|
||||
my $oid_nsTemperatureEntry = '.1.3.6.1.4.1.3224.21.4.1';
|
||||
my $oid_nsTemperatureCur = '.1.3.6.1.4.1.3224.21.4.1.3';
|
||||
my $oid_nsTemperatureDesc = '.1.3.6.1.4.1.3224.21.4.1.4';
|
||||
|
||||
my $result = $self->{snmp}->get_table(oid => $oid_nsTemperatureEntry);
|
||||
return if (scalar(keys %$result) <= 0);
|
||||
|
||||
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
|
||||
next if ($key !~ /^$oid_nsTemperatureCur\.(\d+)$/);
|
||||
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
|
||||
return if ($self->check_filter(section => 'temperature'));
|
||||
|
||||
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nsTemperatureEntry}})) {
|
||||
next if ($oid !~ /^$mapping->{nsTemperatureCur}->{oid}\.(.*)$/);
|
||||
my $instance = $1;
|
||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_nsTemperatureEntry}, instance => $instance);
|
||||
|
||||
next if ($self->check_filter(section => 'temperature', instance => $instance));
|
||||
$self->{components}->{temperature}->{total}++;
|
||||
|
||||
next if ($self->check_exclude(section => 'temperatures', instance => $instance));
|
||||
|
||||
my $temperature_name = $result->{$oid_nsTemperatureDesc . '.' . $instance};
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_nsTemperatureCur . '.' . $instance},
|
||||
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
|
||||
$self->{components}->{temperatures}->{total}++;
|
||||
|
||||
$self->{output}->output_add(severity => $exit_code,long_msg => sprintf($temperature_name . " is %.2f C", $result->{$oid_nsTemperatureCur . '.' . $instance}));
|
||||
|
||||
if ($exit_code ne 'ok') {
|
||||
$self->{output}->output_add(severity => $exit_code,short_msg => sprintf($temperature_name . " is %.2f C", $result->{$oid_nsTemperatureCur . '.' . $instance}));
|
||||
}
|
||||
|
||||
$temperature_name =~ s/\ /_/g;
|
||||
$self->{output}->perfdata_add(label => $temperature_name , unit => 'C', value => sprintf("%.2f", $result->{$oid_nsTemperatureCur . '.' . $instance}),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||
$self->{output}->output_add(long_msg => sprintf("Temperature '%s' is '%.2f' C [instance: %s]",
|
||||
$result->{nsTemperatureDesc}, $result->{nsTemperatureCur},
|
||||
$instance));
|
||||
|
||||
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{nsTemperatureCur});
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Temperature '%s' is %s C", $result->{nsTemperatureDesc}, $result->{nsTemperatureCur}));
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $result->{nsTemperatureDesc}, unit => 'C',
|
||||
value => $result->{nsTemperatureCur},
|
||||
warning => $warn,
|
||||
critical => $crit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
1;
|
@ -25,10 +25,20 @@ use base qw(centreon::plugins::mode);
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use network::juniper::common::screenos::mode::components::fan;
|
||||
use network::juniper::common::screenos::mode::components::module;
|
||||
use network::juniper::common::screenos::mode::components::psu;
|
||||
use network::juniper::common::screenos::mode::components::temperature;
|
||||
my $thresholds = {
|
||||
fan => [
|
||||
['active', 'OK'],
|
||||
['.*', 'CRITICAL'],
|
||||
],
|
||||
module => [
|
||||
['active', 'OK'],
|
||||
['.*', 'CRITICAL'],
|
||||
],
|
||||
psu => [
|
||||
['active', 'OK'],
|
||||
['.*', 'CRITICAL'],
|
||||
],
|
||||
};
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
@ -38,12 +48,15 @@ sub new {
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"exclude:s" => { name => 'exclude' },
|
||||
"component:s" => { name => 'component', default => 'all' },
|
||||
"warning:s" => { name => 'warning', default => '' },
|
||||
"critical:s" => { name => 'critical', default => '' },
|
||||
"filter:s@" => { name => 'filter' },
|
||||
"component:s" => { name => 'component', default => '.*' },
|
||||
"no-component:s" => { name => 'no_component' },
|
||||
"threshold-overload:s@" => { name => 'threshold_overload' },
|
||||
"warning:s@" => { name => 'warning' },
|
||||
"critical:s@" => { name => 'critical' },
|
||||
});
|
||||
$self->{components} = {};
|
||||
$self->{no_components} = undef;
|
||||
return $self;
|
||||
}
|
||||
|
||||
@ -51,79 +64,196 @@ 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 (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';
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
||||
$self->{filter} = [];
|
||||
foreach my $val (@{$self->{option_results}->{filter}}) {
|
||||
next if (!defined($val) || $val eq '');
|
||||
my @values = split (/,/, $val);
|
||||
push @{$self->{filter}}, { filter => $values[0], instance => $values[1] };
|
||||
}
|
||||
|
||||
$self->{overload_th} = {};
|
||||
foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
|
||||
next if (!defined($val) || $val eq '');
|
||||
my @values = split (/,/, $val);
|
||||
if (scalar(@values) < 3) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
my ($section, $instance, $status, $filter);
|
||||
if (scalar(@values) == 3) {
|
||||
($section, $status, $filter) = @values;
|
||||
$instance = '.*';
|
||||
} else {
|
||||
($section, $instance, $status, $filter) = @values;
|
||||
}
|
||||
if ($section !~ /^temperature|psu|module|fan$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload section '" . $val . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if ($self->{output}->is_litteral_status(status => $status) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong threshold-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, instance => $instance };
|
||||
}
|
||||
|
||||
$self->{numeric_threshold} = {};
|
||||
foreach my $option (('warning', 'critical')) {
|
||||
foreach my $val (@{$self->{option_results}->{$option}}) {
|
||||
next if (!defined($val) || $val eq '');
|
||||
if ($val !~ /^(.*?),(.*?),(.*)$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
my ($section, $instance, $value) = ($1, $2, $3);
|
||||
if ($section !~ /^sensor$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong $option option '" . $val . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
my $position = 0;
|
||||
if (defined($self->{numeric_threshold}->{$section})) {
|
||||
$position = scalar(@{$self->{numeric_threshold}->{$section}});
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => $option . '-' . $section . '-' . $position, value => $value)) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong $option threshold '" . $value . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
$self->{numeric_threshold}->{$section} = [] if (!defined($self->{numeric_threshold}->{$section}));
|
||||
push @{$self->{numeric_threshold}->{$section}}, { label => $option . '-' . $section . '-' . $position, threshold => $option, instance => $instance };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub global {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
network::juniper::common::screenos::mode::components::temperature::check($self);
|
||||
network::juniper::common::screenos::mode::components::fan::check($self);
|
||||
network::juniper::common::screenos::mode::components::module::check($self);
|
||||
network::juniper::common::screenos::mode::components::psu::check($self);
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
# $options{snmp} = snmp object
|
||||
$self->{snmp} = $options{snmp};
|
||||
|
||||
if ($self->{option_results}->{component} eq 'all') {
|
||||
$self->global();
|
||||
} elsif ($self->{option_results}->{component} eq 'fan') {
|
||||
network::juniper::common::screenos::mode::components::fan::check($self);
|
||||
} elsif ($self->{option_results}->{component} eq 'module') {
|
||||
network::juniper::common::screenos::mode::components::module::check($self);
|
||||
} elsif ($self->{option_results}->{component} eq 'psu') {
|
||||
network::juniper::common::screenos::mode::components::psu::check($self);
|
||||
} elsif ($self->{option_results}->{component} eq 'temperature') {
|
||||
network::juniper::common::screenos::mode::components::temperature::check($self);
|
||||
} else {
|
||||
my $snmp_request = [];
|
||||
my @components = ('psu', 'fan', 'temperature', 'module');
|
||||
foreach (@components) {
|
||||
if (/$self->{option_results}->{component}/) {
|
||||
my $mod_name = "network::juniper::common::screenos::mode::components::$_";
|
||||
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name,
|
||||
error_msg => "Cannot load module '$mod_name'.");
|
||||
my $func = $mod_name->can('load');
|
||||
$func->(request => $snmp_request);
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(@{$snmp_request}) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
$self->{results} = $self->{snmp}->get_multiple_table(oids => $snmp_request);
|
||||
|
||||
foreach (@components) {
|
||||
if (/$self->{option_results}->{component}/) {
|
||||
my $mod_name = "network::juniper::common::screenos::mode::components::$_";
|
||||
my $func = $mod_name->can('check');
|
||||
$func->($self);
|
||||
}
|
||||
}
|
||||
|
||||
my $total_components = 0;
|
||||
my $display_by_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};
|
||||
my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
|
||||
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name};
|
||||
$display_by_component_append = ', ';
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => sprintf("All %s components [%s] are ok.",
|
||||
short_msg => sprintf("All %s components are ok [%s].",
|
||||
$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) = @_;
|
||||
|
||||
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$section(\s|,|$)/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping $section section."));
|
||||
return 1;
|
||||
sub check_filter {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach (@{$self->{filter}}) {
|
||||
if ($options{section} =~ /$_->{filter}/) {
|
||||
if (!defined($options{instance}) && !defined($_->{instance})) {
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section."));
|
||||
return 1;
|
||||
} elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance."));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub get_severity_numeric {
|
||||
my ($self, %options) = @_;
|
||||
my $status = 'OK'; # default
|
||||
my $thresholds = { warning => undef, critical => undef };
|
||||
my $checked = 0;
|
||||
|
||||
if (defined($self->{numeric_threshold}->{$options{section}})) {
|
||||
my $exits = [];
|
||||
foreach (@{$self->{numeric_threshold}->{$options{section}}}) {
|
||||
if ($options{instance} =~ /$_->{instance}/) {
|
||||
push @{$exits}, $self->{perfdata}->threshold_check(value => $options{value}, threshold => [ { label => $_->{label}, exit_litteral => $_->{threshold} } ]);
|
||||
$thresholds->{$_->{threshold}} = $self->{perfdata}->get_perfdata_for_output(label => $_->{label});
|
||||
$checked = 1;
|
||||
}
|
||||
}
|
||||
$status = $self->{output}->get_most_critical(status => $exits) if (scalar(@{$exits}) > 0);
|
||||
}
|
||||
|
||||
return ($status, $thresholds->{warning}, $thresholds->{critical}, $checked);
|
||||
}
|
||||
|
||||
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 &&
|
||||
(!defined($options{instance}) || $options{instance} =~ /$_->{instance}/)) {
|
||||
$status = $_->{status};
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
}
|
||||
my $label = defined($options{label}) ? $options{label} : $options{section};
|
||||
foreach (@{$thresholds->{$label}}) {
|
||||
if ($options{value} =~ /$$_[0]/i) {
|
||||
$status = $$_[1];
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
@ -136,21 +266,34 @@ Check hardware (fans, power supplies).
|
||||
|
||||
=item B<--component>
|
||||
|
||||
Which component to check (Default: 'all').
|
||||
Can be: 'fan', 'psu', 'module'.
|
||||
Which component to check (Default: '.*').
|
||||
Can be: 'fan', 'psu', 'module', 'temperature'.
|
||||
|
||||
=item B<--exclude>
|
||||
=item B<--filter>
|
||||
|
||||
Exclude some parts (comma seperated list) (Example: --exclude=fans,modules)
|
||||
Can also exclude specific instance: --exclude=fans#1#2#,modules#1#,psus
|
||||
Exclude some parts (comma seperated list) (Example: --filter=psu --filter=modules)
|
||||
Can also exclude specific instance: --filter=fan,1
|
||||
|
||||
=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,[instance,]status,regexp)
|
||||
It used before default thresholds (order stays).
|
||||
Example: --threshold-overload='psu,WARNING,^(?!(active)$)'
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning in degree celsius.
|
||||
Set warning threshold for temperatures (syntax: type,instance,threshold)
|
||||
Example: --warning='temperature,.*,30'
|
||||
|
||||
=item B<--critical>
|
||||
|
||||
Threshold critical in degree celsius.
|
||||
Set critical threshold for temperatures (syntax: type,instance,threshold)
|
||||
Example: --critical='temperature,.*,40'
|
||||
|
||||
=back
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user