summaryrefslogtreecommitdiffstats
path: root/plugins/check_procs.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_procs.c')
-rw-r--r--plugins/check_procs.c109
1 files changed, 58 insertions, 51 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c
index 1b641c5..1894b28 100644
--- a/plugins/check_procs.c
+++ b/plugins/check_procs.c
@@ -49,12 +49,14 @@ int options = 0; /* bitmask of filter criteria to test against */
49#define PCPU 256 49#define PCPU 256
50 50
51/* Different metrics */ 51/* Different metrics */
52int metric = 0; 52char *metric_name;
53#define METRIC_PROCS 0 53enum metric {
54#define METRIC_VSZ 1 54 METRIC_PROCS,
55#define METRIC_RSS 2 55 METRIC_VSZ,
56#define METRIC_CPU 3 56 METRIC_RSS,
57char *metric_name = ""; 57 METRIC_CPU
58};
59enum metric metric = METRIC_PROCS;
58 60
59int verbose = 0; 61int verbose = 0;
60int uid; 62int uid;
@@ -62,11 +64,11 @@ int ppid;
62int vsz; 64int vsz;
63int rss; 65int rss;
64float pcpu; 66float pcpu;
65char *statopts = ""; 67char *statopts;
66char *prog = ""; 68char *prog;
67char *args = ""; 69char *args;
68char *fmt = ""; 70char *fmt;
69char *fails = ""; 71char *fails;
70char tmp[MAX_INPUT_BUFFER]; 72char tmp[MAX_INPUT_BUFFER];
71 73
72 74
@@ -317,54 +319,35 @@ process_arguments (int argc, char **argv)
317 print_revision (progname, revision); 319 print_revision (progname, revision);
318 exit (STATE_OK); 320 exit (STATE_OK);
319 case 't': /* timeout period */ 321 case 't': /* timeout period */
320 if (!is_integer (optarg)) { 322 if (!is_integer (optarg))
321 printf (_("%s: Timeout Interval must be an integer!\n\n"), 323 usage (_("Timeout Interval must be an integer!\n\n"));
322 progname); 324 else
323 print_usage (); 325 timeout_interval = atoi (optarg);
324 exit (STATE_UNKNOWN);
325 }
326 timeout_interval = atoi (optarg);
327 break; 326 break;
328 case 'c': /* critical threshold */ 327 case 'c': /* critical threshold */
329 if (is_integer (optarg)) { 328 if (is_integer (optarg))
330 cmax = atoi (optarg); 329 cmax = atoi (optarg);
330 else if (sscanf (optarg, ":%d", &cmax) == 1)
331 break; 331 break;
332 } 332 else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2)
333 else if (sscanf (optarg, ":%d", &cmax) == 1) {
334 break; 333 break;
335 } 334 else if (sscanf (optarg, "%d:", &cmin) == 1)
336 else if (sscanf (optarg, "%d:%d", &cmin, &cmax) == 2) {
337 break; 335 break;
338 } 336 else
339 else if (sscanf (optarg, "%d:", &cmin) == 1) { 337 usage (_("Critical Process Count must be an integer!\n\n"));
340 break; 338 break;
341 }
342 else {
343 printf (_("%s: Critical Process Count must be an integer!\n\n"),
344 progname);
345 print_usage ();
346 exit (STATE_UNKNOWN);
347 }
348 case 'w': /* warning time threshold */ 339 case 'w': /* warning time threshold */
349 if (is_integer (optarg)) { 340 if (is_integer (optarg))
350 wmax = atoi (optarg); 341 wmax = atoi (optarg);
342 else if (sscanf (optarg, ":%d", &wmax) == 1)
351 break; 343 break;
352 } 344 else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2)
353 else if (sscanf (optarg, ":%d", &wmax) == 1) {
354 break;
355 }
356 else if (sscanf (optarg, "%d:%d", &wmin, &wmax) == 2) {
357 break; 345 break;
358 } 346 else if (sscanf (optarg, "%d:", &wmin) == 1)
359 else if (sscanf (optarg, "%d:", &wmin) == 1) {
360 break; 347 break;
361 } 348 else
362 else { 349 usage (_("%s: Warning Process Count must be an integer!\n\n"));
363 printf (_("%s: Warning Process Count must be an integer!\n\n"), 350 break;
364 progname);
365 print_usage ();
366 exit (STATE_UNKNOWN);
367 }
368 case 'p': /* process id */ 351 case 'p': /* process id */
369 if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) { 352 if (sscanf (optarg, "%d%[^0-9]", &ppid, tmp) == 1) {
370 asprintf (&fmt, "%s%sPPID = %d", fmt, (options ? ", " : ""), ppid); 353 asprintf (&fmt, "%s%sPPID = %d", fmt, (options ? ", " : ""), ppid);
@@ -376,7 +359,10 @@ process_arguments (int argc, char **argv)
376 print_usage (); 359 print_usage ();
377 exit (STATE_UNKNOWN); 360 exit (STATE_UNKNOWN);
378 case 's': /* status */ 361 case 's': /* status */
379 asprintf (&statopts, "%s", optarg); 362 if (statopts)
363 break;
364 else
365 statopts = strdup(optarg);
380 asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts); 366 asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts);
381 options |= STAT; 367 options |= STAT;
382 break; 368 break;
@@ -408,13 +394,19 @@ process_arguments (int argc, char **argv)
408 options |= USER; 394 options |= USER;
409 break; 395 break;
410 case 'C': /* command */ 396 case 'C': /* command */
411 asprintf (&prog, "%s", optarg); 397 if (prog)
398 break;
399 else
400 prog = strdup(optarg);
412 asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""), 401 asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""),
413 prog); 402 prog);
414 options |= PROG; 403 options |= PROG;
415 break; 404 break;
416 case 'a': /* args (full path name with args) */ 405 case 'a': /* args (full path name with args) */
417 asprintf (&args, "%s", optarg); 406 if (args)
407 break;
408 else
409 args = strdup(optarg);
418 asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args); 410 asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args);
419 options |= ARGS; 411 options |= ARGS;
420 break; 412 break;
@@ -521,6 +513,21 @@ validate_arguments ()
521 if (options == 0) 513 if (options == 0)
522 options = ALL; 514 options = ALL;
523 515
516 if (statopts==NULL)
517 statopts = strdup("");
518
519 if (prog==NULL)
520 prog = strdup("");
521
522 if (args==NULL)
523 args = strdup("");
524
525 if (fmt==NULL)
526 fmt = strdup("");
527
528 if (fails==NULL)
529 fails = strdup("");
530
524 return options; 531 return options;
525} 532}
526 533