diff options
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r-- | plugins/check_swap.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 7cbd46b4..26dba0bc 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -1,10 +1,10 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Nagios check_disk plugin | 3 | * Monitoring check_disk plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net) | 6 | * Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net) |
7 | * Copyright (c) 2000-2007 Nagios Plugins Development Team | 7 | * Copyright (c) 2000-2007 Monitoring Plugins Development Team |
8 | * | 8 | * |
9 | * Description: | 9 | * Description: |
10 | * | 10 | * |
@@ -29,7 +29,7 @@ | |||
29 | 29 | ||
30 | const char *progname = "check_swap"; | 30 | const char *progname = "check_swap"; |
31 | const char *copyright = "2000-2007"; | 31 | const char *copyright = "2000-2007"; |
32 | const char *email = "devel@nagios-plugins.org"; | 32 | const char *email = "devel@monitoring-plugins.org"; |
33 | 33 | ||
34 | #include "common.h" | 34 | #include "common.h" |
35 | #include "popen.h" | 35 | #include "popen.h" |
@@ -60,9 +60,10 @@ void print_help (void); | |||
60 | int warn_percent = 0; | 60 | int warn_percent = 0; |
61 | int crit_percent = 0; | 61 | int crit_percent = 0; |
62 | float warn_size_bytes = 0; | 62 | float warn_size_bytes = 0; |
63 | float crit_size_bytes= 0; | 63 | float crit_size_bytes = 0; |
64 | int verbose; | 64 | int verbose; |
65 | int allswaps; | 65 | int allswaps; |
66 | int no_swap_state = STATE_CRITICAL; | ||
66 | 67 | ||
67 | int | 68 | int |
68 | main (int argc, char **argv) | 69 | main (int argc, char **argv) |
@@ -350,7 +351,7 @@ main (int argc, char **argv) | |||
350 | if(total_swap_mb) { | 351 | if(total_swap_mb) { |
351 | percent_used = 100 * ((double) used_swap_mb) / ((double) total_swap_mb); | 352 | percent_used = 100 * ((double) used_swap_mb) / ((double) total_swap_mb); |
352 | } else { | 353 | } else { |
353 | percent_used = 0; | 354 | percent_used = 100; |
354 | } | 355 | } |
355 | 356 | ||
356 | result = max_state (result, check_swap (percent_used, free_swap_mb)); | 357 | result = max_state (result, check_swap (percent_used, free_swap_mb)); |
@@ -372,6 +373,9 @@ main (int argc, char **argv) | |||
372 | int | 373 | int |
373 | check_swap (int usp, float free_swap_mb) | 374 | check_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; |
@@ -538,13 +547,16 @@ print_help (void) | |||
538 | printf (" %s\n", "-c, --critical=INTEGER"); | 547 | printf (" %s\n", "-c, --critical=INTEGER"); |
539 | printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER bytes of swap space are free")); | 548 | printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER bytes of swap space are free")); |
540 | printf (" %s\n", "-c, --critical=PERCENT%%"); | 549 | printf (" %s\n", "-c, --critical=PERCENT%%"); |
541 | printf (" %s\n", _("Exit with CRITCAL status if less than PERCENT of swap space is free")); | 550 | printf (" %s\n", _("Exit with CRITICAL 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"); |
547 | printf ("%s\n", _("Notes:")); | 558 | printf ("%s\n", _("Notes:")); |
559 | printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); | ||
548 | printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); | 560 | printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); |
549 | 561 | ||
550 | printf (UT_SUPPORT); | 562 | printf (UT_SUPPORT); |
@@ -556,6 +568,6 @@ void | |||
556 | print_usage (void) | 568 | print_usage (void) |
557 | { | 569 | { |
558 | printf ("%s\n", _("Usage:")); | 570 | printf ("%s\n", _("Usage:")); |
559 | printf ("%s [-av] -w <percent_free>%% -c <percent_free>%%\n",progname); | 571 | printf (" %s [-av] -w <percent_free>%% -c <percent_free>%%\n",progname); |
560 | printf ("%s [-av] -w <bytes_free> -c <bytes_free>\n", progname); | 572 | printf (" -w <bytes_free> -c <bytes_free> [-n <state>]\n"); |
561 | } | 573 | } |