diff options
-rw-r--r-- | plugins/check_procs.c | 106 |
1 files changed, 17 insertions, 89 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 2f2dcc5..23fdc27 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -45,15 +45,13 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
45 | 45 | ||
46 | int process_arguments (int, char **); | 46 | int process_arguments (int, char **); |
47 | int validate_arguments (void); | 47 | int validate_arguments (void); |
48 | int check_thresholds (int); | ||
49 | int convert_to_seconds (char *); | 48 | int convert_to_seconds (char *); |
50 | void print_help (void); | 49 | void print_help (void); |
51 | void print_usage (void); | 50 | void print_usage (void); |
52 | 51 | ||
53 | int wmax = -1; | 52 | char *warning_range = NULL; |
54 | int cmax = -1; | 53 | char *critical_range = NULL; |
55 | int wmin = -1; | 54 | thresholds *procs_thresholds = NULL; |
56 | int cmin = -1; | ||
57 | 55 | ||
58 | int options = 0; /* bitmask of filter criteria to test against */ | 56 | int options = 0; /* bitmask of filter criteria to test against */ |
59 | #define ALL 1 | 57 | #define ALL 1 |
@@ -238,14 +236,14 @@ main (int argc, char **argv) | |||
238 | } | 236 | } |
239 | 237 | ||
240 | if (metric == METRIC_VSZ) | 238 | if (metric == METRIC_VSZ) |
241 | i = check_thresholds (procvsz); | 239 | i = get_status ((double)procvsz, procs_thresholds); |
242 | else if (metric == METRIC_RSS) | 240 | else if (metric == METRIC_RSS) |
243 | i = check_thresholds (procrss); | 241 | i = get_status ((double)procrss, procs_thresholds); |
244 | /* TODO? float thresholds for --metric=CPU */ | 242 | /* TODO? float thresholds for --metric=CPU */ |
245 | else if (metric == METRIC_CPU) | 243 | else if (metric == METRIC_CPU) |
246 | i = check_thresholds ((int)procpcpu); | 244 | i = get_status (procpcpu, procs_thresholds); |
247 | else if (metric == METRIC_ELAPSED) | 245 | else if (metric == METRIC_ELAPSED) |
248 | i = check_thresholds (procseconds); | 246 | i = get_status ((double)procseconds, procs_thresholds); |
249 | 247 | ||
250 | if (metric != METRIC_PROCS) { | 248 | if (metric != METRIC_PROCS) { |
251 | if (i == STATE_WARNING) { | 249 | if (i == STATE_WARNING) { |
@@ -276,7 +274,7 @@ main (int argc, char **argv) | |||
276 | 274 | ||
277 | /* Needed if procs found, but none match filter */ | 275 | /* Needed if procs found, but none match filter */ |
278 | if ( metric == METRIC_PROCS ) { | 276 | if ( metric == METRIC_PROCS ) { |
279 | result = max_state (result, check_thresholds (procs) ); | 277 | result = max_state (result, get_status ((double)procs, procs_thresholds) ); |
280 | } | 278 | } |
281 | 279 | ||
282 | if ( result == STATE_OK ) { | 280 | if ( result == STATE_OK ) { |
@@ -368,28 +366,10 @@ process_arguments (int argc, char **argv) | |||
368 | timeout_interval = atoi (optarg); | 366 | timeout_interval = atoi (optarg); |
369 | break; | 367 | break; |
370 | case 'c': /* critical threshold */ | 368 | case 'c': /* critical threshold */ |
371 | if (is_integer (optarg)) | 369 | critical_range = optarg; |
372 | cmax = atoi (optarg); | ||
373 | else if (sscanf (optarg, ":%d", &cmax) == 1) | ||
374 | break; | ||
375 | else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2) | ||
376 | break; | ||
377 | else if (sscanf (optarg, "%d:", &cmin) == 1) | ||
378 | break; | ||
379 | else | ||
380 | usage4 (_("Critical Process Count must be an integer!")); | ||
381 | break; | 370 | break; |
382 | case 'w': /* warning threshold */ | 371 | case 'w': /* warning threshold */ |
383 | if (is_integer (optarg)) | 372 | warning_range = optarg; |
384 | wmax = atoi (optarg); | ||
385 | else if (sscanf (optarg, ":%d", &wmax) == 1) | ||
386 | break; | ||
387 | else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2) | ||
388 | break; | ||
389 | else if (sscanf (optarg, "%d:", &wmin) == 1) | ||
390 | break; | ||
391 | else | ||
392 | usage4 (_("Warning Process Count must be an integer!")); | ||
393 | break; | 373 | break; |
394 | case 'p': /* process id */ | 374 | case 'p': /* process id */ |
395 | if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) { | 375 | if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) { |
@@ -518,16 +498,19 @@ process_arguments (int argc, char **argv) | |||
518 | } | 498 | } |
519 | 499 | ||
520 | c = optind; | 500 | c = optind; |
521 | if (wmax == -1 && argv[c]) | 501 | if ((! warning_range) && argv[c]) |
522 | wmax = atoi (argv[c++]); | 502 | warning_range = argv[c++]; |
523 | if (cmax == -1 && argv[c]) | 503 | if ((! critical_range) && argv[c]) |
524 | cmax = atoi (argv[c++]); | 504 | critical_range = argv[c++]; |
525 | if (statopts == NULL && argv[c]) { | 505 | if (statopts == NULL && argv[c]) { |
526 | xasprintf (&statopts, "%s", argv[c++]); | 506 | xasprintf (&statopts, "%s", argv[c++]); |
527 | xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); | 507 | xasprintf (&fmt, _("%s%sSTATE = %s"), (fmt ? fmt : ""), (options ? ", " : ""), statopts); |
528 | options |= STAT; | 508 | options |= STAT; |
529 | } | 509 | } |
530 | 510 | ||
511 | /* this will abort in case of invalid ranges */ | ||
512 | set_thresholds (&procs_thresholds, warning_range, critical_range); | ||
513 | |||
531 | return validate_arguments (); | 514 | return validate_arguments (); |
532 | } | 515 | } |
533 | 516 | ||
@@ -536,27 +519,6 @@ process_arguments (int argc, char **argv) | |||
536 | int | 519 | int |
537 | validate_arguments () | 520 | validate_arguments () |
538 | { | 521 | { |
539 | |||
540 | if (wmax >= 0 && wmin == -1) | ||
541 | wmin = 0; | ||
542 | if (cmax >= 0 && cmin == -1) | ||
543 | cmin = 0; | ||
544 | if (wmax >= wmin && cmax >= cmin) { /* standard ranges */ | ||
545 | if (wmax > cmax && cmax != -1) { | ||
546 | printf (_("wmax (%d) cannot be greater than cmax (%d)\n"), wmax, cmax); | ||
547 | return ERROR; | ||
548 | } | ||
549 | if (cmin > wmin && wmin != -1) { | ||
550 | printf (_("wmin (%d) cannot be less than cmin (%d)\n"), wmin, cmin); | ||
551 | return ERROR; | ||
552 | } | ||
553 | } | ||
554 | |||
555 | /* if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) { */ | ||
556 | /* printf ("At least one threshold must be set\n"); */ | ||
557 | /* return ERROR; */ | ||
558 | /* } */ | ||
559 | |||
560 | if (options == 0) | 522 | if (options == 0) |
561 | options = ALL; | 523 | options = ALL; |
562 | 524 | ||
@@ -579,40 +541,6 @@ validate_arguments () | |||
579 | } | 541 | } |
580 | 542 | ||
581 | 543 | ||
582 | |||
583 | /* Check thresholds against value */ | ||
584 | int | ||
585 | check_thresholds (int value) | ||
586 | { | ||
587 | if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) { | ||
588 | return OK; | ||
589 | } | ||
590 | else if (cmax >= 0 && cmin >= 0 && cmax < cmin) { | ||
591 | if (value > cmax && value < cmin) | ||
592 | return STATE_CRITICAL; | ||
593 | } | ||
594 | else if (cmax >= 0 && value > cmax) { | ||
595 | return STATE_CRITICAL; | ||
596 | } | ||
597 | else if (cmin >= 0 && value < cmin) { | ||
598 | return STATE_CRITICAL; | ||
599 | } | ||
600 | |||
601 | if (wmax >= 0 && wmin >= 0 && wmax < wmin) { | ||
602 | if (value > wmax && value < wmin) { | ||
603 | return STATE_WARNING; | ||
604 | } | ||
605 | } | ||
606 | else if (wmax >= 0 && value > wmax) { | ||
607 | return STATE_WARNING; | ||
608 | } | ||
609 | else if (wmin >= 0 && value < wmin) { | ||
610 | return STATE_WARNING; | ||
611 | } | ||
612 | return STATE_OK; | ||
613 | } | ||
614 | |||
615 | |||
616 | /* convert the elapsed time to seconds */ | 544 | /* convert the elapsed time to seconds */ |
617 | int | 545 | int |
618 | convert_to_seconds(char *etime) { | 546 | convert_to_seconds(char *etime) { |