This commit is contained in:
Quentin garnier 2014-04-14 15:35:11 +02:00
parent f5092350b1
commit 20d85037a4
2 changed files with 63 additions and 8 deletions

View File

@ -50,6 +50,9 @@ sub new {
{
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"swap:s" => { name => 'check_swap' },
"warning-swap:s" => { name => 'warning_swap' },
"critical-swap:s" => { name => 'critical_swap' },
});
return $self;
@ -66,7 +69,17 @@ sub check_options {
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();
}
}
if (defined($self->{option_results}->{check_swap})) {
if (($self->{perfdata}->threshold_validate(label => 'warning-swap', value => $self->{option_results}->{warning_swap})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning-swap threshold '" . $self->{option_results}->{warning_swap} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical-swap', value => $self->{option_results}->{critical_swap})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical-swap threshold '" . $self->{option_results}->{critical_swap} . "'.");
$self->{output}->option_exit();
}
}
}
sub run {
@ -79,10 +92,16 @@ sub run {
my $oid_memShared = '.1.3.6.1.4.1.2021.4.13.0';
my $oid_memBuffer = '.1.3.6.1.4.1.2021.4.14.0';
my $oid_memCached = '.1.3.6.1.4.1.2021.4.15.0';
my $oid_memTotalSwap = '.1.3.6.1.4.1.2021.4.3.0'; # KB
my $oid_memAvailSwap = '.1.3.6.1.4.1.2021.4.4.0'; # KB
my $result = $self->{snmp}->get_leef(oids => [$oid_memTotalReal, $oid_memAvailReal,
$oid_memShared, $oid_memBuffer, $oid_memCached],
nothing_quit => 1);
my $oids = [$oid_memTotalReal, $oid_memAvailReal,
$oid_memShared, $oid_memBuffer, $oid_memCached];
if (defined($self->{option_results}->{check_swap})) {
push @$oids, ($oid_memTotalSwap, $oid_memAvailSwap);
}
my $result = $self->{snmp}->get_leef(oids => $oids,
nothing_quit => 1);
my $shared_used = defined($result->{$oid_memShared}) ? $result->{$oid_memShared} * 1024 : 0;
my $cached_used = $result->{$oid_memCached} * 1024;
@ -115,10 +134,34 @@ sub run {
min => 0);
$self->{output}->perfdata_add(label => "used",
value => $nobuf_used,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1),
min => 0, max => $total_size);
if (defined($self->{option_results}->{check_swap})) {
$total_size = $result->{$oid_memTotalSwap} * 1024;
my $swap_used = ($result->{$oid_memTotalSwap} - $result->{$oid_memAvailSwap}) * 1024;
$prct_used = $swap_used * 100 / $total_size;
$exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical-swap', 'exit_litteral' => 'critical' }, { label => 'warning-swap', exit_litteral => 'warning' } ]);
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size);
my ($swap_used_value, $swap_used_unit) = $self->{perfdata}->change_bytes(value => $swap_used);
my ($swap_free_value, $swap_free_unit) = $self->{perfdata}->change_bytes(value => ($total_size - $swap_used));
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_value . " " . $total_unit,
$swap_used_value . " " . $swap_used_unit, $prct_used,
$swap_free_value . " " . $swap_free_unit, (100 - $prct_used)));
$self->{output}->perfdata_add(label => "swap",
value => $swap_used,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-swap', total => $total_size, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-swap', total => $total_size, cast_int => 1),
min => 0, max => $total_size);
}
$self->{output}->display();
$self->{output}->exit();
}
@ -141,6 +184,18 @@ Threshold warning in percent.
Threshold critical in percent.
=item B<-swap>
Check swap also.
=item B<--warning-swap>
Threshold warning in percent.
=item B<--critical-swap>
Threshold critical in percent.
=back
=cut

View File

@ -96,8 +96,8 @@ sub run {
$self->{output}->perfdata_add(label => "used",
value => $swap_used,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1),
min => 0, max => $total_size);
$self->{output}->display();