diff options
| author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-01-13 04:50:03 +0000 |
|---|---|---|
| committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-01-13 04:50:03 +0000 |
| commit | 2eda58cc9130eebf2fb8117d6e7468686992e196 (patch) | |
| tree | c8ab3bd8e38816276218953129581abd23fd4622 /plugins | |
| parent | 86bf45146e30e16bde8b27b02ad95fac26838170 (diff) | |
| download | monitoring-plugins-2eda58cc9130eebf2fb8117d6e7468686992e196.tar.gz | |
add options for excluding devices and for skipping OK devices in summary
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@235 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_disk.c | 94 |
1 files changed, 61 insertions, 33 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 26d9ac97..55343059 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
| @@ -36,7 +36,6 @@ | |||
| 36 | #include "utils.h" | 36 | #include "utils.h" |
| 37 | #include <stdarg.h> | 37 | #include <stdarg.h> |
| 38 | 38 | ||
| 39 | #define PROGNAME "check_disk" | ||
| 40 | #define REVISION "$Revision$" | 39 | #define REVISION "$Revision$" |
| 41 | #define COPYRIGHT "2000-2002" | 40 | #define COPYRIGHT "2000-2002" |
| 42 | 41 | ||
| @@ -46,29 +45,31 @@ int check_disk (int usp, int free_disk); | |||
| 46 | void print_help (void); | 45 | void print_help (void); |
| 47 | void print_usage (void); | 46 | void print_usage (void); |
| 48 | 47 | ||
| 48 | const char *PROGNAME = "check_disk"; | ||
| 49 | |||
| 49 | int w_df = -1; | 50 | int w_df = -1; |
| 50 | int c_df = -1; | 51 | int c_df = -1; |
| 51 | float w_dfp = -1.0; | 52 | float w_dfp = -1.0; |
| 52 | float c_dfp = -1.0; | 53 | float c_dfp = -1.0; |
| 53 | char *path = ""; | 54 | char *path = ""; |
| 54 | int verbose = FALSE; | 55 | char *exclude_device = ""; |
| 56 | int verbose = 0; | ||
| 55 | int display_mntp = FALSE; | 57 | int display_mntp = FALSE; |
| 56 | 58 | ||
| 59 | |||
| 57 | int | 60 | int |
| 58 | main (int argc, char **argv) | 61 | main (int argc, char **argv) |
| 59 | { | 62 | { |
| 60 | int len; | ||
| 61 | int usp = -1; | 63 | int usp = -1; |
| 62 | int total_disk = -1; | 64 | int total_disk = -1; |
| 63 | int used_disk = -1; | 65 | int used_disk = -1; |
| 64 | int free_disk = -1; | 66 | int free_disk = -1; |
| 65 | int result = STATE_UNKNOWN; | 67 | int result = STATE_UNKNOWN; |
| 66 | int temp_result = STATE_UNKNOWN; | 68 | int disk_result = STATE_UNKNOWN; |
| 67 | char *command_line = NULL; | 69 | char *command_line = ""; |
| 68 | char input_buffer[MAX_INPUT_BUFFER] = ""; | 70 | char input_buffer[MAX_INPUT_BUFFER]; |
| 69 | char file_system[MAX_INPUT_BUFFER] = ""; | 71 | char file_system[MAX_INPUT_BUFFER]; |
| 70 | char mntp[MAX_INPUT_BUFFER] = ""; | 72 | char mntp[MAX_INPUT_BUFFER]; |
| 71 | char outbuf[MAX_INPUT_BUFFER] = ""; | ||
| 72 | char *output = ""; | 73 | char *output = ""; |
| 73 | 74 | ||
| 74 | if (process_arguments (argc, argv) != OK) | 75 | if (process_arguments (argc, argv) != OK) |
| @@ -76,7 +77,7 @@ main (int argc, char **argv) | |||
| 76 | 77 | ||
| 77 | asprintf (&command_line, "%s %s", DF_COMMAND, path); | 78 | asprintf (&command_line, "%s %s", DF_COMMAND, path); |
| 78 | 79 | ||
| 79 | if (verbose) | 80 | if (verbose>0) |
| 80 | printf ("%s ==> ", command_line); | 81 | printf ("%s ==> ", command_line); |
| 81 | 82 | ||
| 82 | child_process = spopen (command_line); | 83 | child_process = spopen (command_line); |
| @@ -95,15 +96,30 @@ main (int argc, char **argv) | |||
| 95 | if (!index (input_buffer, '/')) | 96 | if (!index (input_buffer, '/')) |
| 96 | continue; | 97 | continue; |
| 97 | 98 | ||
| 98 | if (sscanf | 99 | if (sscanf (input_buffer, "%s %d %d %d %d%% %s", file_system, |
| 99 | (input_buffer, "%s %d %d %d %d%% %s", file_system, &total_disk, | 100 | &total_disk, &used_disk, &free_disk, &usp, mntp) == 6 || |
| 100 | &used_disk, &free_disk, &usp, &mntp) == 6 | 101 | sscanf (input_buffer, "%s %*s %d %d %d %d%% %s", file_system, |
| 101 | || sscanf (input_buffer, "%s %*s %d %d %d %d%% %s", file_system, | 102 | &total_disk, &used_disk, &free_disk, &usp, mntp) == 6) { |
| 102 | &total_disk, &used_disk, &free_disk, &usp, &mntp) == 6) { | 103 | |
| 103 | asprintf (&output, "%s [%d kB (%d%%) free on %s]", output, free_disk, | 104 | if (strcmp(exclude_device,file_system) == 0 || |
| 104 | 100 - usp, display_mntp ? mntp : file_system); | 105 | strcmp(exclude_device,mntp) == 0) { |
| 105 | result = max_state (result, check_disk (usp, free_disk)); | 106 | if (verbose>0) |
| 107 | printf ("ignoring %s.", file_system); | ||
| 108 | continue; | ||
| 109 | } | ||
| 110 | |||
| 111 | disk_result = check_disk (usp, free_disk); | ||
| 112 | |||
| 113 | if (strcmp (file_system, "none") == 0) | ||
| 114 | strncpy (file_system, mntp, MAX_INPUT_BUFFER-1); | ||
| 115 | |||
| 116 | if (disk_result!=STATE_OK || verbose>=0) | ||
| 117 | asprintf (&output, "%s [%d kB (%d%%) free on %s]", output, | ||
| 118 | free_disk, 100 - usp, display_mntp ? mntp : file_system); | ||
| 119 | |||
| 120 | result = max_state (result, disk_result); | ||
| 106 | } | 121 | } |
| 122 | |||
| 107 | else { | 123 | else { |
| 108 | printf ("Unable to read output:\n%s\n%s\n", command_line, input_buffer); | 124 | printf ("Unable to read output:\n%s\n%s\n", command_line, input_buffer); |
| 109 | return result; | 125 | return result; |
| @@ -112,27 +128,26 @@ main (int argc, char **argv) | |||
| 112 | } | 128 | } |
| 113 | 129 | ||
| 114 | /* If we get anything on stderr, at least set warning */ | 130 | /* If we get anything on stderr, at least set warning */ |
| 115 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | 131 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { |
| 116 | /*result = max (result, STATE_WARNING); */ | 132 | if (result != STATE_CRITICAL) { |
| 117 | if( !( result == STATE_CRITICAL) ) { | ||
| 118 | result = STATE_WARNING; | 133 | result = STATE_WARNING; |
| 119 | } | 134 | } |
| 135 | } | ||
| 120 | 136 | ||
| 121 | /* close stderr */ | 137 | /* close stderr */ |
| 122 | (void) fclose (child_stderr); | 138 | if (child_stderr) |
| 139 | (void) fclose (child_stderr); | ||
| 123 | 140 | ||
| 124 | /* close the pipe */ | 141 | /* close the pipe */ |
| 125 | if (spclose (child_process)) | 142 | if (spclose(child_process)!=0 && result!=STATE_CRITICAL) |
| 126 | /*result = max (result, STATE_WARNING); */ | ||
| 127 | if( !( result == STATE_CRITICAL) ) { | ||
| 128 | result = STATE_WARNING; | 143 | result = STATE_WARNING; |
| 129 | } | 144 | |
| 130 | if (usp < 0) | 145 | if (usp < 0) |
| 131 | printf ("Disk \"%s\" not mounted or nonexistant\n", path); | 146 | printf ("Disk \"%s\" not mounted or nonexistant\n", path); |
| 132 | else if (result == STATE_UNKNOWN) | 147 | else if (result == STATE_UNKNOWN) |
| 133 | printf ("Unable to read output\n%s\n%s\n", command_line, input_buffer); | 148 | printf ("Unable to read output\n%s\n%s\n", command_line, input_buffer); |
| 134 | else | 149 | else |
| 135 | printf ("DISK %s -%s\n", state_text (result), output); | 150 | printf ("DISK %s%s\n", state_text (result), output); |
| 136 | 151 | ||
| 137 | return result; | 152 | return result; |
| 138 | } | 153 | } |
| @@ -155,6 +170,9 @@ process_arguments (int argc, char **argv) | |||
| 155 | {"version", no_argument, 0, 'V'}, | 170 | {"version", no_argument, 0, 'V'}, |
| 156 | {"help", no_argument, 0, 'h'}, | 171 | {"help", no_argument, 0, 'h'}, |
| 157 | {"mountpoint", no_argument, 0, 'm'}, | 172 | {"mountpoint", no_argument, 0, 'm'}, |
| 173 | {"exclude_device", required_argument, 0, 'x'}, | ||
| 174 | {"quiet", no_argument, 0, 'q'}, | ||
| 175 | |||
| 158 | {0, 0, 0, 0} | 176 | {0, 0, 0, 0} |
| 159 | }; | 177 | }; |
| 160 | #endif | 178 | #endif |
| @@ -169,9 +187,9 @@ process_arguments (int argc, char **argv) | |||
| 169 | while (1) { | 187 | while (1) { |
| 170 | #ifdef HAVE_GETOPT_H | 188 | #ifdef HAVE_GETOPT_H |
| 171 | c = | 189 | c = |
| 172 | getopt_long (argc, argv, "Vhvt:c:w:p:m", long_options, &option_index); | 190 | getopt_long (argc, argv, "+?Vqhvt:c:w:p:x:m", long_options, &option_index); |
| 173 | #else | 191 | #else |
| 174 | c = getopt (argc, argv, "Vhvt:c:w:p:m"); | 192 | c = getopt (argc, argv, "+?Vqhvt:c:w:p:x:m"); |
| 175 | #endif | 193 | #endif |
| 176 | 194 | ||
| 177 | if (c == -1 || c == EOF) | 195 | if (c == -1 || c == EOF) |
| @@ -222,11 +240,17 @@ process_arguments (int argc, char **argv) | |||
| 222 | path = optarg; | 240 | path = optarg; |
| 223 | break; | 241 | break; |
| 224 | case 'v': /* verbose */ | 242 | case 'v': /* verbose */ |
| 225 | verbose = TRUE; | 243 | verbose++; |
| 244 | break; | ||
| 245 | case 'q': /* verbose */ | ||
| 246 | verbose--; | ||
| 226 | break; | 247 | break; |
| 227 | case 'm': /* display mountpoint */ | 248 | case 'm': /* display mountpoint */ |
| 228 | display_mntp = TRUE; | 249 | display_mntp = TRUE; |
| 229 | break; | 250 | break; |
| 251 | case 'x': /* exclude path or partition */ | ||
| 252 | exclude_device = optarg; | ||
| 253 | break; | ||
| 230 | case 'V': /* version */ | 254 | case 'V': /* version */ |
| 231 | print_revision (PROGNAME, REVISION); | 255 | print_revision (PROGNAME, REVISION); |
| 232 | exit (STATE_OK); | 256 | exit (STATE_OK); |
| @@ -311,15 +335,19 @@ print_help (void) | |||
| 311 | " -w, --warning=INTEGER\n" | 335 | " -w, --warning=INTEGER\n" |
| 312 | " Exit with WARNING status if less than INTEGER kilobytes of disk are free\n" | 336 | " Exit with WARNING status if less than INTEGER kilobytes of disk are free\n" |
| 313 | " -w, --warning=PERCENT%%\n" | 337 | " -w, --warning=PERCENT%%\n" |
| 314 | " Exit with WARNING status if more than PERCENT of disk space is free\n" | 338 | " Exit with WARNING status if less than PERCENT of disk space is free\n" |
| 315 | " -c, --critical=INTEGER\n" | 339 | " -c, --critical=INTEGER\n" |
| 316 | " Exit with CRITICAL status if less than INTEGER kilobytes of disk are free\n" | 340 | " Exit with CRITICAL status if less than INTEGER kilobytes of disk are free\n" |
| 317 | " -c, --critical=PERCENT%%\n" | 341 | " -c, --critical=PERCENT%%\n" |
| 318 | " Exit with CRITCAL status if more than PERCENT of disk space is free\n" | 342 | " Exit with CRITCAL status if less than PERCENT of disk space is free\n" |
| 319 | " -p, --path=PATH, --partition=PARTTION\n" | 343 | " -p, --path=PATH, --partition=PARTTION\n" |
| 320 | " Path or partition (checks all mounted partitions if unspecified)\n" | 344 | " Path or partition (checks all mounted partitions if unspecified)\n" |
| 321 | " -m, --mountpoint\n" | 345 | " -m, --mountpoint\n" |
| 322 | " Display the mountpoint instead of the partition\n" | 346 | " Display the mountpoint instead of the partition\n" |
| 347 | " -x, --exclude_device=PATH\n" | ||
| 348 | " Ignore device (only works if -p unspecified)\n" | ||
| 349 | " -e, --errors-only\n" | ||
| 350 | " Display only devices/mountpoints with errors\n" | ||
| 323 | " -v, --verbose\n" | 351 | " -v, --verbose\n" |
| 324 | " Show details for command-line debugging (do not use with nagios server)\n" | 352 | " Show details for command-line debugging (do not use with nagios server)\n" |
| 325 | " -h, --help\n" | 353 | " -h, --help\n" |
| @@ -332,7 +360,7 @@ void | |||
| 332 | print_usage (void) | 360 | print_usage (void) |
| 333 | { | 361 | { |
| 334 | printf | 362 | printf |
| 335 | ("Usage: %s -w limit -c limit [-p path] [-t timeout] [-m] [--verbose]\n" | 363 | ("Usage: %s -w limit -c limit [-p path | -x device] [-t timeout] [-m] [-e] [--verbose]\n" |
| 336 | " %s (-h|--help)\n" | 364 | " %s (-h|--help)\n" |
| 337 | " %s (-V|--version)\n", PROGNAME, PROGNAME, PROGNAME); | 365 | " %s (-V|--version)\n", PROGNAME, PROGNAME, PROGNAME); |
| 338 | } | 366 | } |
