diff options
| author | Ton Voon <tonvoon@users.sourceforge.net> | 2008-03-18 01:21:54 +0000 |
|---|---|---|
| committer | Ton Voon <tonvoon@users.sourceforge.net> | 2008-03-18 01:21:54 +0000 |
| commit | a36696e454ccd3bcfd9fbb0d5f22f4fe176b6e7e (patch) | |
| tree | f15d20d8547269d084feeaf451e80f5aed85cc3b /plugins/check_procs.c | |
| parent | c0cf08d5fc319fa3bc9f5513e96059fef159a2cb (diff) | |
| download | monitoring-plugins-a36696e454ccd3bcfd9fbb0d5f22f4fe176b6e7e.tar.gz | |
Updated check_procs with a hidden --input-file option.
Include some sample outputs for testing
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1954 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_procs.c')
| -rw-r--r-- | plugins/check_procs.c | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 7dae8454..d56d4571 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
| @@ -91,11 +91,13 @@ float pcpu; | |||
| 91 | char *statopts; | 91 | char *statopts; |
| 92 | char *prog; | 92 | char *prog; |
| 93 | char *args; | 93 | char *args; |
| 94 | char *input_filename = NULL; | ||
| 94 | regex_t re_args; | 95 | regex_t re_args; |
| 95 | char *fmt; | 96 | char *fmt; |
| 96 | char *fails; | 97 | char *fails; |
| 97 | char tmp[MAX_INPUT_BUFFER]; | 98 | char tmp[MAX_INPUT_BUFFER]; |
| 98 | 99 | ||
| 100 | FILE *ps_input = NULL; | ||
| 99 | 101 | ||
| 100 | 102 | ||
| 101 | int | 103 | int |
| @@ -156,25 +158,31 @@ main (int argc, char **argv) | |||
| 156 | if (verbose >= 2) | 158 | if (verbose >= 2) |
| 157 | printf (_("CMD: %s\n"), PS_COMMAND); | 159 | printf (_("CMD: %s\n"), PS_COMMAND); |
| 158 | 160 | ||
| 159 | child_process = spopen (PS_COMMAND); | 161 | if (input_filename == NULL) { |
| 160 | if (child_process == NULL) { | 162 | ps_input = spopen (PS_COMMAND); |
| 161 | printf (_("Could not open pipe: %s\n"), PS_COMMAND); | 163 | if (ps_input == NULL) { |
| 162 | return STATE_UNKNOWN; | 164 | printf (_("Could not open pipe: %s\n"), PS_COMMAND); |
| 165 | return STATE_UNKNOWN; | ||
| 166 | } | ||
| 167 | child_stderr = fdopen (child_stderr_array[fileno (ps_input)], "r"); | ||
| 168 | if (child_stderr == NULL) | ||
| 169 | printf (_("Could not open stderr for %s\n"), PS_COMMAND); | ||
| 170 | } else { | ||
| 171 | ps_input = fopen(input_filename, "r"); | ||
| 172 | if (ps_input == NULL) { | ||
| 173 | die( STATE_UNKNOWN, _("Error opening %s\n"), input_filename ); | ||
| 174 | } | ||
| 163 | } | 175 | } |
| 164 | 176 | ||
| 165 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | ||
| 166 | if (child_stderr == NULL) | ||
| 167 | printf (_("Could not open stderr for %s\n"), PS_COMMAND); | ||
| 168 | |||
| 169 | /* flush first line */ | 177 | /* flush first line */ |
| 170 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process); | 178 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input); |
| 171 | while ( input_buffer[strlen(input_buffer)-1] != '\n' ) | 179 | while ( input_buffer[strlen(input_buffer)-1] != '\n' ) |
| 172 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process); | 180 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input); |
| 173 | 181 | ||
| 174 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 182 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input)) { |
| 175 | asprintf (&input_line, "%s", input_buffer); | 183 | asprintf (&input_line, "%s", input_buffer); |
| 176 | while ( input_buffer[strlen(input_buffer)-1] != '\n' ) { | 184 | while ( input_buffer[strlen(input_buffer)-1] != '\n' ) { |
| 177 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process); | 185 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input); |
| 178 | asprintf (&input_line, "%s%s", input_line, input_buffer); | 186 | asprintf (&input_line, "%s%s", input_line, input_buffer); |
| 179 | } | 187 | } |
| 180 | 188 | ||
| @@ -273,19 +281,21 @@ main (int argc, char **argv) | |||
| 273 | } | 281 | } |
| 274 | 282 | ||
| 275 | /* If we get anything on STDERR, at least set warning */ | 283 | /* If we get anything on STDERR, at least set warning */ |
| 276 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | 284 | if (input_filename == NULL) { |
| 277 | if (verbose) | 285 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { |
| 278 | printf ("STDERR: %s", input_buffer); | 286 | if (verbose) |
| 279 | result = max_state (result, STATE_WARNING); | 287 | printf ("STDERR: %s", input_buffer); |
| 280 | printf (_("System call sent warnings to stderr\n")); | 288 | result = max_state (result, STATE_WARNING); |
| 281 | } | 289 | printf (_("System call sent warnings to stderr\n")); |
| 290 | } | ||
| 282 | 291 | ||
| 283 | (void) fclose (child_stderr); | 292 | (void) fclose (child_stderr); |
| 284 | 293 | ||
| 285 | /* close the pipe */ | 294 | /* close the pipe */ |
| 286 | if (spclose (child_process)) { | 295 | if (spclose (ps_input)) { |
| 287 | printf (_("System call returned nonzero status\n")); | 296 | printf (_("System call returned nonzero status\n")); |
| 288 | result = max_state (result, STATE_WARNING); | 297 | result = max_state (result, STATE_WARNING); |
| 298 | } | ||
| 289 | } | 299 | } |
| 290 | 300 | ||
| 291 | if (found == 0) { /* no process lines parsed so return STATE_UNKNOWN */ | 301 | if (found == 0) { /* no process lines parsed so return STATE_UNKNOWN */ |
| @@ -357,6 +367,7 @@ process_arguments (int argc, char **argv) | |||
| 357 | {"version", no_argument, 0, 'V'}, | 367 | {"version", no_argument, 0, 'V'}, |
| 358 | {"verbose", no_argument, 0, 'v'}, | 368 | {"verbose", no_argument, 0, 'v'}, |
| 359 | {"ereg-argument-array", required_argument, 0, CHAR_MAX+1}, | 369 | {"ereg-argument-array", required_argument, 0, CHAR_MAX+1}, |
| 370 | {"input-file", required_argument, 0, CHAR_MAX+2}, | ||
| 360 | {0, 0, 0, 0} | 371 | {0, 0, 0, 0} |
| 361 | }; | 372 | }; |
| 362 | 373 | ||
| @@ -523,6 +534,9 @@ process_arguments (int argc, char **argv) | |||
| 523 | case 'v': /* command */ | 534 | case 'v': /* command */ |
| 524 | verbose++; | 535 | verbose++; |
| 525 | break; | 536 | break; |
| 537 | case CHAR_MAX+2: | ||
| 538 | input_filename = optarg; | ||
| 539 | break; | ||
| 526 | } | 540 | } |
| 527 | } | 541 | } |
| 528 | 542 | ||
| @@ -690,7 +704,7 @@ print_help (void) | |||
| 690 | { | 704 | { |
| 691 | print_revision (progname, revision); | 705 | print_revision (progname, revision); |
| 692 | 706 | ||
| 693 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>"); | 707 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); |
| 694 | printf (COPYRIGHT, copyright, email); | 708 | printf (COPYRIGHT, copyright, email); |
| 695 | 709 | ||
| 696 | printf ("%s\n", _("Checks all processes and generates WARNING or CRITICAL states if the specified")); | 710 | printf ("%s\n", _("Checks all processes and generates WARNING or CRITICAL states if the specified")); |
