parent
2886f09a3c
commit
a5bef3a1bc
|
@ -46,7 +46,7 @@ my %map_status = (
|
||||||
sub check {
|
sub check {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
$self->{components}->{fans} = {name => 'fans', total => 0, skip => 0};
|
$self->{components}->{fans} = {name => 'fans', total => 0};
|
||||||
$self->{output}->output_add(long_msg => "Checking fans");
|
$self->{output}->output_add(long_msg => "Checking fans");
|
||||||
return if ($self->check_exclude(section => 'fans'));
|
return if ($self->check_exclude(section => 'fans'));
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ my %map_status = (
|
||||||
sub check {
|
sub check {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
$self->{components}->{modules} = {name => 'modules', total => 0, skip => 0};
|
$self->{components}->{modules} = {name => 'modules', total => 0};
|
||||||
$self->{output}->output_add(long_msg => "Checking modules");
|
$self->{output}->output_add(long_msg => "Checking modules");
|
||||||
return if ($self->check_exclude(section => 'modules'));
|
return if ($self->check_exclude(section => 'modules'));
|
||||||
|
|
||||||
|
@ -62,11 +62,11 @@ sub check {
|
||||||
my $instance = $1;
|
my $instance = $1;
|
||||||
|
|
||||||
next if ($self->check_exclude(section => 'modules', instance => $instance));
|
next if ($self->check_exclude(section => 'modules', instance => $instance));
|
||||||
$self->{components}->{modules}->{total}++;
|
|
||||||
|
|
||||||
my $type = $result->{$oid_nsSlotType . '.' . $instance};
|
my $type = $result->{$oid_nsSlotType . '.' . $instance};
|
||||||
my $status = $result->{$oid_nsSlotStatus . '.' . $instance};
|
my $status = $result->{$oid_nsSlotStatus . '.' . $instance};
|
||||||
|
|
||||||
|
$self->{components}->{modules}->{total}++;
|
||||||
$self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s].",
|
$self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s].",
|
||||||
$type, $map_status{$status}, $instance));
|
$type, $map_status{$status}, $instance));
|
||||||
if ($status != 1) {
|
if ($status != 1) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ my %map_status = (
|
||||||
sub check {
|
sub check {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
$self->{components}->{psus} = {name => 'psus', total => 0, skip => 0};
|
$self->{components}->{psus} = {name => 'psus', total => 0};
|
||||||
$self->{output}->output_add(long_msg => "Checking power supplies");
|
$self->{output}->output_add(long_msg => "Checking power supplies");
|
||||||
return if ($self->check_exclude(section => 'psus'));
|
return if ($self->check_exclude(section => 'psus'));
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ sub check {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
$self->{output}->output_add(long_msg => "Checking temperatures");
|
$self->{output}->output_add(long_msg => "Checking temperatures");
|
||||||
$self->{components}->{temperatures} = {name => 'temperatures', total => 0, skip => 0};
|
$self->{components}->{temperatures} = {name => 'temperatures', total => 0};
|
||||||
return if ($self->check_exclude('temperatures'));
|
return if ($self->check_exclude('temperatures'));
|
||||||
|
|
||||||
my $oid_nsTemperatureEntry = '.1.3.6.1.4.1.3224.21.4.1';
|
my $oid_nsTemperatureEntry = '.1.3.6.1.4.1.3224.21.4.1';
|
||||||
|
@ -58,10 +58,10 @@ sub check {
|
||||||
|
|
||||||
next if ($self->check_exclude(section => 'temperatures', instance => $instance));
|
next if ($self->check_exclude(section => 'temperatures', instance => $instance));
|
||||||
|
|
||||||
my $temperature_name = $result->{$oid_nsTemperatureDesc . '.' . $instance};
|
my $temperature_name = $result->{$oid_nsTemperatureDesc . '.' . $instance};
|
||||||
|
|
||||||
my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_nsTemperatureCur . '.' . $instance},
|
my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_nsTemperatureCur . '.' . $instance},
|
||||||
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||||
|
|
||||||
$self->{components}->{temperatures}->{total}++;
|
$self->{components}->{temperatures}->{total}++;
|
||||||
|
|
||||||
|
@ -71,13 +71,12 @@ sub check {
|
||||||
$self->{output}->output_add(severity => $exit_code,short_msg => sprintf($temperature_name . " is %.2f C", $result->{$oid_nsTemperatureCur . '.' . $instance}));
|
$self->{output}->output_add(severity => $exit_code,short_msg => sprintf($temperature_name . " is %.2f C", $result->{$oid_nsTemperatureCur . '.' . $instance}));
|
||||||
}
|
}
|
||||||
|
|
||||||
$temperature_name =~ s/\ /_/g;
|
$temperature_name =~ s/\ /_/g;
|
||||||
$self->{output}->perfdata_add(label => $temperature_name, unit => 'C',
|
$self->{output}->perfdata_add(label => $temperature_name , unit => 'C', value => sprintf("%.2f", $result->{$oid_nsTemperatureCur . '.' . $instance}),
|
||||||
value => sprintf("%.2f", $result->{$oid_nsTemperatureCur . '.' . $instance}),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -52,13 +52,11 @@ sub new {
|
||||||
|
|
||||||
$self->{version} = '1.0';
|
$self->{version} = '1.0';
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments =>
|
||||||
{
|
{
|
||||||
"exclude:s" => { name => 'exclude' },
|
"exclude:s" => { name => 'exclude' },
|
||||||
"absent-problem:s" => { name => 'absent' },
|
|
||||||
"component:s" => { name => 'component', default => 'all' },
|
"component:s" => { name => 'component', default => 'all' },
|
||||||
"no-component:s" => { name => 'no_component' },
|
"warning:s" => { name => 'warning', default => '' },
|
||||||
"warning:s" => { name => 'warning', },
|
"critical:s" => { name => 'critical', default => '' },
|
||||||
"critical:s" => { name => 'critical', },
|
|
||||||
});
|
});
|
||||||
$self->{components} = {};
|
$self->{components} = {};
|
||||||
return $self;
|
return $self;
|
||||||
|
@ -76,13 +74,7 @@ sub check_options {
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||||
$self->{output}->option_exit();
|
$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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub global {
|
sub global {
|
||||||
|
@ -114,14 +106,15 @@ sub run {
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
my $total_components = 0;
|
my $total_components = 0;
|
||||||
my $display_by_component = '';
|
my $display_by_component = '';
|
||||||
my $display_by_component_append = '';
|
my $display_by_component_append = '';
|
||||||
foreach my $comp (sort(keys %{$self->{components}})) {
|
foreach my $comp (sort(keys %{$self->{components}})) {
|
||||||
# Skipping short msg when no components
|
# Skipping short msg when no components
|
||||||
next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0);
|
next if ($self->{components}->{$comp}->{total} == 0);
|
||||||
$total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip};
|
$total_components += $self->{components}->{$comp}->{total};
|
||||||
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $self->{components}->{$comp}->{skip} . ' ' . $self->{components}->{$comp}->{name};
|
$display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . ' ' . $self->{components}->{$comp}->{name};
|
||||||
$display_by_component_append = ', ';
|
$display_by_component_append = ', ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,46 +125,20 @@ sub run {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
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}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_exclude {
|
sub check_exclude {
|
||||||
my ($self, %options) = @_;
|
my ($self, $section) = @_;
|
||||||
|
|
||||||
if (defined($options{instance})) {
|
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$section(\s|,|$)/) {
|
||||||
if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) {
|
$self->{output}->output_add(long_msg => sprintf("Skipping $section section."));
|
||||||
$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 1;
|
||||||
}
|
}
|
||||||
return 0;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
@ -192,15 +159,6 @@ Can be: 'fan', 'psu', 'module'.
|
||||||
Exclude some parts (comma seperated list) (Example: --exclude=fans,modules)
|
Exclude some parts (comma seperated list) (Example: --exclude=fans,modules)
|
||||||
Can also exclude specific instance: --exclude=fans#1#2#,modules#1#,psus
|
Can also exclude specific instance: --exclude=fans#1#2#,modules#1#,psus
|
||||||
|
|
||||||
=item B<--absent-problem>
|
|
||||||
|
|
||||||
N/A for following equipment. Not needed.
|
|
||||||
|
|
||||||
=item B<--no-component>
|
|
||||||
|
|
||||||
Return an error if no compenents are checked.
|
|
||||||
If total (with skipped) is 0. (Default: 'critical' returns).
|
|
||||||
|
|
||||||
=item B<--warning>
|
=item B<--warning>
|
||||||
|
|
||||||
Threshold warning in degree celsius.
|
Threshold warning in degree celsius.
|
||||||
|
|
Loading…
Reference in New Issue