aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_snmp.c
diff options
context:
space:
mode:
authorGravatar Ton Voon <tonvoon@macbook.local> 2009-03-14 02:36:20 +0000
committerGravatar Ton Voon <tonvoon@macbook.local> 2009-03-14 02:36:20 +0000
commit12c17fe8a25ada493a87ed3d5a5885e3414052ac (patch)
treefa4f64c77a1323331d533d8c784d49c6b5db4775 /plugins/check_snmp.c
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/check_snmp.c')
-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 1b1eb2e8..03c2a174 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -143,6 +143,8 @@ main (int argc, char **argv)
int i = 0;
int iresult = STATE_UNKNOWN;
int result = STATE_UNKNOWN;
+ int return_code = 0;
+ int external_error = 0;
char **command_line = NULL;
char *cl_hidden_auth = NULL;
char *oidname = NULL;
@@ -220,22 +222,28 @@ main (int argc, char **argv)
printf ("%s\n", cl_hidden_auth);
/* Run the command */
- result = cmd_run_array (command_line, &chld_out, &chld_err, 0);
-
- if (chld_err.lines > 0) {
- printf (_("External command error: %s\n"), chld_err.line[0]);
- for (i = 1; i < chld_err.lines; i++) {
- printf ("%s\n", chld_err.line[i]);
+ return_code = cmd_run_array (command_line, &chld_out, &chld_err, 0);
+
+ /* Due to net-snmp sometimes showing stderr messages with poorly formed MIBs,
+ only return state unknown if return code is non zero or there is no stdout.
+ Do this way so that if there is stderr, will get added to output, which helps problem diagnosis
+ /*
+ if (return_code != 0)
+ external_error=1;
+ if (chld_out.lines == 0)
+ external_error=1;
+ if (external_error) {
+ if (chld_err.lines > 0) {
+ printf (_("External command error: %s\n"), chld_err.line[0]);
+ for (i = 1; i < chld_err.lines; i++) {
+ printf ("%s\n", chld_err.line[i]);
+ }
+ } else {
+ printf(_("External command error with no output (return code: %d)\n"), return_code);
}
exit (STATE_UNKNOWN);
}
- /* Return UNKNOWN or worse if no output is returned */
- if (chld_out.lines == 0)
- die (max_state_alt (result, STATE_UNKNOWN), _("%s problem - No data received from host\nCMD: %s\n"),
- label,
- cl_hidden_auth);
-
if (verbose) {
for (i = 0; i < chld_out.lines; i++) {
printf ("%s\n", chld_out.line[i]);