diff options
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index ccf0891..1b641c5 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -1,114 +1,36 @@ | |||
1 | /****************************************************************************** | 1 | /****************************************************************************** |
2 | * | ||
3 | * CHECK_PROCS.C | ||
4 | * | ||
5 | * Program: Process plugin for Nagios | ||
6 | * License: GPL | ||
7 | * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) | ||
8 | * | ||
9 | * $Id$ | ||
10 | * | ||
11 | * Description: | ||
12 | * | ||
13 | * This plugin checks the number of currently running processes and | ||
14 | * generates WARNING or CRITICAL states if the process count is outside | ||
15 | * the specified threshold ranges. The process count can be filtered by | ||
16 | * process owner, parent process PID, current state (e.g., 'Z'), or may | ||
17 | * be the total number of running processes | ||
18 | * | ||
19 | * License Information: | ||
20 | * | ||
21 | * This program is free software; you can redistribute it and/or modify | ||
22 | * it under the terms of the GNU General Public License as published by | ||
23 | * the Free Software Foundation; either version 2 of the License, or | ||
24 | * (at your option) any later version. | ||
25 | * | ||
26 | * This program is distributed in the hope that it will be useful, but | ||
27 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
29 | * General Public License for more details. | ||
30 | * | ||
31 | * You should have received a copy of the GNU General Public License | ||
32 | * along with this program; if not, write to the Free Software | ||
33 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
34 | * | ||
35 | ******************************************************************************/ | ||
36 | 2 | ||
37 | const char *progname = "check_procs"; | 3 | This program is free software; you can redistribute it and/or modify |
38 | #define REVISION "$Revision$" | 4 | it under the terms of the GNU General Public License as published by |
39 | #define COPYRIGHT "1999-2002" | 5 | the Free Software Foundation; either version 2 of the License, or |
40 | #define AUTHOR "Ethan Galstad" | 6 | (at your option) any later version. |
41 | #define EMAIL "nagios@nagios.org" | ||
42 | #define SUMMARY "\ | ||
43 | Checks all processes and generates WARNING or CRITICAL states if the specified\n\ | ||
44 | metric is outside the required threshold ranges. The metric defaults to number\n\ | ||
45 | of processes. Search filters can be applied to limit the processes to check.\n" | ||
46 | 7 | ||
47 | #define OPTIONS "\ | 8 | This program is distributed in the hope that it will be useful, |
48 | -w <range> -c <range> [-m metric]\n\ | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
49 | [-s state] [-p ppid] [-u user] [-r rss] [-z vsz] [-P %cpu]\n\ | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
50 | [-a argument-array] [-C command] [-v]" | 11 | GNU General Public License for more details. |
51 | 12 | ||
52 | #define LONGOPTIONS "\ | 13 | You should have received a copy of the GNU General Public License |
53 | Required Arguments:\n\ | 14 | along with this program; if not, write to the Free Software |
54 | -w, --warning=RANGE\n\ | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
55 | Generate warning state if metric is outside this range\n\ | ||
56 | -c, --critical=RANGE\n\ | ||
57 | Generate critical state if metric is outside this range\n\ | ||
58 | Optional Arguments:\n\ | ||
59 | -m, --metric=TYPE\n\ | ||
60 | Check thresholds against metric. Valid types:\n\ | ||
61 | PROCS - number of processes (default)\n\ | ||
62 | VSZ - virtual memory size\n\ | ||
63 | RSS - resident set memory size\n\ | ||
64 | CPU - percentage cpu\n\ | ||
65 | -v, --verbose\n\ | ||
66 | Extra information. Up to 3 verbosity levels\n\ | ||
67 | Optional Filters:\n\ | ||
68 | -s, --state=STATUSFLAGS\n\ | ||
69 | Only scan for processes that have, in the output of `ps`, one or\n\ | ||
70 | more of the status flags you specify (for example R, Z, S, RS,\n\ | ||
71 | RSZDT, plus others based on the output of your 'ps' command).\n\ | ||
72 | -p, --ppid=PPID\n\ | ||
73 | Only scan for children of the parent process ID indicated.\n\ | ||
74 | -z, --vsz=VSZ\n\ | ||
75 | Only scan for processes with vsz higher than indicated.\n\ | ||
76 | -r, --rss=RSS\n\ | ||
77 | Only scan for processes with rss higher than indicated.\n\ | ||
78 | -P, --pcpu=PCPU\n\ | ||
79 | Only scan for processes with pcpu higher than indicated.\n\ | ||
80 | -u, --user=USER\n\ | ||
81 | Only scan for processes with user name or ID indicated.\n\ | ||
82 | -a, --argument-array=STRING\n\ | ||
83 | Only scan for processes with args that contain STRING.\n\ | ||
84 | -C, --command=COMMAND\n\ | ||
85 | Only scan for exact matches to the named COMMAND.\n\ | ||
86 | \n\ | ||
87 | RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If\n\ | ||
88 | specified 'max:min', a warning status will be generated if the\n\ | ||
89 | count is inside the specified range\n" | ||
90 | 16 | ||
91 | #define EXAMPLES "\ | 17 | ******************************************************************************/ |
92 | check_procs -w 2:2 -c 2:1024 -C portsentry\n\ | 18 | |
93 | Warning if not two processes with command name portsentry. Critical\n\ | 19 | const char *progname = "check_procs"; |
94 | if < 2 or > 1024 processes\n\ | 20 | const char *revision = "$Revision$"; |
95 | check_procs -w 10 -a '/usr/local/bin/perl' -u root\n\ | 21 | const char *copyright = "2000-2003"; |
96 | Warning alert if > 10 processes with command arguments containing \n\ | 22 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
97 | '/usr/local/bin/perl' and owned by root\n\ | ||
98 | check_procs -w 50000 -c 100000 --metric=VSZ\n\ | ||
99 | Alert if vsz of any processes over 50K or 100K\n" | ||
100 | 23 | ||
101 | #include "config.h" | ||
102 | #include <pwd.h> | ||
103 | #include "common.h" | 24 | #include "common.h" |
104 | #include "popen.h" | 25 | #include "popen.h" |
105 | #include "utils.h" | 26 | #include "utils.h" |
27 | #include <pwd.h> | ||
106 | 28 | ||
107 | int process_arguments (int, char **); | 29 | int process_arguments (int, char **); |
108 | int validate_arguments (void); | 30 | int validate_arguments (void); |
109 | void print_usage (void); | ||
110 | void print_help (void); | ||
111 | int check_thresholds (int); | 31 | int check_thresholds (int); |
32 | void print_help (void); | ||
33 | void print_usage (void); | ||
112 | 34 | ||
113 | int wmax = -1; | 35 | int wmax = -1; |
114 | int cmax = -1; | 36 | int cmax = -1; |
@@ -147,6 +69,11 @@ char *fmt = ""; | |||
147 | char *fails = ""; | 69 | char *fails = ""; |
148 | char tmp[MAX_INPUT_BUFFER]; | 70 | char tmp[MAX_INPUT_BUFFER]; |
149 | 71 | ||
72 | |||
73 | |||
74 | |||
75 | |||
76 | |||
150 | int | 77 | int |
151 | main (int argc, char **argv) | 78 | main (int argc, char **argv) |
152 | { | 79 | { |
@@ -170,7 +97,7 @@ main (int argc, char **argv) | |||
170 | int cols; /* number of columns in ps output */ | 97 | int cols; /* number of columns in ps output */ |
171 | int warn = 0; /* number of processes in warn state */ | 98 | int warn = 0; /* number of processes in warn state */ |
172 | int crit = 0; /* number of processes in crit state */ | 99 | int crit = 0; /* number of processes in crit state */ |
173 | int i; | 100 | int i = 0; |
174 | 101 | ||
175 | int result = STATE_UNKNOWN; | 102 | int result = STATE_UNKNOWN; |
176 | 103 | ||
@@ -178,26 +105,26 @@ main (int argc, char **argv) | |||
178 | metric = METRIC_PROCS; | 105 | metric = METRIC_PROCS; |
179 | 106 | ||
180 | if (process_arguments (argc, argv) == ERROR) | 107 | if (process_arguments (argc, argv) == ERROR) |
181 | usage ("Unable to parse command line\n"); | 108 | usage (_("Unable to parse command line\n")); |
182 | 109 | ||
183 | if (verbose >= 2) | 110 | if (verbose >= 2) |
184 | printf ("CMD: %s\n", PS_COMMAND); | 111 | printf (_("CMD: %s\n"), PS_COMMAND); |
185 | 112 | ||
186 | child_process = spopen (PS_COMMAND); | 113 | child_process = spopen (PS_COMMAND); |
187 | if (child_process == NULL) { | 114 | if (child_process == NULL) { |
188 | printf ("Could not open pipe: %s\n", PS_COMMAND); | 115 | printf (_("Could not open pipe: %s\n"), PS_COMMAND); |
189 | return STATE_UNKNOWN; | 116 | return STATE_UNKNOWN; |
190 | } | 117 | } |
191 | 118 | ||
192 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | 119 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); |
193 | if (child_stderr == NULL) | 120 | if (child_stderr == NULL) |
194 | printf ("Could not open stderr for %s\n", PS_COMMAND); | 121 | printf (_("Could not open stderr for %s\n"), PS_COMMAND); |
195 | 122 | ||
196 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process); | 123 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process); |
197 | 124 | ||
198 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 125 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { |
199 | strcpy(procprog,""); | 126 | strcpy (procprog, ""); |
200 | asprintf(&procargs,""); | 127 | asprintf (&procargs, "%s", ""); |
201 | 128 | ||
202 | cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST); | 129 | cols = sscanf (input_buffer, PS_FORMAT, PS_VARLIST); |
203 | 130 | ||
@@ -270,28 +197,28 @@ main (int argc, char **argv) | |||
270 | } | 197 | } |
271 | /* This should not happen */ | 198 | /* This should not happen */ |
272 | else if (verbose) { | 199 | else if (verbose) { |
273 | printf("Not parseable: %s", input_buffer); | 200 | printf(_("Not parseable: %s"), input_buffer); |
274 | } | 201 | } |
275 | } | 202 | } |
276 | 203 | ||
277 | /* If we get anything on STDERR, at least set warning */ | 204 | /* If we get anything on STDERR, at least set warning */ |
278 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | 205 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { |
279 | if (verbose) | 206 | if (verbose) |
280 | printf ("STDERR: %s", input_buffer); | 207 | printf (_("STDERR: %s"), input_buffer); |
281 | result = max_state (result, STATE_WARNING); | 208 | result = max_state (result, STATE_WARNING); |
282 | printf ("System call sent warnings to stderr\n"); | 209 | printf (_("System call sent warnings to stderr\n")); |
283 | } | 210 | } |
284 | 211 | ||
285 | (void) fclose (child_stderr); | 212 | (void) fclose (child_stderr); |
286 | 213 | ||
287 | /* close the pipe */ | 214 | /* close the pipe */ |
288 | if (spclose (child_process)) { | 215 | if (spclose (child_process)) { |
289 | printf ("System call returned nonzero status\n"); | 216 | printf (_("System call returned nonzero status\n")); |
290 | result = max_state (result, STATE_WARNING); | 217 | result = max_state (result, STATE_WARNING); |
291 | } | 218 | } |
292 | 219 | ||
293 | if (found == 0) { /* no process lines parsed so return STATE_UNKNOWN */ | 220 | if (found == 0) { /* no process lines parsed so return STATE_UNKNOWN */ |
294 | printf ("Unable to read output\n"); | 221 | printf (_("Unable to read output\n")); |
295 | return result; | 222 | return result; |
296 | } | 223 | } |
297 | 224 | ||
@@ -304,23 +231,23 @@ main (int argc, char **argv) | |||
304 | } | 231 | } |
305 | 232 | ||
306 | if ( result == STATE_OK ) { | 233 | if ( result == STATE_OK ) { |
307 | printf ("%s OK: %d process%s", | 234 | printf (_("%s OK: %d process%s"), |
308 | metric_name, procs, ( procs != 1 ? "es" : "") ); | 235 | metric_name, procs, ( procs != 1 ? "es" : "") ); |
309 | } else if (result == STATE_WARNING) { | 236 | } else if (result == STATE_WARNING) { |
310 | if ( metric == METRIC_PROCS ) { | 237 | if ( metric == METRIC_PROCS ) { |
311 | printf ("PROCS WARNING: %d process%s", procs, | 238 | printf (_("PROCS WARNING: %d process%s"), procs, |
312 | ( procs != 1 ? "es" : "")); | 239 | ( procs != 1 ? "es" : "")); |
313 | } else { | 240 | } else { |
314 | printf ("%s WARNING: %d warn out of %d process%s", | 241 | printf (_("%s WARNING: %d warn out of %d process%s"), |
315 | metric_name, warn, procs, | 242 | metric_name, warn, procs, |
316 | ( procs != 1 ? "es" : "")); | 243 | ( procs != 1 ? "es" : "")); |
317 | } | 244 | } |
318 | } else if (result == STATE_CRITICAL) { | 245 | } else if (result == STATE_CRITICAL) { |
319 | if (metric == METRIC_PROCS) { | 246 | if (metric == METRIC_PROCS) { |
320 | printf ("PROCS CRITICAL: %d process%s", procs, | 247 | printf (_("PROCS CRITICAL: %d process%s"), procs, |
321 | ( procs != 1 ? "es" : "")); | 248 | ( procs != 1 ? "es" : "")); |
322 | } else { | 249 | } else { |
323 | printf ("%s CRITICAL: %d crit, %d warn out of %d process%s", | 250 | printf (_("%s CRITICAL: %d crit, %d warn out of %d process%s"), |
324 | metric_name, crit, warn, procs, | 251 | metric_name, crit, warn, procs, |
325 | ( procs != 1 ? "es" : "")); | 252 | ( procs != 1 ? "es" : "")); |
326 | } | 253 | } |
@@ -337,38 +264,11 @@ main (int argc, char **argv) | |||
337 | return result; | 264 | return result; |
338 | } | 265 | } |
339 | 266 | ||
340 | /* Check thresholds against value */ | ||
341 | int | ||
342 | check_thresholds (int value) | ||
343 | { | ||
344 | if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) { | ||
345 | return OK; | ||
346 | } | ||
347 | else if (cmax >= 0 && cmin >= 0 && cmax < cmin) { | ||
348 | if (value > cmax && value < cmin) | ||
349 | return STATE_CRITICAL; | ||
350 | } | ||
351 | else if (cmax >= 0 && value > cmax) { | ||
352 | return STATE_CRITICAL; | ||
353 | } | ||
354 | else if (cmin >= 0 && value < cmin) { | ||
355 | return STATE_CRITICAL; | ||
356 | } | ||
357 | 267 | ||
358 | if (wmax >= 0 && wmin >= 0 && wmax < wmin) { | ||
359 | if (value > wmax && value < wmin) { | ||
360 | return STATE_WARNING; | ||
361 | } | ||
362 | } | ||
363 | else if (wmax >= 0 && value > wmax) { | ||
364 | return STATE_WARNING; | ||
365 | } | ||
366 | else if (wmin >= 0 && value < wmin) { | ||
367 | return STATE_WARNING; | ||
368 | } | ||
369 | return STATE_OK; | ||
370 | } | ||
371 | 268 | ||
269 | |||
270 | |||
271 | |||
372 | /* process command-line arguments */ | 272 | /* process command-line arguments */ |
373 | int | 273 | int |
374 | process_arguments (int argc, char **argv) | 274 | process_arguments (int argc, char **argv) |
@@ -414,11 +314,11 @@ process_arguments (int argc, char **argv) | |||
414 | print_help (); | 314 | print_help (); |
415 | exit (STATE_OK); | 315 | exit (STATE_OK); |
416 | case 'V': /* version */ | 316 | case 'V': /* version */ |
417 | print_revision (progname, REVISION); | 317 | print_revision (progname, revision); |
418 | exit (STATE_OK); | 318 | exit (STATE_OK); |
419 | case 't': /* timeout period */ | 319 | case 't': /* timeout period */ |
420 | if (!is_integer (optarg)) { | 320 | if (!is_integer (optarg)) { |
421 | printf ("%s: Timeout Interval must be an integer!\n\n", | 321 | printf (_("%s: Timeout Interval must be an integer!\n\n"), |
422 | progname); | 322 | progname); |
423 | print_usage (); | 323 | print_usage (); |
424 | exit (STATE_UNKNOWN); | 324 | exit (STATE_UNKNOWN); |
@@ -440,7 +340,7 @@ process_arguments (int argc, char **argv) | |||
440 | break; | 340 | break; |
441 | } | 341 | } |
442 | else { | 342 | else { |
443 | printf ("%s: Critical Process Count must be an integer!\n\n", | 343 | printf (_("%s: Critical Process Count must be an integer!\n\n"), |
444 | progname); | 344 | progname); |
445 | print_usage (); | 345 | print_usage (); |
446 | exit (STATE_UNKNOWN); | 346 | exit (STATE_UNKNOWN); |
@@ -460,7 +360,7 @@ process_arguments (int argc, char **argv) | |||
460 | break; | 360 | break; |
461 | } | 361 | } |
462 | else { | 362 | else { |
463 | printf ("%s: Warning Process Count must be an integer!\n\n", | 363 | printf (_("%s: Warning Process Count must be an integer!\n\n"), |
464 | progname); | 364 | progname); |
465 | print_usage (); | 365 | print_usage (); |
466 | exit (STATE_UNKNOWN); | 366 | exit (STATE_UNKNOWN); |
@@ -471,13 +371,13 @@ process_arguments (int argc, char **argv) | |||
471 | options |= PPID; | 371 | options |= PPID; |
472 | break; | 372 | break; |
473 | } | 373 | } |
474 | printf ("%s: Parent Process ID must be an integer!\n\n", | 374 | printf (_("%s: Parent Process ID must be an integer!\n\n"), |
475 | progname); | 375 | progname); |
476 | print_usage (); | 376 | print_usage (); |
477 | exit (STATE_UNKNOWN); | 377 | exit (STATE_UNKNOWN); |
478 | case 's': /* status */ | 378 | case 's': /* status */ |
479 | asprintf (&statopts, "%s", optarg); | 379 | asprintf (&statopts, "%s", optarg); |
480 | asprintf (&fmt, "%s%sSTATE = %s", fmt, (options ? ", " : ""), statopts); | 380 | asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts); |
481 | options |= STAT; | 381 | options |= STAT; |
482 | break; | 382 | break; |
483 | case 'u': /* user or user id */ | 383 | case 'u': /* user or user id */ |
@@ -486,7 +386,7 @@ process_arguments (int argc, char **argv) | |||
486 | pw = getpwuid ((uid_t) uid); | 386 | pw = getpwuid ((uid_t) uid); |
487 | /* check to be sure user exists */ | 387 | /* check to be sure user exists */ |
488 | if (pw == NULL) { | 388 | if (pw == NULL) { |
489 | printf ("UID %d was not found\n", uid); | 389 | printf (_("UID %d was not found\n"), uid); |
490 | print_usage (); | 390 | print_usage (); |
491 | exit (STATE_UNKNOWN); | 391 | exit (STATE_UNKNOWN); |
492 | } | 392 | } |
@@ -495,7 +395,7 @@ process_arguments (int argc, char **argv) | |||
495 | pw = getpwnam (optarg); | 395 | pw = getpwnam (optarg); |
496 | /* check to be sure user exists */ | 396 | /* check to be sure user exists */ |
497 | if (pw == NULL) { | 397 | if (pw == NULL) { |
498 | printf ("User name %s was not found\n", optarg); | 398 | printf (_("User name %s was not found\n"), optarg); |
499 | print_usage (); | 399 | print_usage (); |
500 | exit (STATE_UNKNOWN); | 400 | exit (STATE_UNKNOWN); |
501 | } | 401 | } |
@@ -503,49 +403,49 @@ process_arguments (int argc, char **argv) | |||
503 | uid = pw->pw_uid; | 403 | uid = pw->pw_uid; |
504 | } | 404 | } |
505 | user = pw->pw_name; | 405 | user = pw->pw_name; |
506 | asprintf (&fmt, "%s%sUID = %d (%s)", fmt, (options ? ", " : ""), | 406 | asprintf (&fmt, _("%s%sUID = %d (%s)"), fmt, (options ? ", " : ""), |
507 | uid, user); | 407 | uid, user); |
508 | options |= USER; | 408 | options |= USER; |
509 | break; | 409 | break; |
510 | case 'C': /* command */ | 410 | case 'C': /* command */ |
511 | asprintf (&prog, "%s", optarg); | 411 | asprintf (&prog, "%s", optarg); |
512 | asprintf (&fmt, "%s%scommand name '%s'", fmt, (options ? ", " : ""), | 412 | asprintf (&fmt, _("%s%scommand name '%s'"), fmt, (options ? ", " : ""), |
513 | prog); | 413 | prog); |
514 | options |= PROG; | 414 | options |= PROG; |
515 | break; | 415 | break; |
516 | case 'a': /* args (full path name with args) */ | 416 | case 'a': /* args (full path name with args) */ |
517 | asprintf (&args, "%s", optarg); | 417 | asprintf (&args, "%s", optarg); |
518 | asprintf (&fmt, "%s%sargs '%s'", fmt, (options ? ", " : ""), args); | 418 | asprintf (&fmt, _("%s%sargs '%s'"), fmt, (options ? ", " : ""), args); |
519 | options |= ARGS; | 419 | options |= ARGS; |
520 | break; | 420 | break; |
521 | case 'r': /* RSS */ | 421 | case 'r': /* RSS */ |
522 | if (sscanf (optarg, "%d%[^0-9]", &rss, tmp) == 1) { | 422 | if (sscanf (optarg, "%d%[^0-9]", &rss, tmp) == 1) { |
523 | asprintf (&fmt, "%s%sRSS >= %d", fmt, (options ? ", " : ""), rss); | 423 | asprintf (&fmt, _("%s%sRSS >= %d"), fmt, (options ? ", " : ""), rss); |
524 | options |= RSS; | 424 | options |= RSS; |
525 | break; | 425 | break; |
526 | } | 426 | } |
527 | printf ("%s: RSS must be an integer!\n\n", | 427 | printf (_("%s: RSS must be an integer!\n\n"), |
528 | progname); | 428 | progname); |
529 | print_usage (); | 429 | print_usage (); |
530 | exit (STATE_UNKNOWN); | 430 | exit (STATE_UNKNOWN); |
531 | case 'z': /* VSZ */ | 431 | case 'z': /* VSZ */ |
532 | if (sscanf (optarg, "%d%[^0-9]", &vsz, tmp) == 1) { | 432 | if (sscanf (optarg, "%d%[^0-9]", &vsz, tmp) == 1) { |
533 | asprintf (&fmt, "%s%sVSZ >= %d", fmt, (options ? ", " : ""), vsz); | 433 | asprintf (&fmt, _("%s%sVSZ >= %d"), fmt, (options ? ", " : ""), vsz); |
534 | options |= VSZ; | 434 | options |= VSZ; |
535 | break; | 435 | break; |
536 | } | 436 | } |
537 | printf ("%s: VSZ must be an integer!\n\n", | 437 | printf (_("%s: VSZ must be an integer!\n\n"), |
538 | progname); | 438 | progname); |
539 | print_usage (); | 439 | print_usage (); |
540 | exit (STATE_UNKNOWN); | 440 | exit (STATE_UNKNOWN); |
541 | case 'P': /* PCPU */ | 441 | case 'P': /* PCPU */ |
542 | /* TODO: -P 1.5.5 is accepted */ | 442 | /* TODO: -P 1.5.5 is accepted */ |
543 | if (sscanf (optarg, "%f%[^0-9.]", &pcpu, tmp) == 1) { | 443 | if (sscanf (optarg, "%f%[^0-9.]", &pcpu, tmp) == 1) { |
544 | asprintf (&fmt, "%s%sPCPU >= %.2f", fmt, (options ? ", " : ""), pcpu); | 444 | asprintf (&fmt, _("%s%sPCPU >= %.2f"), fmt, (options ? ", " : ""), pcpu); |
545 | options |= PCPU; | 445 | options |= PCPU; |
546 | break; | 446 | break; |
547 | } | 447 | } |
548 | printf ("%s: PCPU must be a float!\n\n", | 448 | printf (_("%s: PCPU must be a float!\n\n"), |
549 | progname); | 449 | progname); |
550 | print_usage (); | 450 | print_usage (); |
551 | exit (STATE_UNKNOWN); | 451 | exit (STATE_UNKNOWN); |
@@ -567,7 +467,7 @@ process_arguments (int argc, char **argv) | |||
567 | metric = METRIC_CPU; | 467 | metric = METRIC_CPU; |
568 | break; | 468 | break; |
569 | } | 469 | } |
570 | printf ("%s: metric must be one of PROCS, VSZ, RSS, CPU!\n\n", | 470 | printf (_("%s: metric must be one of PROCS, VSZ, RSS, CPU!\n\n"), |
571 | progname); | 471 | progname); |
572 | print_usage (); | 472 | print_usage (); |
573 | exit (STATE_UNKNOWN); | 473 | exit (STATE_UNKNOWN); |
@@ -584,7 +484,7 @@ process_arguments (int argc, char **argv) | |||
584 | cmax = atoi (argv[c++]); | 484 | cmax = atoi (argv[c++]); |
585 | if (statopts == NULL && argv[c]) { | 485 | if (statopts == NULL && argv[c]) { |
586 | asprintf (&statopts, "%s", argv[c++]); | 486 | asprintf (&statopts, "%s", argv[c++]); |
587 | asprintf (&fmt, "%s%sSTATE = %s", fmt, (options ? ", " : ""), statopts); | 487 | asprintf (&fmt, _("%s%sSTATE = %s"), fmt, (options ? ", " : ""), statopts); |
588 | options |= STAT; | 488 | options |= STAT; |
589 | } | 489 | } |
590 | 490 | ||
@@ -592,6 +492,8 @@ process_arguments (int argc, char **argv) | |||
592 | } | 492 | } |
593 | 493 | ||
594 | 494 | ||
495 | |||
496 | |||
595 | int | 497 | int |
596 | validate_arguments () | 498 | validate_arguments () |
597 | { | 499 | { |
@@ -602,11 +504,11 @@ validate_arguments () | |||
602 | cmin = 0; | 504 | cmin = 0; |
603 | if (wmax >= wmin && cmax >= cmin) { /* standard ranges */ | 505 | if (wmax >= wmin && cmax >= cmin) { /* standard ranges */ |
604 | if (wmax > cmax && cmax != -1) { | 506 | if (wmax > cmax && cmax != -1) { |
605 | printf ("wmax (%d) cannot be greater than cmax (%d)\n", wmax, cmax); | 507 | printf (_("wmax (%d) cannot be greater than cmax (%d)\n"), wmax, cmax); |
606 | return ERROR; | 508 | return ERROR; |
607 | } | 509 | } |
608 | if (cmin > wmin && wmin != -1) { | 510 | if (cmin > wmin && wmin != -1) { |
609 | printf ("wmin (%d) cannot be less than cmin (%d)\n", wmin, cmin); | 511 | printf (_("wmin (%d) cannot be less than cmin (%d)\n"), wmin, cmin); |
610 | return ERROR; | 512 | return ERROR; |
611 | } | 513 | } |
612 | } | 514 | } |
@@ -623,22 +525,136 @@ validate_arguments () | |||
623 | } | 525 | } |
624 | 526 | ||
625 | 527 | ||
528 | |||
529 | |||
530 | |||
531 | |||
532 | /* Check thresholds against value */ | ||
533 | int | ||
534 | check_thresholds (int value) | ||
535 | { | ||
536 | if (wmax == -1 && cmax == -1 && wmin == -1 && cmin == -1) { | ||
537 | return OK; | ||
538 | } | ||
539 | else if (cmax >= 0 && cmin >= 0 && cmax < cmin) { | ||
540 | if (value > cmax && value < cmin) | ||
541 | return STATE_CRITICAL; | ||
542 | } | ||
543 | else if (cmax >= 0 && value > cmax) { | ||
544 | return STATE_CRITICAL; | ||
545 | } | ||
546 | else if (cmin >= 0 && value < cmin) { | ||
547 | return STATE_CRITICAL; | ||
548 | } | ||
549 | |||
550 | if (wmax >= 0 && wmin >= 0 && wmax < wmin) { | ||
551 | if (value > wmax && value < wmin) { | ||
552 | return STATE_WARNING; | ||
553 | } | ||
554 | } | ||
555 | else if (wmax >= 0 && value > wmax) { | ||
556 | return STATE_WARNING; | ||
557 | } | ||
558 | else if (wmin >= 0 && value < wmin) { | ||
559 | return STATE_WARNING; | ||
560 | } | ||
561 | return STATE_OK; | ||
562 | } | ||
563 | |||
564 | |||
565 | |||
566 | |||
567 | |||
568 | |||
626 | void | 569 | void |
627 | print_help (void) | 570 | print_help (void) |
628 | { | 571 | { |
629 | print_revision (progname, REVISION); | 572 | print_revision (progname, revision); |
630 | printf | 573 | |
631 | ("Copyright (c) %s %s <%s>\n\n%s\n", | 574 | printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>")); |
632 | COPYRIGHT, AUTHOR, EMAIL, SUMMARY); | 575 | printf (_(COPYRIGHT), copyright, email); |
576 | |||
577 | printf(_("\ | ||
578 | Checks all processes and generates WARNING or CRITICAL states if the specified\n\ | ||
579 | metric is outside the required threshold ranges. The metric defaults to number\n\ | ||
580 | of processes. Search filters can be applied to limit the processes to check.\n\n")); | ||
581 | |||
633 | print_usage (); | 582 | print_usage (); |
634 | printf ("\nOptions:\n" LONGOPTIONS "\nExamples:\n" EXAMPLES "\n"); | 583 | |
584 | printf(_("\n\ | ||
585 | Required Arguments:\n\ | ||
586 | -w, --warning=RANGE\n\ | ||
587 | Generate warning state if metric is outside this range\n\ | ||
588 | -c, --critical=RANGE\n\ | ||
589 | Generate critical state if metric is outside this range\n")); | ||
590 | |||
591 | printf(_("\n\ | ||
592 | Optional Arguments:\n\ | ||
593 | -m, --metric=TYPE\n\ | ||
594 | Check thresholds against metric. Valid types:\n\ | ||
595 | PROCS - number of processes (default)\n\ | ||
596 | VSZ - virtual memory size\n\ | ||
597 | RSS - resident set memory size\n\ | ||
598 | CPU - percentage cpu\n\ | ||
599 | -v, --verbose\n\ | ||
600 | Extra information. Up to 3 verbosity levels\n")); | ||
601 | |||
602 | printf(_("\n\ | ||
603 | Optional Filters:\n\ | ||
604 | -s, --state=STATUSFLAGS\n\ | ||
605 | Only scan for processes that have, in the output of `ps`, one or\n\ | ||
606 | more of the status flags you specify (for example R, Z, S, RS,\n\ | ||
607 | RSZDT, plus others based on the output of your 'ps' command).\n\ | ||
608 | -p, --ppid=PPID\n\ | ||
609 | Only scan for children of the parent process ID indicated.\n\ | ||
610 | -z, --vsz=VSZ\n\ | ||
611 | Only scan for processes with vsz higher than indicated.\n\ | ||
612 | -r, --rss=RSS\n\ | ||
613 | Only scan for processes with rss higher than indicated.\n")); | ||
614 | |||
615 | printf(_("\ | ||
616 | -P, --pcpu=PCPU\n\ | ||
617 | Only scan for processes with pcpu higher than indicated.\n\ | ||
618 | -u, --user=USER\n\ | ||
619 | Only scan for processes with user name or ID indicated.\n\ | ||
620 | -a, --argument-array=STRING\n\ | ||
621 | Only scan for processes with args that contain STRING.\n\ | ||
622 | -C, --command=COMMAND\n\ | ||
623 | Only scan for exact matches to the named COMMAND.\n")); | ||
624 | |||
625 | printf(_("\n\ | ||
626 | RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If\n\ | ||
627 | specified 'max:min', a warning status will be generated if the\n\ | ||
628 | count is inside the specified range\n\n")); | ||
629 | |||
630 | printf(_("\ | ||
631 | This plugin checks the number of currently running processes and\n\ | ||
632 | generates WARNING or CRITICAL states if the process count is outside\n\ | ||
633 | the specified threshold ranges. The process count can be filtered by\n\ | ||
634 | process owner, parent process PID, current state (e.g., 'Z'), or may\n\ | ||
635 | be the total number of running processes\n\n")); | ||
636 | |||
637 | printf(_("\ | ||
638 | Examples:\n\ | ||
639 | check_procs -w 2:2 -c 2:1024 -C portsentry\n\ | ||
640 | Warning if not two processes with command name portsentry. Critical\n\ | ||
641 | if < 2 or > 1024 processes\n\n\ | ||
642 | check_procs -w 10 -a '/usr/local/bin/perl' -u root\n\ | ||
643 | Warning alert if > 10 processes with command arguments containing \n\ | ||
644 | '/usr/local/bin/perl' and owned by root\n\n\ | ||
645 | check_procs -w 50000 -c 100000 --metric=VSZ\n\ | ||
646 | Alert if vsz of any processes over 50K or 100K\n\n")); | ||
647 | |||
648 | printf (_(UT_SUPPORT)); | ||
635 | } | 649 | } |
636 | 650 | ||
637 | void | 651 | void |
638 | print_usage (void) | 652 | print_usage (void) |
639 | { | 653 | { |
640 | printf ("Usage:\n" " %s %s\n" | 654 | printf ("\ |
641 | " %s (-h | --help) for detailed help\n" | 655 | Usage: %s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n\ |
642 | " %s (-V | --version) for version information\n", | 656 | [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n\ |
643 | progname, OPTIONS, progname, progname); | 657 | [-C command] [-v]\n", progname); |
658 | printf (_(UT_HLP_VRS), progname, progname); | ||
644 | } | 659 | } |
660 | |||