From 445d3a41fe0f96446d9164f107f402663f6256bc Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Mon, 23 Jun 2014 15:05:42 +0200 Subject: [PATCH] Fix #5635 --- os/linux/local/mode/swap.pm | 19 +++++++++++++++++++ snmp_standard/mode/memory.pm | 23 +++++++++++++++++++++-- snmp_standard/mode/swap.pm | 23 +++++++++++++++++++++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/os/linux/local/mode/swap.pm b/os/linux/local/mode/swap.pm index 0faf5d9eb..169d8dff1 100644 --- a/os/linux/local/mode/swap.pm +++ b/os/linux/local/mode/swap.pm @@ -61,7 +61,9 @@ sub new { "command-options:s" => { name => 'command_options', default => '/proc/meminfo 2>&1' }, "warning:s" => { name => 'warning', }, "critical:s" => { name => 'critical', }, + "no-swap:s" => { name => 'no_swap' }, }); + $self->{no_swap} = 'critical'; return $self; } @@ -77,6 +79,13 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } + if (defined($self->{option_results}->{no_swap}) && $self->{option_results}->{no_swap} ne '') { + if ($self->{output}->is_litteral_status(status => $self->{option_results}->{no_swap}) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong --no-swap status '" . $self->{option_results}->{no_swap} . "'."); + $self->{output}->option_exit(); + } + $self->{no_swap} = $self->{option_results}->{no_swap}; + } } sub run { @@ -102,6 +111,12 @@ sub run { $self->{output}->add_option_msg(short_msg => "Some informations missing."); $self->{output}->option_exit(); } + if ($total_size == 0) { + $self->{output}->output_add(severity => $self->{no_swap}, + short_msg => 'No active swap.'); + $self->{output}->display(); + $self->{output}->exit(); + } my $swap_used = $total_size - $swap_free; @@ -146,6 +161,10 @@ Threshold warning in percent. Threshold critical in percent. +=item B<--no-swap> + +Threshold if no active swap (default: 'critical'). + =item B<--remote> Execute command remotely in 'ssh'. diff --git a/snmp_standard/mode/memory.pm b/snmp_standard/mode/memory.pm index cc1e8b7f1..3a8207402 100644 --- a/snmp_standard/mode/memory.pm +++ b/snmp_standard/mode/memory.pm @@ -50,11 +50,12 @@ sub new { { "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "swap:s" => { name => 'check_swap' }, + "swap" => { name => 'check_swap' }, "warning-swap:s" => { name => 'warning_swap' }, "critical-swap:s" => { name => 'critical_swap' }, + "no-swap:s" => { name => 'no_swap' }, }); - + $self->{no_swap} = 'critical'; return $self; } @@ -79,6 +80,13 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical-swap threshold '" . $self->{option_results}->{critical_swap} . "'."); $self->{output}->option_exit(); } + if (defined($self->{option_results}->{no_swap}) && $self->{option_results}->{no_swap} ne '') { + if ($self->{output}->is_litteral_status(status => $self->{option_results}->{no_swap}) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong --no-swap status '" . $self->{option_results}->{no_swap} . "'."); + $self->{output}->option_exit(); + } + $self->{no_swap} = $self->{option_results}->{no_swap}; + } } } @@ -139,6 +147,13 @@ sub run { min => 0, max => $total_size); if (defined($self->{option_results}->{check_swap})) { + if ($result->{$oid_memTotalSwap} == 0) { + $self->{output}->output_add(severity => $self->{no_swap}, + short_msg => 'No active swap.'); + $self->{output}->display(); + $self->{output}->exit(); + } + $total_size = $result->{$oid_memTotalSwap} * 1024; my $swap_used = ($result->{$oid_memTotalSwap} - $result->{$oid_memAvailSwap}) * 1024; @@ -196,6 +211,10 @@ Threshold warning in percent. Threshold critical in percent. +=item B<--no-swap> + +Threshold if no active swap (default: 'critical'). + =back =cut diff --git a/snmp_standard/mode/swap.pm b/snmp_standard/mode/swap.pm index 3f9efc78e..032b37a3d 100644 --- a/snmp_standard/mode/swap.pm +++ b/snmp_standard/mode/swap.pm @@ -50,8 +50,9 @@ sub new { { "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, + "no-swap:s" => { name => 'no_swap' }, }); - + $self->{no_swap} = 'critical'; return $self; } @@ -66,7 +67,14 @@ 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}->{no_swap}) && $self->{option_results}->{no_swap} ne '') { + if ($self->{output}->is_litteral_status(status => $self->{option_results}->{no_swap}) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong --no-swap status '" . $self->{option_results}->{no_swap} . "'."); + $self->{output}->option_exit(); + } + $self->{no_swap} = $self->{option_results}->{no_swap}; + } } sub run { @@ -78,6 +86,13 @@ sub run { my $oid_memAvailSwap = '.1.3.6.1.4.1.2021.4.4.0'; # KB my $result = $self->{snmp}->get_leef(oids => [$oid_memTotalSwap, $oid_memAvailSwap], nothing_quit => 1); + if ($result->{$oid_memTotalSwap} == 0) { + $self->{output}->output_add(severity => $self->{no_swap}, + short_msg => 'No active swap.'); + $self->{output}->display(); + $self->{output}->exit(); + } + my $total_size = $result->{$oid_memTotalSwap} * 1024; my $swap_used = ($result->{$oid_memTotalSwap} - $result->{$oid_memAvailSwap}) * 1024; @@ -122,6 +137,10 @@ Threshold warning in percent. Threshold critical in percent. +=item B<--no-swap> + +Threshold if no active swap (default: 'critical'). + =back =cut