diff options
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 499a8d2..56c5f42 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -399,28 +399,30 @@ check_swap(float free_swap_mb, float total_swap_mb) | |||
399 | if (!total_swap_mb) return no_swap_state; | 399 | if (!total_swap_mb) return no_swap_state; |
400 | 400 | ||
401 | uint64_t free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ | 401 | uint64_t free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ |
402 | |||
403 | if (!crit.is_percentage && crit.value >= free_swap) return STATE_CRITICAL; | ||
404 | if (!warn.is_percentage && warn.value >= free_swap) return STATE_WARNING; | ||
405 | |||
406 | |||
407 | uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; | 402 | uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; |
408 | 403 | ||
409 | if (crit.is_percentage && | 404 | if (warn.value && crit.value) { /* Thresholds defined */ |
410 | crit.value != 0 && | 405 | if (!crit.is_percentage && crit.value >= free_swap) return STATE_CRITICAL; |
411 | usage_percentage >= (100 - crit.value)) | 406 | if (!warn.is_percentage && warn.value >= free_swap) return STATE_WARNING; |
412 | { | 407 | |
413 | return STATE_CRITICAL; | 408 | if (crit.is_percentage && |
414 | } | 409 | crit.value != 0 && |
415 | 410 | usage_percentage >= (100 - crit.value)) | |
416 | if (warn.is_percentage && | 411 | { |
417 | warn.value != 0 && | 412 | return STATE_CRITICAL; |
418 | usage_percentage >= (100 - warn.value)) | 413 | } |
419 | { | 414 | |
420 | return STATE_WARNING; | 415 | if (warn.is_percentage && |
421 | } | 416 | warn.value != 0 && |
422 | 417 | usage_percentage >= (100 - warn.value)) | |
423 | return STATE_OK; | 418 | { |
419 | return STATE_WARNING; | ||
420 | } | ||
421 | |||
422 | return STATE_OK; | ||
423 | } else { /* Without thresholds */ | ||
424 | return STATE_OK; | ||
425 | } | ||
424 | } | 426 | } |
425 | 427 | ||
426 | 428 | ||
@@ -443,9 +445,6 @@ process_arguments (int argc, char **argv) | |||
443 | {0, 0, 0, 0} | 445 | {0, 0, 0, 0} |
444 | }; | 446 | }; |
445 | 447 | ||
446 | if (argc < 2) | ||
447 | return ERROR; | ||
448 | |||
449 | while (1) { | 448 | while (1) { |
450 | c = getopt_long (argc, argv, "+?Vvhac:w:n:", longopts, &option); | 449 | c = getopt_long (argc, argv, "+?Vvhac:w:n:", longopts, &option); |
451 | 450 | ||
@@ -547,9 +546,12 @@ process_arguments (int argc, char **argv) | |||
547 | int | 546 | int |
548 | validate_arguments (void) | 547 | validate_arguments (void) |
549 | { | 548 | { |
550 | if (warn.value == 0 && crit.value == 0) { | 549 | if (warn.value && !crit.value) { |
551 | return ERROR; | 550 | usage4(_("Must define both warning and critical thresholds")); |
552 | } | 551 | } |
552 | else if (crit.value && !warn.value) { | ||
553 | usage4(_("Must define both warning and critical thresholds")); | ||
554 | } | ||
553 | else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) { | 555 | else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) { |
554 | /* This is NOT triggered if warn and crit are different units, e.g warn is percentage | 556 | /* This is NOT triggered if warn and crit are different units, e.g warn is percentage |
555 | * and crit is absolute. We cannot determine the condition at this point since we | 557 | * and crit is absolute. We cannot determine the condition at this point since we |
@@ -595,6 +597,7 @@ print_help (void) | |||
595 | printf ("\n"); | 597 | printf ("\n"); |
596 | printf ("%s\n", _("Notes:")); | 598 | printf ("%s\n", _("Notes:")); |
597 | printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); | 599 | printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); |
600 | printf (" %s\n", _("Without thresholds, the plugin shows free swap space and performance data, but always returns OK.")); | ||
598 | printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); | 601 | printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); |
599 | 602 | ||
600 | printf (UT_SUPPORT); | 603 | printf (UT_SUPPORT); |
@@ -605,6 +608,6 @@ void | |||
605 | print_usage (void) | 608 | print_usage (void) |
606 | { | 609 | { |
607 | printf ("%s\n", _("Usage:")); | 610 | printf ("%s\n", _("Usage:")); |
608 | printf (" %s [-av] -w <percent_free>%% -c <percent_free>%%\n",progname); | 611 | printf (" %s [-av] [-w <percent_free>%%] [-c <percent_free>%%]\n",progname); |
609 | printf (" -w <bytes_free> -c <bytes_free> [-n <state>]\n"); | 612 | printf (" [-w <bytes_free>] [-c <bytes_free>] [-n <state>]\n"); |
610 | } | 613 | } |