summaryrefslogtreecommitdiffstats
path: root/plugins/check_swap.c
diff options
context:
space:
mode:
authorSven Nierlein <sven@consol.de>2024-07-23 19:09:21 (GMT)
committerGitHub <noreply@github.com>2024-07-23 19:09:21 (GMT)
commit562deb749af3943dfcb6582ffcf48afb0b27e074 (patch)
treed0406ecb6d12955fec2a354ed27a23aab490692d /plugins/check_swap.c
parentf29785f5035e489576d2ba74be774273b73dd149 (diff)
parentea104fa400acfa017e9d7690dea19edef787421f (diff)
downloadmonitoring-plugins-562deb749af3943dfcb6582ffcf48afb0b27e074.tar.gz
Merge branch 'master' into check_curl_featuresrefs/pull/2006/head
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r--plugins/check_swap.c55
1 files changed, 26 insertions, 29 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 499a8d2..e7ee785 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,10 +546,7 @@ process_arguments (int argc, char **argv)
547int 546int
548validate_arguments (void) 547validate_arguments (void)
549{ 548{
550 if (warn.value == 0 && crit.value == 0) { 549 if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) {
551 return ERROR;
552 }
553 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 550 /* 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 551 * and crit is absolute. We cannot determine the condition at this point since we
556 * dont know the value of total swap yet 552 * dont know the value of total swap yet
@@ -595,6 +591,7 @@ print_help (void)
595 printf ("\n"); 591 printf ("\n");
596 printf ("%s\n", _("Notes:")); 592 printf ("%s\n", _("Notes:"));
597 printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); 593 printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked."));
594 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.")); 595 printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s."));
599 596
600 printf (UT_SUPPORT); 597 printf (UT_SUPPORT);
@@ -605,6 +602,6 @@ void
605print_usage (void) 602print_usage (void)
606{ 603{
607 printf ("%s\n", _("Usage:")); 604 printf ("%s\n", _("Usage:"));
608 printf (" %s [-av] -w <percent_free>%% -c <percent_free>%%\n",progname); 605 printf (" %s [-av] [-w <percent_free>%%] [-c <percent_free>%%]\n",progname);
609 printf (" -w <bytes_free> -c <bytes_free> [-n <state>]\n"); 606 printf (" [-w <bytes_free>] [-c <bytes_free>] [-n <state>]\n");
610} 607}