diff options
-rw-r--r-- | plugins/check_procs.c | 79 |
1 files changed, 66 insertions, 13 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 7f3ca21d..bebde983 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -108,6 +108,7 @@ thresholds *number_threshold = NULL; | |||
108 | thresholds *vsz_threshold = NULL; | 108 | thresholds *vsz_threshold = NULL; |
109 | thresholds *rss_threshold = NULL; | 109 | thresholds *rss_threshold = NULL; |
110 | thresholds *cpu_threshold = NULL; | 110 | thresholds *cpu_threshold = NULL; |
111 | int new_style_thresholds = 0; | ||
111 | 112 | ||
112 | int warn = 0; /* number of processes in warn state */ | 113 | int warn = 0; /* number of processes in warn state */ |
113 | int crit = 0; /* number of processes in crit state */ | 114 | int crit = 0; /* number of processes in crit state */ |
@@ -119,6 +120,9 @@ main (int argc, char **argv) | |||
119 | char *input_buffer; | 120 | char *input_buffer; |
120 | char *input_line; | 121 | char *input_line; |
121 | char *procprog; | 122 | char *procprog; |
123 | char *last_critical = NULL; | ||
124 | char *last_warning = NULL; | ||
125 | char *last_failed_process = NULL; | ||
122 | 126 | ||
123 | pid_t mypid = 0; | 127 | pid_t mypid = 0; |
124 | int procuid = 0; | 128 | int procuid = 0; |
@@ -147,6 +151,8 @@ main (int argc, char **argv) | |||
147 | double vsz_max = 0; | 151 | double vsz_max = 0; |
148 | double rss_max = 0; | 152 | double rss_max = 0; |
149 | double cpu_max = 0; | 153 | double cpu_max = 0; |
154 | int multiple_process_output_flag = 0; | ||
155 | int number_threshold_failure_flag = 0; | ||
150 | 156 | ||
151 | 157 | ||
152 | setlocale (LC_ALL, ""); | 158 | setlocale (LC_ALL, ""); |
@@ -158,6 +164,7 @@ main (int argc, char **argv) | |||
158 | procprog = malloc (MAX_INPUT_BUFFER); | 164 | procprog = malloc (MAX_INPUT_BUFFER); |
159 | 165 | ||
160 | asprintf (&metric_name, "PROCS"); | 166 | asprintf (&metric_name, "PROCS"); |
167 | asprintf (&last_failed_process, ""); | ||
161 | 168 | ||
162 | if (process_arguments (argc, argv) == ERROR) | 169 | if (process_arguments (argc, argv) == ERROR) |
163 | usage4 (_("Could not parse arguments")); | 170 | usage4 (_("Could not parse arguments")); |
@@ -171,7 +178,7 @@ main (int argc, char **argv) | |||
171 | } | 178 | } |
172 | alarm (timeout_interval); | 179 | alarm (timeout_interval); |
173 | 180 | ||
174 | if (verbose >= 2) | 181 | if (verbose >= 3) |
175 | printf (_("CMD: %s\n"), PS_COMMAND); | 182 | printf (_("CMD: %s\n"), PS_COMMAND); |
176 | 183 | ||
177 | if (input_filename == NULL) { | 184 | if (input_filename == NULL) { |
@@ -280,10 +287,18 @@ main (int argc, char **argv) | |||
280 | actions_on_failed_state( check_thresholds (procseconds), procprog ); | 287 | actions_on_failed_state( check_thresholds (procseconds), procprog ); |
281 | } | 288 | } |
282 | 289 | ||
290 | asprintf( &last_critical, "" ); | ||
291 | asprintf( &last_warning, "" ); | ||
283 | /* Check against all new style thresholds */ | 292 | /* Check against all new style thresholds */ |
284 | if (vsz_threshold != NULL) { | 293 | if (vsz_threshold != NULL) { |
285 | if ((i = get_status( procvsz, vsz_threshold )) != STATE_OK ) { | 294 | if ((i = get_status( procvsz, vsz_threshold )) != STATE_OK ) { |
286 | actions_on_failed_state(i, procprog); | 295 | actions_on_failed_state(i, procprog); |
296 | asprintf( &last_failed_process, "%s", procprog ); | ||
297 | if (i == STATE_CRITICAL) { | ||
298 | asprintf( &last_critical, "vsz=%d", procvsz ); | ||
299 | } else if (i == STATE_WARNING) { | ||
300 | asprintf( &last_warning, "vsz=%d", procvsz ); | ||
301 | } | ||
287 | if (verbose >= 2) { | 302 | if (verbose >= 2) { |
288 | printf("VSZ state %d: proc=%s vsz=%d ", i, procprog, procvsz); | 303 | printf("VSZ state %d: proc=%s vsz=%d ", i, procprog, procvsz); |
289 | print_thresholds( vsz_threshold ); | 304 | print_thresholds( vsz_threshold ); |
@@ -293,6 +308,12 @@ main (int argc, char **argv) | |||
293 | if (rss_threshold != NULL) { | 308 | if (rss_threshold != NULL) { |
294 | if ((i = get_status( procrss, rss_threshold )) != STATE_OK ) { | 309 | if ((i = get_status( procrss, rss_threshold )) != STATE_OK ) { |
295 | actions_on_failed_state(i, procprog); | 310 | actions_on_failed_state(i, procprog); |
311 | asprintf( &last_failed_process, "%s", procprog ); | ||
312 | if (i == STATE_CRITICAL) { | ||
313 | asprintf( &last_critical, "%s%srss=%d", last_critical, (strcmp(last_critical,"") ? ", " : ""), procrss ); | ||
314 | } else if (i == STATE_WARNING) { | ||
315 | asprintf( &last_warning, "%s%srss=%d", last_warning, (strcmp(last_warning,"") ? ", " : ""), procrss ); | ||
316 | } | ||
296 | if (verbose >= 2) { | 317 | if (verbose >= 2) { |
297 | printf("RSS: proc=%s rss=%d ", procprog, procrss); | 318 | printf("RSS: proc=%s rss=%d ", procprog, procrss); |
298 | print_thresholds( rss_threshold ); | 319 | print_thresholds( rss_threshold ); |
@@ -302,6 +323,12 @@ main (int argc, char **argv) | |||
302 | if (cpu_threshold != NULL) { | 323 | if (cpu_threshold != NULL) { |
303 | if (( i = get_status( procpcpu, cpu_threshold )) != STATE_OK ) { | 324 | if (( i = get_status( procpcpu, cpu_threshold )) != STATE_OK ) { |
304 | actions_on_failed_state(i, procprog); | 325 | actions_on_failed_state(i, procprog); |
326 | asprintf( &last_failed_process, "%s", procprog ); | ||
327 | if (i == STATE_CRITICAL) { | ||
328 | asprintf( &last_critical, "%s%scpu=%.2f%%", last_critical, (strcmp(last_critical,"") ? ", " : ""), procpcpu ); | ||
329 | } else if (i == STATE_WARNING) { | ||
330 | asprintf( &last_warning, "%s%scpu=%.2f%%", last_warning, (strcmp(last_warning,"") ? ", " : ""), procpcpu ); | ||
331 | } | ||
305 | if (verbose >= 2) { | 332 | if (verbose >= 2) { |
306 | printf("CPU: proc=%s cpu=%f ", procprog, procpcpu); | 333 | printf("CPU: proc=%s cpu=%f ", procprog, procpcpu); |
307 | print_thresholds( cpu_threshold ); | 334 | print_thresholds( cpu_threshold ); |
@@ -358,31 +385,54 @@ main (int argc, char **argv) | |||
358 | } | 385 | } |
359 | 386 | ||
360 | if (number_threshold != NULL) { | 387 | if (number_threshold != NULL) { |
361 | i = get_status( procs, number_threshold ); | 388 | if (i = get_status( procs, number_threshold ) != STATE_OK) { |
362 | actions_on_failed_state(i, "NUMBER_OF_PROCESSES"); | 389 | actions_on_failed_state(i, "NUMBER_OF_PROCESSES"); |
390 | if (verbose >= 2) { | ||
391 | printf("NUMBER: total_procs=%d ", procs); | ||
392 | print_thresholds( number_threshold ); | ||
393 | } | ||
394 | number_threshold_failure_flag = 1; | ||
395 | } | ||
363 | } | 396 | } |
364 | 397 | ||
365 | if ( result == STATE_OK ) { | 398 | if ( result == STATE_OK ) { |
366 | printf ("%s %s: ", metric_name, _("OK")); | 399 | printf ("%s %s: ", metric_name, _("OK")); |
400 | multiple_process_output_flag = 1; | ||
367 | } else if (result == STATE_WARNING) { | 401 | } else if (result == STATE_WARNING) { |
368 | printf ("%s %s: ", metric_name, _("WARNING")); | 402 | printf ("%s %s: ", metric_name, _("WARNING")); |
369 | if ( metric != METRIC_PROCS ) { | 403 | if (procs == 1 && new_style_thresholds && ! number_threshold_failure_flag) { |
370 | printf (_("Alerts: %d warn from "), warn); | 404 | printf("%s: warning %s", last_failed_process, last_warning); |
405 | } else { | ||
406 | if ( metric != METRIC_PROCS ) { | ||
407 | printf (_("Alerts: %d warn from "), warn); | ||
408 | } | ||
409 | multiple_process_output_flag = 1; | ||
371 | } | 410 | } |
372 | } else if (result == STATE_CRITICAL) { | 411 | } else if (result == STATE_CRITICAL) { |
373 | printf ("%s %s: ", metric_name, _("CRITICAL")); | 412 | printf ("%s %s: ", metric_name, _("CRITICAL")); |
374 | if (metric != METRIC_PROCS) { | 413 | if (procs == 1 && new_style_thresholds && ! number_threshold_failure_flag) { |
375 | printf (_("Alerts: %d crit, %d warn from "), crit, warn); | 414 | printf("%s: critical %s", last_failed_process, last_critical); |
415 | if (strcmp(last_warning, "")) { | ||
416 | printf("; warning %s", last_warning); | ||
417 | } | ||
418 | } else { | ||
419 | if (metric != METRIC_PROCS) { | ||
420 | printf (_("Alerts: %d crit, %d warn from "), crit, warn); | ||
421 | } | ||
422 | multiple_process_output_flag = 1; | ||
376 | } | 423 | } |
377 | } | 424 | } |
378 | printf (ngettext ("%d process", "%d processes", (unsigned long) procs), procs); | 425 | |
426 | if (multiple_process_output_flag) { | ||
427 | printf (ngettext ("%d process", "%d processes", (unsigned long) procs), procs); | ||
379 | 428 | ||
380 | if (strcmp(fmt,"") != 0) { | 429 | if (strcmp(fmt,"") != 0) { |
381 | printf (_(" with %s"), fmt); | 430 | printf (_(" with %s"), fmt); |
382 | } | 431 | } |
383 | 432 | ||
384 | if ( verbose >= 1 && strcmp(fails,"") ) | 433 | if ( verbose >= 1 && strcmp(fails,"") ) |
385 | printf (" [%s]", fails); | 434 | printf (" [%s]", fails); |
435 | } | ||
386 | 436 | ||
387 | printf(" | "); | 437 | printf(" | "); |
388 | if( number_threshold != NULL) | 438 | if( number_threshold != NULL) |
@@ -622,16 +672,19 @@ process_arguments (int argc, char **argv) | |||
622 | break; | 672 | break; |
623 | case CHAR_MAX+4: | 673 | case CHAR_MAX+4: |
624 | rss_threshold = parse_thresholds_string(optarg); | 674 | rss_threshold = parse_thresholds_string(optarg); |
675 | new_style_thresholds++; | ||
625 | if (metric == DEFAULT) | 676 | if (metric == DEFAULT) |
626 | default_metric=NONE; | 677 | default_metric=NONE; |
627 | break; | 678 | break; |
628 | case CHAR_MAX+7: | 679 | case CHAR_MAX+7: |
629 | vsz_threshold = parse_thresholds_string(optarg); | 680 | vsz_threshold = parse_thresholds_string(optarg); |
681 | new_style_thresholds++; | ||
630 | if (metric == DEFAULT) | 682 | if (metric == DEFAULT) |
631 | default_metric=NONE; | 683 | default_metric=NONE; |
632 | break; | 684 | break; |
633 | case CHAR_MAX+10: | 685 | case CHAR_MAX+10: |
634 | cpu_threshold = parse_thresholds_string(optarg); | 686 | cpu_threshold = parse_thresholds_string(optarg); |
687 | new_style_thresholds++; | ||
635 | if (metric == DEFAULT) | 688 | if (metric == DEFAULT) |
636 | default_metric=NONE; | 689 | default_metric=NONE; |
637 | break; | 690 | break; |