فهرست منبع

Incorrect output when checking non-existent disk (John Rouillard - 1326050)

git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1349 f882894a-f735-0410-b71e-b25c423dba1c
Ton Voon 20 سال پیش
والد
کامیت
61cd9f525a
3فایلهای تغییر یافته به همراه25 افزوده شده و 4 حذف شده
  1. 7 0
      NPTest.pm
  2. 1 3
      plugins/check_disk.c
  3. 17 1
      plugins/t/check_disk.t

+ 7 - 0
NPTest.pm

@@ -596,6 +596,13 @@ sub output {
 	}
 }
 
+sub perf_output {
+	my $self = shift;
+	$_ = $self->{output};
+	s/[^|]*\|//;
+	return $_;
+}
+
 sub testCmd {
 	my $class = shift;
 	my $command = shift or die "No command passed to testCmd";

+ 1 - 3
plugins/check_disk.c

@@ -275,8 +275,6 @@ main (int argc, char **argv)
 
   }
 
-  asprintf (&output, "%s|%s", output, perf);
-
   if (verbose > 2)
     asprintf (&output, "%s%s", output, details);
 
@@ -290,7 +288,7 @@ main (int argc, char **argv)
     temp_list = temp_list->name_next;
   }
 
-  printf ("DISK %s%s\n", state_text (result), output);
+  printf ("DISK %s%s|%s\n", state_text (result), output, perf);
   return result;
 }
 

+ 17 - 1
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 => 26;
+	plan tests => 31;
 }
 
 $result = NPTest->testCmd( 
@@ -157,3 +157,19 @@ TODO: {
 $result = NPTest->testCmd( "./check_disk 200 0 $mountpoint_valid" );
 cmp_ok( $result->return_code, '==', 3, "Old syntax: Error with values outside percent range" );
 
+TODO: {
+	local $TODO = "Check existence of each filesystem as a directory";
+	$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /bob" );
+	cmp_ok( $result->return_code, '==', 2, "Checking /bob - return error because /bob does not exist" );
+}
+
+$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /" );
+my $root_output = $result->output;
+
+$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /etc" );
+cmp_ok( $result->return_code, '==', 0, "Checking /etc - should return info for /" );
+cmp_ok( $result->output, 'eq', $root_output, "check_disk /etc gives same as check_disk /");
+
+$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /bob" );
+cmp_ok( $result->return_code, '==', 2, "Checking / and /bob gives critical");
+unlike( $result->perf_output, 'm#/bob#', "perf data does not have /bob in it");