summaryrefslogtreecommitdiffstats
path: root/plugins/check_swap.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r--plugins/check_swap.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 04256adf..d8fc14f2 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -60,9 +60,10 @@ void print_help (void);
60int warn_percent = 0; 60int warn_percent = 0;
61int crit_percent = 0; 61int crit_percent = 0;
62float warn_size_bytes = 0; 62float warn_size_bytes = 0;
63float crit_size_bytes= 0; 63float crit_size_bytes = 0;
64int verbose; 64int verbose;
65int allswaps; 65int allswaps;
66int no_swap_state = STATE_CRITICAL;
66 67
67int 68int
68main (int argc, char **argv) 69main (int argc, char **argv)
@@ -372,6 +373,9 @@ main (int argc, char **argv)
372int 373int
373check_swap (int usp, float free_swap_mb) 374check_swap (int usp, float free_swap_mb)
374{ 375{
376
377 if (!free_swap_mb) return no_swap_state;
378
375 int result = STATE_UNKNOWN; 379 int result = STATE_UNKNOWN;
376 float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ 380 float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */
377 if (usp >= 0 && crit_percent != 0 && usp >= (100.0 - crit_percent)) 381 if (usp >= 0 && crit_percent != 0 && usp >= (100.0 - crit_percent))
@@ -400,6 +404,7 @@ process_arguments (int argc, char **argv)
400 {"warning", required_argument, 0, 'w'}, 404 {"warning", required_argument, 0, 'w'},
401 {"critical", required_argument, 0, 'c'}, 405 {"critical", required_argument, 0, 'c'},
402 {"allswaps", no_argument, 0, 'a'}, 406 {"allswaps", no_argument, 0, 'a'},
407 {"no-swap", required_argument, 0, 'n'},
403 {"verbose", no_argument, 0, 'v'}, 408 {"verbose", no_argument, 0, 'v'},
404 {"version", no_argument, 0, 'V'}, 409 {"version", no_argument, 0, 'V'},
405 {"help", no_argument, 0, 'h'}, 410 {"help", no_argument, 0, 'h'},
@@ -410,7 +415,7 @@ process_arguments (int argc, char **argv)
410 return ERROR; 415 return ERROR;
411 416
412 while (1) { 417 while (1) {
413 c = getopt_long (argc, argv, "+?Vvhac:w:", longopts, &option); 418 c = getopt_long (argc, argv, "+?Vvhac:w:n:", longopts, &option);
414 419
415 if (c == -1 || c == EOF) 420 if (c == -1 || c == EOF)
416 break; 421 break;
@@ -455,6 +460,10 @@ process_arguments (int argc, char **argv)
455 case 'a': /* all swap */ 460 case 'a': /* all swap */
456 allswaps = TRUE; 461 allswaps = TRUE;
457 break; 462 break;
463 case 'n':
464 if ((no_swap_state = mp_translate_state(optarg)) == ERROR) {
465 usage4 (_("no-swap result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
466 }
458 case 'v': /* verbose */ 467 case 'v': /* verbose */
459 verbose++; 468 verbose++;
460 break; 469 break;
@@ -541,6 +550,8 @@ print_help (void)
541 printf (" %s\n", _("Exit with CRITCAL status if less than PERCENT of swap space is free")); 550 printf (" %s\n", _("Exit with CRITCAL status if less than PERCENT of swap space is free"));
542 printf (" %s\n", "-a, --allswaps"); 551 printf (" %s\n", "-a, --allswaps");
543 printf (" %s\n", _("Conduct comparisons for all swap partitions, one by one")); 552 printf (" %s\n", _("Conduct comparisons for all swap partitions, one by one"));
553 printf (" %s\n", "-n, --no-swap=<ok|warning|critical|unknown>");
554 printf (" %s %s\n", _("Resulting state when there is no swap regardless of thresholds. Default:"), state_text(no_swap_state));
544 printf (UT_VERBOSE); 555 printf (UT_VERBOSE);
545 556
546 printf ("\n"); 557 printf ("\n");