summaryrefslogtreecommitdiffstats
path: root/plugins/check_swap.c
diff options
context:
space:
mode:
authorLorenz <12514511+RincewindsHat@users.noreply.github.com>2023-01-09 16:55:10 +0100
committerGitHub <noreply@github.com>2023-01-09 16:55:10 +0100
commite0ada6f11a82ed6119836482b84c8ba5df491d8f (patch)
tree6ddcd5f7850169d82d88dca56a2e5c0dbda08b4e /plugins/check_swap.c
parentc389aa4f918aab5cf181aa2cb9dec68b3bf34d4f (diff)
parent0899e41f5075d661153eb2c77ace1734a8f66bfa (diff)
downloadmonitoring-plugins-e0ada6f.tar.gz
Merge branch 'master' into rename_output_to_cmd_output
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r--plugins/check_swap.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index bb854beb..a607da1e 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -1,30 +1,30 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring check_swap plugin 3* Monitoring check_swap 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 Monitoring Plugins Development Team 7* Copyright (c) 2000-2007 Monitoring Plugins Development Team
8* 8*
9* Description: 9* Description:
10* 10*
11* This file contains the check_swap plugin 11* This file contains the check_swap plugin
12* 12*
13* 13*
14* This program is free software: you can redistribute it and/or modify 14* This program is free software: you can redistribute it and/or modify
15* it under the terms of the GNU General Public License as published by 15* it under the terms of the GNU General Public License as published by
16* the Free Software Foundation, either version 3 of the License, or 16* the Free Software Foundation, either version 3 of the License, or
17* (at your option) any later version. 17* (at your option) any later version.
18* 18*
19* This program is distributed in the hope that it will be useful, 19* This program is distributed in the hope that it will be useful,
20* but WITHOUT ANY WARRANTY; without even the implied warranty of 20* but WITHOUT ANY WARRANTY; without even the implied warranty of
21* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22* GNU General Public License for more details. 22* GNU General Public License for more details.
23* 23*
24* You should have received a copy of the GNU General Public License 24* You should have received a copy of the GNU General Public License
25* along with this program. If not, see <http://www.gnu.org/licenses/>. 25* along with this program. If not, see <http://www.gnu.org/licenses/>.
26* 26*
27* 27*
28*****************************************************************************/ 28*****************************************************************************/
29 29
30const char *progname = "check_swap"; 30const char *progname = "check_swap";
@@ -150,7 +150,7 @@ main (int argc, char **argv)
150 * The following sscanf call looks for lines looking like: "SwapTotal: 123" and "SwapFree: 123" 150 * The following sscanf call looks for lines looking like: "SwapTotal: 123" and "SwapFree: 123"
151 * This format exists at least on Debian Linux with a 5.* kernel 151 * This format exists at least on Debian Linux with a 5.* kernel
152 */ 152 */
153 else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFreCchd]%*[:] %f %*[k]%*[B]", str, &tmp_KB)) { 153 else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFreCchd]%*[:] %lu %*[k]%*[B]", str, &tmp_KB)) {
154 if (verbose >= 3) { 154 if (verbose >= 3) {
155 printf("Got %s with %lu\n", str, tmp_KB); 155 printf("Got %s with %lu\n", str, tmp_KB);
156 } 156 }
@@ -389,7 +389,7 @@ main (int argc, char **argv)
389 TRUE, warn_print, 389 TRUE, warn_print,
390 TRUE, crit_print, 390 TRUE, crit_print,
391 TRUE, 0, 391 TRUE, 0,
392 TRUE, (long) total_swap_mb)); 392 TRUE, (long) total_swap_mb * 1024 * 1024));
393 393
394 return result; 394 return result;
395} 395}
@@ -410,7 +410,6 @@ check_swap(float free_swap_mb, float total_swap_mb)
410 uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; 410 uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100;
411 411
412 if (crit.is_percentage && 412 if (crit.is_percentage &&
413 usage_percentage >= 0 &&
414 crit.value != 0 && 413 crit.value != 0 &&
415 usage_percentage >= (100 - crit.value)) 414 usage_percentage >= (100 - crit.value))
416 { 415 {
@@ -418,7 +417,6 @@ check_swap(float free_swap_mb, float total_swap_mb)
418 } 417 }
419 418
420 if (warn.is_percentage && 419 if (warn.is_percentage &&
421 usage_percentage >= 0 &&
422 warn.value != 0 && 420 warn.value != 0 &&
423 usage_percentage >= (100 - warn.value)) 421 usage_percentage >= (100 - warn.value))
424 { 422 {
@@ -475,10 +473,9 @@ process_arguments (int argc, char **argv)
475 if (is_uint64(optarg, &warn.value)) { 473 if (is_uint64(optarg, &warn.value)) {
476 if (warn.value > 100) { 474 if (warn.value > 100) {
477 usage4 (_("Warning threshold percentage must be <= 100!")); 475 usage4 (_("Warning threshold percentage must be <= 100!"));
478 } else {
479 break;
480 } 476 }
481 } 477 }
478 break;
482 } else { 479 } else {
483 /* It's Bytes */ 480 /* It's Bytes */
484 warn.is_percentage = 0; 481 warn.is_percentage = 0;
@@ -506,10 +503,9 @@ process_arguments (int argc, char **argv)
506 if (is_uint64(optarg, &crit.value)) { 503 if (is_uint64(optarg, &crit.value)) {
507 if (crit.value> 100) { 504 if (crit.value> 100) {
508 usage4 (_("Critical threshold percentage must be <= 100!")); 505 usage4 (_("Critical threshold percentage must be <= 100!"));
509 } else {
510 break;
511 } 506 }
512 } 507 }
508 break;
513 } else { 509 } else {
514 /* It's Bytes */ 510 /* It's Bytes */
515 crit.is_percentage = 0; 511 crit.is_percentage = 0;
@@ -527,6 +523,7 @@ process_arguments (int argc, char **argv)
527 if ((no_swap_state = mp_translate_state(optarg)) == ERROR) { 523 if ((no_swap_state = mp_translate_state(optarg)) == ERROR) {
528 usage4 (_("no-swap result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); 524 usage4 (_("no-swap result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
529 } 525 }
526 break;
530 case 'v': /* verbose */ 527 case 'v': /* verbose */
531 verbose++; 528 verbose++;
532 break; 529 break;