summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Odenbach <odenbach@uni-paderborn.de>2017-05-31 12:15:47 (GMT)
committerChristopher Odenbach <odenbach@uni-paderborn.de>2017-05-31 12:15:47 (GMT)
commit6995b510759cf531d70745b7d0c6e8a0d9010b06 (patch)
treeab98653fa5f387d2323b189ada738d781f8085a7
parentb3d39e605ef7ce7da056721c4e2e140966be3530 (diff)
downloadmonitoring-plugins-6995b510759cf531d70745b7d0c6e8a0d9010b06.tar.gz
repaired "-n" behaviour. If run with "-n ok" a host which ranrefs/pull/1491/head
completely out of swap space would return "ok" which is not desired. It should only return "ok" if there is no swap space configured at all.
-rw-r--r--plugins/check_swap.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 4d5a407..0ff0c77 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -51,7 +51,7 @@ const char *email = "devel@monitoring-plugins.org";
51# define SWAP_CONVERSION 1 51# define SWAP_CONVERSION 1
52#endif 52#endif
53 53
54int check_swap (int usp, float free_swap_mb); 54int check_swap (int usp, float free_swap_mb, float total_swap_mb);
55int process_arguments (int argc, char **argv); 55int process_arguments (int argc, char **argv);
56int validate_arguments (void); 56int validate_arguments (void);
57void print_usage (void); 57void print_usage (void);
@@ -128,7 +128,7 @@ main (int argc, char **argv)
128 percent=100.0; 128 percent=100.0;
129 else 129 else
130 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 130 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
131 result = max_state (result, check_swap (percent, dskfree_mb)); 131 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
132 if (verbose) 132 if (verbose)
133 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 133 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
134 } 134 }
@@ -227,7 +227,7 @@ main (int argc, char **argv)
227 free_swap_mb += dskfree_mb; 227 free_swap_mb += dskfree_mb;
228 if (allswaps) { 228 if (allswaps) {
229 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 229 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
230 result = max_state (result, check_swap (percent, dskfree_mb)); 230 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
231 if (verbose) 231 if (verbose)
232 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 232 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
233 } 233 }
@@ -289,7 +289,7 @@ main (int argc, char **argv)
289 289
290 if(allswaps && dsktotal_mb > 0){ 290 if(allswaps && dsktotal_mb > 0){
291 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 291 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
292 result = max_state (result, check_swap (percent, dskfree_mb)); 292 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
293 if (verbose) { 293 if (verbose) {
294 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 294 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
295 } 295 }
@@ -328,7 +328,7 @@ main (int argc, char **argv)
328 328
329 if(allswaps && dsktotal_mb > 0){ 329 if(allswaps && dsktotal_mb > 0){
330 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb)); 330 percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
331 result = max_state (result, check_swap (percent, dskfree_mb)); 331 result = max_state (result, check_swap (percent, dskfree_mb, dsktotal_mb));
332 if (verbose) { 332 if (verbose) {
333 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent); 333 xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
334 } 334 }
@@ -355,7 +355,7 @@ main (int argc, char **argv)
355 status = "- Swap is either disabled, not present, or of zero size. "; 355 status = "- Swap is either disabled, not present, or of zero size. ";
356 } 356 }
357 357
358 result = max_state (result, check_swap (percent_used, free_swap_mb)); 358 result = max_state (result, check_swap (percent_used, free_swap_mb, total_swap_mb));
359 printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"), 359 printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"),
360 state_text (result), 360 state_text (result),
361 (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status); 361 (100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status);
@@ -372,10 +372,10 @@ main (int argc, char **argv)
372 372
373 373
374int 374int
375check_swap (int usp, float free_swap_mb) 375check_swap (int usp, float free_swap_mb, float total_swap_mb)
376{ 376{
377 377
378 if (!free_swap_mb) return no_swap_state; 378 if (!total_swap_mb) return no_swap_state;
379 379
380 int result = STATE_UNKNOWN; 380 int result = STATE_UNKNOWN;
381 float 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 */