[monitoring-plugins] check_disk: fix ugly output with -e option and ...

Kristian Schuster git at monitoring-plugins.org
Sat Mar 11 10:30:12 CET 2023


 Module: monitoring-plugins
 Branch: master
 Commit: e102b8a49e857a474db516455d2e871e6834ae34
 Author: Kristian Schuster <116557017+KriSchu at users.noreply.github.com>
   Date: Mon Feb 20 02:03:01 2023 +0100
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=e102b8a

check_disk: fix ugly output with -e option and adapt tests accordingly

---

 plugins/check_disk.c   | 10 +++++-----
 plugins/t/check_disk.t |  8 ++++----
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index d32841d..c52d1df 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -186,8 +186,8 @@ main (int argc, char **argv)
   char mountdir[32];
 #endif
 
-  preamble = strdup (" free space:");
-  ignored_preamble = strdup (" ignored paths:");
+  preamble = strdup (" - free space:");
+  ignored_preamble = strdup (" - ignored paths:");
   output = strdup ("");
   ignored = strdup ("");
   details = strdup ("");
@@ -455,12 +455,12 @@ main (int argc, char **argv)
   if (verbose >= 2)
     xasprintf (&output, "%s%s", output, details);
 
-  if (strcmp(output, "") == 0) {
+  if (strcmp(output, "") == 0 && ! erronly) {
     preamble = "";
-    xasprintf (&output, " No disks were found for provided parameters;");
+    xasprintf (&output, " - No disks were found for provided parameters;");
   }
 
-  printf ("DISK %s -%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf);
+  printf ("DISK %s%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf);
   return result;
 }
 
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t
index 73f1e37..c8f08f5 100644
--- a/plugins/t/check_disk.t
+++ b/plugins/t/check_disk.t
@@ -126,7 +126,7 @@ my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
 
 
 $result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free" );
-is( $result->only_output, "DISK OK - No disks were found for provided parameters;", "No print out of disks with -e for OKs");
+is( $result->only_output, "DISK OK", "No print out of disks with -e for OKs");
 
 $result = NPTest->testCmd( "./check_disk 100 100 $more_free" );
 cmp_ok( $result->return_code, '==', 0, "Old syntax okay" );
@@ -355,7 +355,7 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo
 # ignore-missing: exit okay, when fs is not accessible
 $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob");
 cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob");
-like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /bob;.*$/', 'Output OK');
+like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /bob;.*$/', 'Output OK');
 
 # ignore-missing: exit okay, when regex does not match
 $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob");
@@ -365,7 +365,7 @@ like( $result->output, '/^DISK OK - No disks were found for provided parameters;
 # ignore-missing: exit okay, when fs with exact match (-E) is not found
 $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc");
 cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs");
-like( $result->output, '/^DISK OK - No disks were found for provided parameters; ignored paths: /etc;.*$/', 'Output OK');
+like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /etc;.*$/', 'Output OK');
 
 # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex)
 $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'");
@@ -375,4 +375,4 @@ like( $result->output, '/^DISK OK - free space: \/ .*$/', 'Output OK');
 # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path)
 $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'");
 cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
-like( $result->output, '/^DISK OK - free space: / .*; ignored paths: /bob;.*$/', 'Output OK');
\ No newline at end of file
+like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK');
\ No newline at end of file



More information about the Commits mailing list