diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/check_procs.c | 61 |
2 files changed, 16 insertions, 47 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 67c49ca..85e4a5d 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am | |||
@@ -79,7 +79,7 @@ check_nwstat_LDADD = $(NETLIBS) | |||
79 | check_overcr_LDADD = $(NETLIBS) | 79 | check_overcr_LDADD = $(NETLIBS) |
80 | check_pgsql_LDADD = $(NETLIBS) $(PGLIBS) | 80 | check_pgsql_LDADD = $(NETLIBS) $(PGLIBS) |
81 | check_ping_LDADD = $(NETLIBS) popen.o | 81 | check_ping_LDADD = $(NETLIBS) popen.o |
82 | check_procs_LDADD = $(BASEOBJS) popen.o | 82 | check_procs_LDADD = $(BASEOBJS) |
83 | check_radius_LDADD = $(NETLIBS) $(RADIUSLIBS) | 83 | check_radius_LDADD = $(NETLIBS) $(RADIUSLIBS) |
84 | check_real_LDADD = $(NETLIBS) | 84 | check_real_LDADD = $(NETLIBS) |
85 | check_snmp_LDADD = $(BASEOBJS) popen.o | 85 | check_snmp_LDADD = $(BASEOBJS) popen.o |
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index 875f867..4aaeddb 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -41,8 +41,8 @@ const char *copyright = "2000-2008"; | |||
41 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 41 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
42 | 42 | ||
43 | #include "common.h" | 43 | #include "common.h" |
44 | #include "popen.h" | ||
45 | #include "utils.h" | 44 | #include "utils.h" |
45 | #include "utils_cmd.h" | ||
46 | #include "regex.h" | 46 | #include "regex.h" |
47 | 47 | ||
48 | #include <pwd.h> | 48 | #include <pwd.h> |
@@ -129,8 +129,9 @@ main (int argc, char **argv) | |||
129 | int expected_cols = PS_COLS - 1; | 129 | int expected_cols = PS_COLS - 1; |
130 | int warn = 0; /* number of processes in warn state */ | 130 | int warn = 0; /* number of processes in warn state */ |
131 | int crit = 0; /* number of processes in crit state */ | 131 | int crit = 0; /* number of processes in crit state */ |
132 | int i = 0; | 132 | int i = 0, j = 0; |
133 | int result = STATE_UNKNOWN; | 133 | int result = STATE_UNKNOWN; |
134 | output chld_out, chld_err; | ||
134 | 135 | ||
135 | setlocale (LC_ALL, ""); | 136 | setlocale (LC_ALL, ""); |
136 | bindtextdomain (PACKAGE, LOCALEDIR); | 137 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -153,41 +154,27 @@ main (int argc, char **argv) | |||
153 | mypid = getpid(); | 154 | mypid = getpid(); |
154 | 155 | ||
155 | /* Set signal handling and alarm timeout */ | 156 | /* Set signal handling and alarm timeout */ |
156 | if (signal (SIGALRM, popen_timeout_alarm_handler) == SIG_ERR) { | 157 | if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { |
157 | usage4 (_("Cannot catch SIGALRM")); | 158 | die (STATE_UNKNOWN, _("Cannot catch SIGALRM")); |
158 | } | 159 | } |
159 | alarm (timeout_interval); | 160 | (void) alarm ((unsigned) timeout_interval); |
160 | 161 | ||
161 | if (verbose >= 2) | 162 | if (verbose >= 2) |
162 | printf (_("CMD: %s\n"), PS_COMMAND); | 163 | printf (_("CMD: %s\n"), PS_COMMAND); |
163 | 164 | ||
164 | if (input_filename == NULL) { | 165 | if (input_filename == NULL) { |
165 | ps_input = spopen (PS_COMMAND); | 166 | result = cmd_run( PS_COMMAND, &chld_out, &chld_err, 0); |
166 | if (ps_input == NULL) { | 167 | if (chld_err.lines > 0) { |
167 | printf (_("Could not open pipe: %s\n"), PS_COMMAND); | 168 | printf ("%s: %s", _("System call sent warnings to stderr"), chld_err.line[0]); |
168 | return STATE_UNKNOWN; | 169 | exit(STATE_WARNING); |
169 | } | 170 | } |
170 | child_stderr = fdopen (child_stderr_array[fileno (ps_input)], "r"); | ||
171 | if (child_stderr == NULL) | ||
172 | printf (_("Could not open stderr for %s\n"), PS_COMMAND); | ||
173 | } else { | 171 | } else { |
174 | ps_input = fopen(input_filename, "r"); | 172 | result = cmd_file_read( input_filename, &chld_out, 0); |
175 | if (ps_input == NULL) { | ||
176 | die( STATE_UNKNOWN, _("Error opening %s\n"), input_filename ); | ||
177 | } | ||
178 | } | 173 | } |
179 | 174 | ||
180 | /* flush first line */ | 175 | /* flush first line: j starts at 1 */ |
181 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input); | 176 | for (j = 1; j < chld_out.lines; j++) { |
182 | while ( input_buffer[strlen(input_buffer)-1] != '\n' ) | 177 | input_line = chld_out.line[j]; |
183 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input); | ||
184 | |||
185 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input)) { | ||
186 | asprintf (&input_line, "%s", input_buffer); | ||
187 | while ( input_buffer[strlen(input_buffer)-1] != '\n' ) { | ||
188 | fgets (input_buffer, MAX_INPUT_BUFFER - 1, ps_input); | ||
189 | asprintf (&input_line, "%s%s", input_line, input_buffer); | ||
190 | } | ||
191 | 178 | ||
192 | if (verbose >= 3) | 179 | if (verbose >= 3) |
193 | printf ("%s", input_line); | 180 | printf ("%s", input_line); |
@@ -283,27 +270,9 @@ main (int argc, char **argv) | |||
283 | } | 270 | } |
284 | } | 271 | } |
285 | 272 | ||
286 | /* If we get anything on STDERR, at least set warning */ | ||
287 | if (input_filename == NULL) { | ||
288 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) { | ||
289 | if (verbose) | ||
290 | printf ("STDERR: %s", input_buffer); | ||
291 | result = max_state (result, STATE_WARNING); | ||
292 | printf (_("System call sent warnings to stderr\n")); | ||
293 | } | ||
294 | |||
295 | (void) fclose (child_stderr); | ||
296 | |||
297 | /* close the pipe */ | ||
298 | if (spclose (ps_input)) { | ||
299 | printf (_("System call returned nonzero status\n")); | ||
300 | result = max_state (result, STATE_WARNING); | ||
301 | } | ||
302 | } | ||
303 | |||
304 | if (found == 0) { /* no process lines parsed so return STATE_UNKNOWN */ | 273 | if (found == 0) { /* no process lines parsed so return STATE_UNKNOWN */ |
305 | printf (_("Unable to read output\n")); | 274 | printf (_("Unable to read output\n")); |
306 | return result; | 275 | return STATE_UNKNOWN; |
307 | } | 276 | } |
308 | 277 | ||
309 | if ( result == STATE_UNKNOWN ) | 278 | if ( result == STATE_UNKNOWN ) |