Просмотр исходного кода

Added newline switch for multi-line output of drives

Trevor McDonald 12 лет назад
Родитель
Сommit
2103f155a0
1 измененных файлов с 23 добавлено и 6 удалено
  1. 23 6
      plugins/check_disk.c

+ 23 - 6
plugins/check_disk.c

@@ -135,6 +135,7 @@ char *exclude_device;
 char *units;
 uintmax_t mult = 1024 * 1024;
 int verbose = 0;
+int newline = FALSE;
 int erronly = FALSE;
 int display_mntp = FALSE;
 int exact_match = FALSE;
@@ -344,10 +345,19 @@ main (int argc, char **argv)
                 path->dfree_units,
                 units,
                 path->dfree_pct);
-      if (path->dused_inodes_percent < 0) {
-        xasprintf(&output, "%s inode=-);", output);
+      /* Whether or not to put all disks on new line */
+      if (newline) {
+        if (path->dused_inodes_percent < 0) {
+          xasprintf(&output, "%s inode=-);\n", output);
+        } else {
+          xasprintf(&output, "%s inode=%.0f%%);\n", output, path->dfree_inodes_percent );
+        }
       } else {
-        xasprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent );
+        if (path->dused_inodes_percent < 0) {
+          xasprintf(&output, "%s inode=-);", output);
+        } else {
+          xasprintf(&output, "%s inode=%.0f%%);", output, path->dfree_inodes_percent );
+        }
       }
 
       /* TODO: Need to do a similar debug line
@@ -365,8 +375,11 @@ main (int argc, char **argv)
   if (verbose >= 2)
     xasprintf (&output, "%s%s", output, details);
 
-
-  printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf);
+  if (newline) {
+    printf ("DISK %s%s\n%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf);
+  } else {
+    printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf);
+  }
   return result;
 }
 
@@ -427,6 +440,7 @@ process_arguments (int argc, char **argv)
     {"exclude_device", required_argument, 0, 'x'},
     {"exclude-type", required_argument, 0, 'X'},
     {"include-type", required_argument, 0, 'N'},
+    {"newlines", no_argument, 0, 'n'},
     {"group", required_argument, 0, 'g'},
     {"eregi-path", required_argument, 0, 'R'},
     {"eregi-partition", required_argument, 0, 'R'},
@@ -461,7 +475,7 @@ process_arguments (int argc, char **argv)
       strcpy (argv[c], "-t");
 
   while (1) {
-    c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEA", longopts, &option);
+    c = getopt_long (argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLg:R:r:i:I:MEAn", longopts, &option);
 
     if (c == -1 || c == EOF)
       break;
@@ -603,6 +617,9 @@ process_arguments (int argc, char **argv)
     case 'N':                 /* include file system type */
       np_add_name(&fs_include_list, optarg);
       break;
+    case 'n':                 /* show each disk on a new line */
+      newline = TRUE;
+      break;
     case 'v':                 /* verbose */
       verbose++;
       break;