summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorTon Voon <tonvoon@macbook.local>2009-03-14 02:36:20 (GMT)
committerTon Voon <tonvoon@macbook.local>2009-03-14 02:36:20 (GMT)
commit12c17fe8a25ada493a87ed3d5a5885e3414052ac (patch)
treefa4f64c77a1323331d533d8c784d49c6b5db4775 /plugins
parent36e58ae0c3ad7a9d3660722b35d3ed9c97687dd2 (diff)
downloadmonitoring-plugins-12c17fe8a25ada493a87ed3d5a5885e3414052ac.tar.gz
Ignore stderr messages unless return code is non-zero or there is no output
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_snmp.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 1b1eb2e..03c2a17 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -143,6 +143,8 @@ main (int argc, char **argv)
143 int i = 0; 143 int i = 0;
144 int iresult = STATE_UNKNOWN; 144 int iresult = STATE_UNKNOWN;
145 int result = STATE_UNKNOWN; 145 int result = STATE_UNKNOWN;
146 int return_code = 0;
147 int external_error = 0;
146 char **command_line = NULL; 148 char **command_line = NULL;
147 char *cl_hidden_auth = NULL; 149 char *cl_hidden_auth = NULL;
148 char *oidname = NULL; 150 char *oidname = NULL;
@@ -220,22 +222,28 @@ main (int argc, char **argv)
220 printf ("%s\n", cl_hidden_auth); 222 printf ("%s\n", cl_hidden_auth);
221 223
222 /* Run the command */ 224 /* Run the command */
223 result = cmd_run_array (command_line, &chld_out, &chld_err, 0); 225 return_code = cmd_run_array (command_line, &chld_out, &chld_err, 0);
224 226
225 if (chld_err.lines > 0) { 227 /* Due to net-snmp sometimes showing stderr messages with poorly formed MIBs,
226 printf (_("External command error: %s\n"), chld_err.line[0]); 228 only return state unknown if return code is non zero or there is no stdout.
227 for (i = 1; i < chld_err.lines; i++) { 229 Do this way so that if there is stderr, will get added to output, which helps problem diagnosis
228 printf ("%s\n", chld_err.line[i]); 230 /*
231 if (return_code != 0)
232 external_error=1;
233 if (chld_out.lines == 0)
234 external_error=1;
235 if (external_error) {
236 if (chld_err.lines > 0) {
237 printf (_("External command error: %s\n"), chld_err.line[0]);
238 for (i = 1; i < chld_err.lines; i++) {
239 printf ("%s\n", chld_err.line[i]);
240 }
241 } else {
242 printf(_("External command error with no output (return code: %d)\n"), return_code);
229 } 243 }
230 exit (STATE_UNKNOWN); 244 exit (STATE_UNKNOWN);
231 } 245 }
232 246
233 /* Return UNKNOWN or worse if no output is returned */
234 if (chld_out.lines == 0)
235 die (max_state_alt (result, STATE_UNKNOWN), _("%s problem - No data received from host\nCMD: %s\n"),
236 label,
237 cl_hidden_auth);
238
239 if (verbose) { 247 if (verbose) {
240 for (i = 0; i < chld_out.lines; i++) { 248 for (i = 0; i < chld_out.lines; i++) {
241 printf ("%s\n", chld_out.line[i]); 249 printf ("%s\n", chld_out.line[i]);