diff options
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r-- | plugins/check_swap.c | 306 |
1 files changed, 171 insertions, 135 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 4d5a4071..cd965e31 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 | ||
30 | const char *progname = "check_swap"; | 30 | const char *progname = "check_swap"; |
@@ -51,16 +51,19 @@ const char *email = "devel@monitoring-plugins.org"; | |||
51 | # define SWAP_CONVERSION 1 | 51 | # define SWAP_CONVERSION 1 |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | int check_swap (int usp, float free_swap_mb); | 54 | typedef struct { |
55 | int is_percentage; | ||
56 | uint64_t value; | ||
57 | } threshold_t; | ||
58 | |||
59 | int check_swap (float free_swap_mb, float total_swap_mb); | ||
55 | int process_arguments (int argc, char **argv); | 60 | int process_arguments (int argc, char **argv); |
56 | int validate_arguments (void); | 61 | int validate_arguments (void); |
57 | void print_usage (void); | 62 | void print_usage (void); |
58 | void print_help (void); | 63 | void print_help (void); |
59 | 64 | ||
60 | int warn_percent = 0; | 65 | threshold_t warn; |
61 | int crit_percent = 0; | 66 | threshold_t crit; |
62 | float warn_size_bytes = 0; | ||
63 | float crit_size_bytes = 0; | ||
64 | int verbose; | 67 | int verbose; |
65 | int allswaps; | 68 | int allswaps; |
66 | int no_swap_state = STATE_CRITICAL; | 69 | int no_swap_state = STATE_CRITICAL; |
@@ -68,9 +71,10 @@ int no_swap_state = STATE_CRITICAL; | |||
68 | int | 71 | int |
69 | main (int argc, char **argv) | 72 | main (int argc, char **argv) |
70 | { | 73 | { |
71 | int percent_used, percent; | 74 | unsigned int percent_used, percent; |
72 | float total_swap_mb = 0, used_swap_mb = 0, free_swap_mb = 0; | 75 | uint64_t total_swap_mb = 0, used_swap_mb = 0, free_swap_mb = 0; |
73 | float dsktotal_mb = 0, dskused_mb = 0, dskfree_mb = 0, tmp_mb = 0; | 76 | uint64_t dsktotal_mb = 0, dskused_mb = 0, dskfree_mb = 0; |
77 | uint64_t tmp_KB = 0; | ||
74 | int result = STATE_UNKNOWN; | 78 | int result = STATE_UNKNOWN; |
75 | char input_buffer[MAX_INPUT_BUFFER]; | 79 | char input_buffer[MAX_INPUT_BUFFER]; |
76 | #ifdef HAVE_PROC_MEMINFO | 80 | #ifdef HAVE_PROC_MEMINFO |
@@ -116,10 +120,15 @@ main (int argc, char **argv) | |||
116 | } | 120 | } |
117 | fp = fopen (PROC_MEMINFO, "r"); | 121 | fp = fopen (PROC_MEMINFO, "r"); |
118 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { | 122 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) { |
119 | if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %f %f %f", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) { | 123 | /* |
120 | dsktotal_mb = dsktotal_mb / 1048576; /* Apply conversion */ | 124 | * The following sscanf call looks for a line looking like: "Swap: 123 123 123" |
121 | dskused_mb = dskused_mb / 1048576; | 125 | * On which kind of system this format exists, I can not say, but I wanted to |
122 | dskfree_mb = dskfree_mb / 1048576; | 126 | * document this for people who are not adapt with sscanf anymore, like me |
127 | */ | ||
128 | if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %lu %lu %lu", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) { | ||
129 | dsktotal_mb = dsktotal_mb / (1024 * 1024); /* Apply conversion */ | ||
130 | dskused_mb = dskused_mb / (1024 * 1024); | ||
131 | dskfree_mb = dskfree_mb / (1024 * 1024); | ||
123 | total_swap_mb += dsktotal_mb; | 132 | total_swap_mb += dsktotal_mb; |
124 | used_swap_mb += dskused_mb; | 133 | used_swap_mb += dskused_mb; |
125 | free_swap_mb += dskfree_mb; | 134 | free_swap_mb += dskfree_mb; |
@@ -128,21 +137,29 @@ main (int argc, char **argv) | |||
128 | percent=100.0; | 137 | percent=100.0; |
129 | else | 138 | else |
130 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 139 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
131 | result = max_state (result, check_swap (percent, dskfree_mb)); | 140 | result = max_state (result, check_swap (dskfree_mb, dsktotal_mb)); |
132 | if (verbose) | 141 | if (verbose) |
133 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 142 | xasprintf (&status, "%s [%lu (%d%%)]", status, dskfree_mb, 100 - percent); |
134 | } | 143 | } |
135 | } | 144 | } |
136 | else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %f %*[k]%*[B]", str, &tmp_mb)) { | 145 | |
146 | /* | ||
147 | * The following sscanf call looks for lines looking like: "SwapTotal: 123" and "SwapFree: 123" | ||
148 | * This format exists at least on Debian Linux with a 5.* kernel | ||
149 | */ | ||
150 | else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFreCchd]%*[:] %lu %*[k]%*[B]", str, &tmp_KB)) { | ||
137 | if (verbose >= 3) { | 151 | if (verbose >= 3) { |
138 | printf("Got %s with %f\n", str, tmp_mb); | 152 | printf("Got %s with %lu\n", str, tmp_KB); |
139 | } | 153 | } |
140 | /* I think this part is always in Kb, so convert to mb */ | 154 | /* I think this part is always in Kb, so convert to mb */ |
141 | if (strcmp ("Total", str) == 0) { | 155 | if (strcmp ("Total", str) == 0) { |
142 | dsktotal_mb = tmp_mb / 1024; | 156 | dsktotal_mb = tmp_KB / 1024; |
143 | } | 157 | } |
144 | else if (strcmp ("Free", str) == 0) { | 158 | else if (strcmp ("Free", str) == 0) { |
145 | dskfree_mb = tmp_mb / 1024; | 159 | dskfree_mb = dskfree_mb + tmp_KB / 1024; |
160 | } | ||
161 | else if (strcmp ("Cached", str) == 0) { | ||
162 | dskfree_mb = dskfree_mb + tmp_KB / 1024; | ||
146 | } | 163 | } |
147 | } | 164 | } |
148 | } | 165 | } |
@@ -161,7 +178,7 @@ main (int argc, char **argv) | |||
161 | # ifdef _AIX | 178 | # ifdef _AIX |
162 | if (!allswaps) { | 179 | if (!allswaps) { |
163 | xasprintf(&swap_command, "%s", "/usr/sbin/lsps -s"); | 180 | xasprintf(&swap_command, "%s", "/usr/sbin/lsps -s"); |
164 | xasprintf(&swap_format, "%s", "%f%*s %f"); | 181 | xasprintf(&swap_format, "%s", "%lu%*s %lu"); |
165 | conv_factor = 1; | 182 | conv_factor = 1; |
166 | } | 183 | } |
167 | # endif | 184 | # endif |
@@ -188,9 +205,9 @@ main (int argc, char **argv) | |||
188 | temp_buffer = strtok (input_buffer, " \n"); | 205 | temp_buffer = strtok (input_buffer, " \n"); |
189 | while (temp_buffer) { | 206 | while (temp_buffer) { |
190 | if (strstr (temp_buffer, "blocks")) | 207 | if (strstr (temp_buffer, "blocks")) |
191 | sprintf (str, "%s %s", str, "%f"); | 208 | sprintf (str, "%s %s", str, "%lu"); |
192 | else if (strstr (temp_buffer, "dskfree")) | 209 | else if (strstr (temp_buffer, "dskfree")) |
193 | sprintf (str, "%s %s", str, "%f"); | 210 | sprintf (str, "%s %s", str, "%lu"); |
194 | else | 211 | else |
195 | sprintf (str, "%s %s", str, "%*s"); | 212 | sprintf (str, "%s %s", str, "%*s"); |
196 | temp_buffer = strtok (NULL, " \n"); | 213 | temp_buffer = strtok (NULL, " \n"); |
@@ -227,7 +244,7 @@ main (int argc, char **argv) | |||
227 | free_swap_mb += dskfree_mb; | 244 | free_swap_mb += dskfree_mb; |
228 | if (allswaps) { | 245 | if (allswaps) { |
229 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 246 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
230 | result = max_state (result, check_swap (percent, dskfree_mb)); | 247 | result = max_state (result, check_swap (dskfree_mb, dsktotal_mb)); |
231 | if (verbose) | 248 | if (verbose) |
232 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 249 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); |
233 | } | 250 | } |
@@ -289,7 +306,7 @@ main (int argc, char **argv) | |||
289 | 306 | ||
290 | if(allswaps && dsktotal_mb > 0){ | 307 | if(allswaps && dsktotal_mb > 0){ |
291 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 308 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
292 | result = max_state (result, check_swap (percent, dskfree_mb)); | 309 | result = max_state (result, check_swap (dskfree_mb, dsktotal_mb)); |
293 | if (verbose) { | 310 | if (verbose) { |
294 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 311 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); |
295 | } | 312 | } |
@@ -328,7 +345,7 @@ main (int argc, char **argv) | |||
328 | 345 | ||
329 | if(allswaps && dsktotal_mb > 0){ | 346 | if(allswaps && dsktotal_mb > 0){ |
330 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); | 347 | percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); |
331 | result = max_state (result, check_swap (percent, dskfree_mb)); | 348 | result = max_state (result, check_swap(dskfree_mb, dsktotal_mb)); |
332 | if (verbose) { | 349 | if (verbose) { |
333 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); | 350 | xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); |
334 | } | 351 | } |
@@ -355,41 +372,55 @@ main (int argc, char **argv) | |||
355 | status = "- Swap is either disabled, not present, or of zero size. "; | 372 | status = "- Swap is either disabled, not present, or of zero size. "; |
356 | } | 373 | } |
357 | 374 | ||
358 | result = max_state (result, check_swap (percent_used, free_swap_mb)); | 375 | result = max_state (result, check_swap(free_swap_mb, total_swap_mb)); |
359 | printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"), | 376 | printf (_("SWAP %s - %d%% free (%dMB out of %dMB) %s|"), |
360 | state_text (result), | 377 | state_text (result), |
361 | (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status); | 378 | (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status); |
362 | 379 | ||
363 | puts (perfdata ("swap", (long) free_swap_mb, "MB", | 380 | uint64_t warn_print = warn.value; |
364 | TRUE, (long) max (warn_size_bytes/(1024 * 1024), warn_percent/100.0*total_swap_mb), | 381 | if (warn.is_percentage) warn_print = warn.value * (total_swap_mb *1024 *1024/100); |
365 | TRUE, (long) max (crit_size_bytes/(1024 * 1024), crit_percent/100.0*total_swap_mb), | 382 | uint64_t crit_print = crit.value; |
383 | if (crit.is_percentage) crit_print = crit.value * (total_swap_mb *1024 *1024/100); | ||
384 | |||
385 | puts (perfdata_uint64 ("swap", free_swap_mb *1024 *1024, "B", | ||
386 | TRUE, warn_print, | ||
387 | TRUE, crit_print, | ||
366 | TRUE, 0, | 388 | TRUE, 0, |
367 | TRUE, (long) total_swap_mb)); | 389 | TRUE, (long) total_swap_mb * 1024 * 1024)); |
368 | 390 | ||
369 | return result; | 391 | return result; |
370 | } | 392 | } |
371 | 393 | ||
372 | 394 | ||
373 | |||
374 | int | 395 | int |
375 | check_swap (int usp, float free_swap_mb) | 396 | check_swap(float free_swap_mb, float total_swap_mb) |
376 | { | 397 | { |
377 | 398 | ||
378 | if (!free_swap_mb) return no_swap_state; | 399 | if (!total_swap_mb) return no_swap_state; |
379 | 400 | ||
380 | int result = STATE_UNKNOWN; | 401 | uint64_t free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ |
381 | float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ | 402 | |
382 | if (usp >= 0 && crit_percent != 0 && usp >= (100.0 - crit_percent)) | 403 | if (!crit.is_percentage && crit.value >= free_swap) return STATE_CRITICAL; |
383 | result = STATE_CRITICAL; | 404 | if (!warn.is_percentage && warn.value >= free_swap) return STATE_WARNING; |
384 | else if (crit_size_bytes > 0 && free_swap <= crit_size_bytes) | 405 | |
385 | result = STATE_CRITICAL; | 406 | |
386 | else if (usp >= 0 && warn_percent != 0 && usp >= (100.0 - warn_percent)) | 407 | uint64_t usage_percentage = ((total_swap_mb - free_swap_mb) / total_swap_mb) * 100; |
387 | result = STATE_WARNING; | 408 | |
388 | else if (warn_size_bytes > 0 && free_swap <= warn_size_bytes) | 409 | if (crit.is_percentage && |
389 | result = STATE_WARNING; | 410 | crit.value != 0 && |
390 | else if (usp >= 0.0) | 411 | usage_percentage >= (100 - crit.value)) |
391 | result = STATE_OK; | 412 | { |
392 | return result; | 413 | return STATE_CRITICAL; |
414 | } | ||
415 | |||
416 | if (warn.is_percentage && | ||
417 | warn.value != 0 && | ||
418 | usage_percentage >= (100 - warn.value)) | ||
419 | { | ||
420 | return STATE_WARNING; | ||
421 | } | ||
422 | |||
423 | return STATE_OK; | ||
393 | } | 424 | } |
394 | 425 | ||
395 | 426 | ||
@@ -422,42 +453,66 @@ process_arguments (int argc, char **argv) | |||
422 | break; | 453 | break; |
423 | 454 | ||
424 | switch (c) { | 455 | switch (c) { |
425 | case 'w': /* warning size threshold */ | 456 | case 'w': /* warning size threshold */ |
426 | if (is_intnonneg (optarg)) { | 457 | { |
427 | warn_size_bytes = (float) atoi (optarg); | 458 | /* |
428 | break; | 459 | * We expect either a positive integer value without a unit, which means |
429 | } | 460 | * the unit is Bytes or a positive integer value and a percentage sign (%), |
430 | else if (strstr (optarg, ",") && | 461 | * which means the value must be with 0 and 100 and is relative to the total swap |
431 | strstr (optarg, "%") && | 462 | */ |
432 | sscanf (optarg, "%f,%d%%", &warn_size_bytes, &warn_percent) == 2) { | 463 | size_t length; |
433 | warn_size_bytes = floorf(warn_size_bytes); | 464 | length = strlen(optarg); |
434 | break; | 465 | |
435 | } | 466 | if (optarg[length - 1] == '%') { |
436 | else if (strstr (optarg, "%") && | 467 | /* It's percentage */ |
437 | sscanf (optarg, "%d%%", &warn_percent) == 1) { | 468 | warn.is_percentage = 1; |
438 | break; | 469 | optarg[length - 1] = '\0'; |
439 | } | 470 | if (is_uint64(optarg, &warn.value)) { |
440 | else { | 471 | if (warn.value > 100) { |
441 | usage4 (_("Warning threshold must be integer or percentage!")); | 472 | usage4 (_("Warning threshold percentage must be <= 100!")); |
442 | } | 473 | } |
443 | case 'c': /* critical size threshold */ | 474 | } |
444 | if (is_intnonneg (optarg)) { | 475 | break; |
445 | crit_size_bytes = (float) atoi (optarg); | 476 | } else { |
446 | break; | 477 | /* It's Bytes */ |
447 | } | 478 | warn.is_percentage = 0; |
448 | else if (strstr (optarg, ",") && | 479 | if (is_uint64(optarg, &warn.value)) { |
449 | strstr (optarg, "%") && | 480 | break; |
450 | sscanf (optarg, "%f,%d%%", &crit_size_bytes, &crit_percent) == 2) { | 481 | } else { |
451 | crit_size_bytes = floorf(crit_size_bytes); | 482 | usage4 (_("Warning threshold be positive integer or percentage!")); |
452 | break; | 483 | } |
453 | } | 484 | } |
454 | else if (strstr (optarg, "%") && | ||
455 | sscanf (optarg, "%d%%", &crit_percent) == 1) { | ||
456 | break; | ||
457 | } | ||
458 | else { | ||
459 | usage4 (_("Critical threshold must be integer or percentage!")); | ||
460 | } | 485 | } |
486 | case 'c': /* critical size threshold */ | ||
487 | { | ||
488 | /* | ||
489 | * We expect either a positive integer value without a unit, which means | ||
490 | * the unit is Bytes or a positive integer value and a percentage sign (%), | ||
491 | * which means the value must be with 0 and 100 and is relative to the total swap | ||
492 | */ | ||
493 | size_t length; | ||
494 | length = strlen(optarg); | ||
495 | |||
496 | if (optarg[length - 1] == '%') { | ||
497 | /* It's percentage */ | ||
498 | crit.is_percentage = 1; | ||
499 | optarg[length - 1] = '\0'; | ||
500 | if (is_uint64(optarg, &crit.value)) { | ||
501 | if (crit.value> 100) { | ||
502 | usage4 (_("Critical threshold percentage must be <= 100!")); | ||
503 | } | ||
504 | } | ||
505 | break; | ||
506 | } else { | ||
507 | /* It's Bytes */ | ||
508 | crit.is_percentage = 0; | ||
509 | if (is_uint64(optarg, &crit.value)) { | ||
510 | break; | ||
511 | } else { | ||
512 | usage4 (_("Critical threshold be positive integer or percentage!")); | ||
513 | } | ||
514 | } | ||
515 | } | ||
461 | case 'a': /* all swap */ | 516 | case 'a': /* all swap */ |
462 | allswaps = TRUE; | 517 | allswaps = TRUE; |
463 | break; | 518 | break; |
@@ -465,6 +520,7 @@ process_arguments (int argc, char **argv) | |||
465 | if ((no_swap_state = mp_translate_state(optarg)) == ERROR) { | 520 | if ((no_swap_state = mp_translate_state(optarg)) == ERROR) { |
466 | usage4 (_("no-swap result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | 521 | usage4 (_("no-swap result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); |
467 | } | 522 | } |
523 | break; | ||
468 | case 'v': /* verbose */ | 524 | case 'v': /* verbose */ |
469 | verbose++; | 525 | verbose++; |
470 | break; | 526 | break; |
@@ -482,23 +538,6 @@ process_arguments (int argc, char **argv) | |||
482 | c = optind; | 538 | c = optind; |
483 | if (c == argc) | 539 | if (c == argc) |
484 | return validate_arguments (); | 540 | return validate_arguments (); |
485 | if (warn_percent == 0 && is_intnonneg (argv[c])) | ||
486 | warn_percent = atoi (argv[c++]); | ||
487 | |||
488 | if (c == argc) | ||
489 | return validate_arguments (); | ||
490 | if (crit_percent == 0 && is_intnonneg (argv[c])) | ||
491 | crit_percent = atoi (argv[c++]); | ||
492 | |||
493 | if (c == argc) | ||
494 | return validate_arguments (); | ||
495 | if (warn_size_bytes == 0 && is_intnonneg (argv[c])) | ||
496 | warn_size_bytes = (float) atoi (argv[c++]); | ||
497 | |||
498 | if (c == argc) | ||
499 | return validate_arguments (); | ||
500 | if (crit_size_bytes == 0 && is_intnonneg (argv[c])) | ||
501 | crit_size_bytes = (float) atoi (argv[c++]); | ||
502 | 541 | ||
503 | return validate_arguments (); | 542 | return validate_arguments (); |
504 | } | 543 | } |
@@ -508,17 +547,15 @@ process_arguments (int argc, char **argv) | |||
508 | int | 547 | int |
509 | validate_arguments (void) | 548 | validate_arguments (void) |
510 | { | 549 | { |
511 | if (warn_percent == 0 && crit_percent == 0 && warn_size_bytes == 0 | 550 | if (warn.value == 0 && crit.value == 0) { |
512 | && crit_size_bytes == 0) { | ||
513 | return ERROR; | 551 | return ERROR; |
514 | } | 552 | } |
515 | else if (warn_percent < crit_percent) { | 553 | else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) { |
516 | usage4 | 554 | /* This is NOT triggered if warn and crit are different units, e.g warn is percentage |
517 | (_("Warning percentage should be more than critical percentage")); | 555 | * and crit is absolute. We cannot determine the condition at this point since we |
518 | } | 556 | * dont know the value of total swap yet |
519 | else if (warn_size_bytes < crit_size_bytes) { | 557 | */ |
520 | usage4 | 558 | usage4(_("Warning should be more than critical")); |
521 | (_("Warning free space should be more than critical free space")); | ||
522 | } | 559 | } |
523 | return OK; | 560 | return OK; |
524 | } | 561 | } |
@@ -534,7 +571,7 @@ print_help (void) | |||
534 | 571 | ||
535 | printf ("%s\n", _("Check swap space on local machine.")); | 572 | printf ("%s\n", _("Check swap space on local machine.")); |
536 | 573 | ||
537 | printf ("\n\n"); | 574 | printf ("\n\n"); |
538 | 575 | ||
539 | print_usage (); | 576 | print_usage (); |
540 | 577 | ||
@@ -542,33 +579,32 @@ print_help (void) | |||
542 | printf (UT_EXTRA_OPTS); | 579 | printf (UT_EXTRA_OPTS); |
543 | 580 | ||
544 | printf (" %s\n", "-w, --warning=INTEGER"); | 581 | printf (" %s\n", "-w, --warning=INTEGER"); |
545 | printf (" %s\n", _("Exit with WARNING status if less than INTEGER bytes of swap space are free")); | 582 | printf (" %s\n", _("Exit with WARNING status if less than INTEGER bytes of swap space are free")); |
546 | printf (" %s\n", "-w, --warning=PERCENT%%"); | 583 | printf (" %s\n", "-w, --warning=PERCENT%"); |
547 | printf (" %s\n", _("Exit with WARNING status if less than PERCENT of swap space is free")); | 584 | printf (" %s\n", _("Exit with WARNING status if less than PERCENT of swap space is free")); |
548 | printf (" %s\n", "-c, --critical=INTEGER"); | 585 | printf (" %s\n", "-c, --critical=INTEGER"); |
549 | printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER bytes of swap space are free")); | 586 | printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER bytes of swap space are free")); |
550 | printf (" %s\n", "-c, --critical=PERCENT%%"); | 587 | printf (" %s\n", "-c, --critical=PERCENT%"); |
551 | printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of swap space is free")); | 588 | printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of swap space is free")); |
552 | printf (" %s\n", "-a, --allswaps"); | 589 | printf (" %s\n", "-a, --allswaps"); |
553 | printf (" %s\n", _("Conduct comparisons for all swap partitions, one by one")); | 590 | printf (" %s\n", _("Conduct comparisons for all swap partitions, one by one")); |
554 | printf (" %s\n", "-n, --no-swap=<ok|warning|critical|unknown>"); | 591 | printf (" %s\n", "-n, --no-swap=<ok|warning|critical|unknown>"); |
555 | printf (" %s %s\n", _("Resulting state when there is no swap regardless of thresholds. Default:"), state_text(no_swap_state)); | 592 | printf (" %s %s\n", _("Resulting state when there is no swap regardless of thresholds. Default:"), state_text(no_swap_state)); |
556 | printf (UT_VERBOSE); | 593 | printf (UT_VERBOSE); |
557 | 594 | ||
558 | printf ("\n"); | 595 | printf ("\n"); |
559 | printf ("%s\n", _("Notes:")); | 596 | printf ("%s\n", _("Notes:")); |
560 | printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); | 597 | printf (" %s\n", _("Both INTEGER and PERCENT thresholds can be specified, they are all checked.")); |
561 | printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); | 598 | printf (" %s\n", _("On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.")); |
562 | 599 | ||
563 | printf (UT_SUPPORT); | 600 | printf (UT_SUPPORT); |
564 | } | 601 | } |
565 | 602 | ||
566 | 603 | ||
567 | |||
568 | void | 604 | void |
569 | print_usage (void) | 605 | print_usage (void) |
570 | { | 606 | { |
571 | printf ("%s\n", _("Usage:")); | 607 | printf ("%s\n", _("Usage:")); |
572 | printf (" %s [-av] -w <percent_free>%% -c <percent_free>%%\n",progname); | 608 | printf (" %s [-av] -w <percent_free>%% -c <percent_free>%%\n",progname); |
573 | printf (" -w <bytes_free> -c <bytes_free> [-n <state>]\n"); | 609 | printf (" -w <bytes_free> -c <bytes_free> [-n <state>]\n"); |
574 | } | 610 | } |