summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSubhendu Ghosh <sghosh@users.sourceforge.net>2002-06-06 04:15:49 (GMT)
committerSubhendu Ghosh <sghosh@users.sourceforge.net>2002-06-06 04:15:49 (GMT)
commit9e971876cd15292c7e1c02deb829bd478789eed4 (patch)
tree92560738e5f536be7c77e0cb7fb5f712fbb2d9e0
parent33d91abe09df43a041a8067c1e0e54450eba012c (diff)
downloadmonitoring-plugins-9e971876cd15292c7e1c02deb829bd478789eed4.tar.gz
added option for mount point - Tom Bertelson
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@46 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--plugins/check_disk.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index d7aad07..7429424 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -51,6 +51,7 @@ float w_dfp = -1.0;
51float c_dfp = -1.0; 51float c_dfp = -1.0;
52char *path = NULL; 52char *path = NULL;
53int verbose = FALSE; 53int verbose = FALSE;
54int display_mntp = FALSE;
54 55
55int 56int
56main (int argc, char **argv) 57main (int argc, char **argv)
@@ -64,6 +65,7 @@ main (int argc, char **argv)
64 char *command_line = NULL; 65 char *command_line = NULL;
65 char input_buffer[MAX_INPUT_BUFFER] = ""; 66 char input_buffer[MAX_INPUT_BUFFER] = "";
66 char file_system[MAX_INPUT_BUFFER] = ""; 67 char file_system[MAX_INPUT_BUFFER] = "";
68 char mntp[MAX_INPUT_BUFFER] = "";
67 char outbuf[MAX_INPUT_BUFFER] = ""; 69 char outbuf[MAX_INPUT_BUFFER] = "";
68 char *output = NULL; 70 char *output = NULL;
69 71
@@ -92,15 +94,16 @@ main (int argc, char **argv)
92 continue; 94 continue;
93 95
94 if (sscanf 96 if (sscanf
95 (input_buffer, "%s %d %d %d %d%%", file_system, &total_disk, 97 (input_buffer, "%s %d %d %d %d%% %s", file_system, &total_disk,
96 &used_disk, &free_disk, &usp) == 5 98 &used_disk, &free_disk, &usp, &mntp) == 6
97 || sscanf (input_buffer, "%s %*s %d %d %d %d%%", file_system, 99 || sscanf (input_buffer, "%s %*s %d %d %d %d%% %s", file_system,
98 &total_disk, &used_disk, &free_disk, &usp) == 5) { 100 &total_disk, &used_disk, &free_disk, &usp, &mntp) == 6) {
101
99 result = max (result, check_disk (usp, free_disk)); 102 result = max (result, check_disk (usp, free_disk));
100 len = 103 len =
101 snprintf (outbuf, MAX_INPUT_BUFFER - 1, 104 snprintf (outbuf, MAX_INPUT_BUFFER - 1,
102 " [%d kB (%d%%) free on %s]", free_disk, 100 - usp, 105 " [%d kB (%d%%) free on %s]", free_disk, 100 - usp,
103 file_system); 106 display_mntp ? mntp : file_system);
104 outbuf[len] = 0; 107 outbuf[len] = 0;
105 output = strscat (output, outbuf); 108 output = strscat (output, outbuf);
106 } 109 }
@@ -121,8 +124,8 @@ main (int argc, char **argv)
121 if (spclose (child_process)) 124 if (spclose (child_process))
122 result = max (result, STATE_WARNING); 125 result = max (result, STATE_WARNING);
123 126
124 else if (usp < 0) 127 if (usp < 0)
125 printf ("Disk %s not mounted or nonexistant\n", argv[3]); 128 printf ("Disk \"%s\" not mounted or nonexistant\n", path);
126 else if (result == STATE_UNKNOWN) 129 else if (result == STATE_UNKNOWN)
127 printf ("Unable to read output\n%s\n%s\n", command_line, input_buffer); 130 printf ("Unable to read output\n%s\n%s\n", command_line, input_buffer);
128 else 131 else
@@ -183,6 +186,7 @@ call_getopt (int argc, char **argv)
183 {"verbose", no_argument, 0, 'v'}, 186 {"verbose", no_argument, 0, 'v'},
184 {"version", no_argument, 0, 'V'}, 187 {"version", no_argument, 0, 'V'},
185 {"help", no_argument, 0, 'h'}, 188 {"help", no_argument, 0, 'h'},
189 {"mountpoint", no_argument, 0, 'm'},
186 {0, 0, 0, 0} 190 {0, 0, 0, 0}
187 }; 191 };
188#endif 192#endif
@@ -190,9 +194,9 @@ call_getopt (int argc, char **argv)
190 while (1) { 194 while (1) {
191#ifdef HAVE_GETOPT_H 195#ifdef HAVE_GETOPT_H
192 c = 196 c =
193 getopt_long (argc, argv, "+?Vhvt:c:w:p:", long_options, &option_index); 197 getopt_long (argc, argv, "+?Vhvt:c:w:p:m", long_options, &option_index);
194#else 198#else
195 c = getopt (argc, argv, "+?Vhvt:c:w:p:"); 199 c = getopt (argc, argv, "+?Vhvt:c:w:p:m");
196#endif 200#endif
197 201
198 i++; 202 i++;
@@ -255,6 +259,9 @@ call_getopt (int argc, char **argv)
255 case 'v': /* verbose */ 259 case 'v': /* verbose */
256 verbose = TRUE; 260 verbose = TRUE;
257 break; 261 break;
262 case 'm': /* display mountpoint */
263 display_mntp = TRUE;
264 break;
258 case 'V': /* version */ 265 case 'V': /* version */
259 print_revision (my_basename (argv[0]), "$Revision$"); 266 print_revision (my_basename (argv[0]), "$Revision$");
260 exit (STATE_OK); 267 exit (STATE_OK);
@@ -335,6 +342,8 @@ print_help (void)
335 " Exit with CRITCAL status if more than PERCENT of disk space is free\n" 342 " Exit with CRITCAL status if more than PERCENT of disk space is free\n"
336 " -p, --path=PATH, --partition=PARTTION\n" 343 " -p, --path=PATH, --partition=PARTTION\n"
337 " Path or partition (checks all mounted partitions if unspecified)\n" 344 " Path or partition (checks all mounted partitions if unspecified)\n"
345 " -m, --mountpoint\n"
346 " Display the mountpoint instead of the partition\n"
338 " -v, --verbose\n" 347 " -v, --verbose\n"
339 " Show details for command-line debugging (do not use with nagios server)\n" 348 " Show details for command-line debugging (do not use with nagios server)\n"
340 " -h, --help\n" 349 " -h, --help\n"
@@ -347,7 +356,7 @@ void
347print_usage (void) 356print_usage (void)
348{ 357{
349 printf 358 printf
350 ("Usage: %s -w limit -c limit [-p path] [-t timeout] [--verbose]\n" 359 ("Usage: %s -w limit -c limit [-p path] [-t timeout] [-m] [--verbose]\n"
351 " %s (-h|--help)\n" 360 " %s (-h|--help)\n"
352 " %s (-V|--version)\n", PROGNAME, PROGNAME, PROGNAME); 361 " %s (-V|--version)\n", PROGNAME, PROGNAME, PROGNAME);
353} 362}