From bd9a612f6c18fcc9b17e5abf58def18b19521d82 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Thu, 12 Oct 2006 13:58:43 +0000 Subject: Fixed output from -e in check_disk (Andreas Behal) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1490 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/NPTest.pm b/NPTest.pm index 1372d14..432f396 100644 --- a/NPTest.pm +++ b/NPTest.pm @@ -603,6 +603,13 @@ sub perf_output { return $1 || ""; } +sub only_output { + my $self = shift; + $_ = $self->{output}; + /(.*?)\|/; + return $1 || ""; +} + sub testCmd { my $class = shift; my $command = shift or die "No command passed to testCmd"; diff --git a/THANKS.in b/THANKS.in index 5cdcdf7..5bc5208 100644 --- a/THANKS.in +++ b/THANKS.in @@ -191,3 +191,4 @@ Lance Albertson Nathan Vonnahme Mike Emigh Christian Mies +Andreas Behal diff --git a/plugins/check_disk.c b/plugins/check_disk.c index b546fd2..b9787c8 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -206,6 +206,10 @@ main (int argc, char **argv) /* Process for every path in list */ for (path = path_select_list; path; path=path->name_next) { + + /* reset disk result */ + disk_result = STATE_UNKNOWN; + me = path->best_match; /* Filters */ @@ -258,23 +262,25 @@ main (int argc, char **argv) temp_result = get_status(dfree_units, path->freespace_units); if (verbose >=3) printf("Freespace_units result=%d\n", temp_result); - result = max_state( result, temp_result ); + disk_result = max_state( disk_result, temp_result ); temp_result = get_status(dfree_pct, path->freespace_percent); if (verbose >=3) printf("Freespace%% result=%d\n", temp_result); - result = max_state( result, temp_result ); + disk_result = max_state( disk_result, temp_result ); temp_result = get_status(dused_units, path->usedspace_units); if (verbose >=3) printf("Usedspace_units result=%d\n", temp_result); - result = max_state( result, temp_result ); + disk_result = max_state( disk_result, temp_result ); temp_result = get_status(dused_pct, path->usedspace_percent); if (verbose >=3) printf("Usedspace_percent result=%d\n", temp_result); - result = max_state( result, temp_result ); + disk_result = max_state( disk_result, temp_result ); temp_result = get_status(dused_inodes_percent, path->usedinodes_percent); if (verbose >=3) printf("Usedinodes_percent result=%d\n", temp_result); - result = max_state( result, temp_result ); + disk_result = max_state( disk_result, temp_result ); + + result = max_state(result, disk_result); asprintf (&perf, "%s %s", perf, perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index 6634492..0fe87aa 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t @@ -22,7 +22,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { plan skip_all => "Need 2 mountpoints to test"; } else { - plan tests => 35; + plan tests => 39; } $result = NPTest->testCmd( @@ -85,6 +85,16 @@ $result = NPTest->testCmd( "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" ); cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); +my $all_disks = $result->output; + +$result = NPTest->testCmd( + "./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" + ); +isnt( $result->output, $all_disks, "-e gives different output"); +like( $result->output, qr/$less_free/, "Found problem $less_free"); +unlike( $result->only_output, qr/$more_free/, "Has ignored $more_free as not a problem"); +like( $result->perf_output, qr/$more_free/, "But $more_free is still in perf data"); + @@ -97,7 +107,6 @@ $result = NPTest->testCmd( "./check_disk -w $avg_free% -c $avg_free% -p $less_free" ); cmp_ok( $result->return_code, '==', 2, "Get critical on less_free, checking avg_free"); - $result = NPTest->testCmd( "./check_disk -w $avg_free% -c 0% -p $more_free -w $avg_free% -c $avg_free% -p $less_free" ); -- cgit v0.10-9-g596f