From 43571dba915621251378e35e85cc593803d9fbe6 Mon Sep 17 00:00:00 2001 From: Thomas Guyot-Sionnest Date: Fri, 31 Jul 2009 03:50:42 -0400 Subject: [PATCH] check_snmp: Add some verbose output and tests --- plugins/check_snmp.c | 7 +++++-- plugins/t/check_snmp.t | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index dff5bcc..9096cda 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -100,7 +100,7 @@ size_t nunits = 0; size_t unitv_size = 8; int numoids = 0; int numauthpriv = 0; -int verbose = FALSE; +int verbose = 0; int usesnmpgetnext = FALSE; char *warning_thresholds = NULL; char *critical_thresholds = NULL; @@ -255,6 +255,9 @@ main (int argc, char **argv) ptr = chld_out.line[i]; oidname = strpcpy (oidname, ptr, delimiter); response = strstr (ptr, delimiter); + if (verbose > 2) { + printf("Processing line %i\n line: %s\n oidname: %s\n response: %s\n", i+1, ptr, oidname, response); + } /* We strip out the datatype indicator for PHBs */ @@ -431,7 +434,7 @@ process_arguments (int argc, char **argv) print_revision (progname, NP_VERSION); exit (STATE_OK); case 'v': /* verbose */ - verbose = TRUE; + verbose++; break; /* Connection info */ diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index e0138e6..2ce0858 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t @@ -8,7 +8,7 @@ use strict; use Test::More; use NPTest; -my $tests = 44; +my $tests = 46; plan tests => $tests; my $res; @@ -54,6 +54,10 @@ SKIP: { cmp_ok( $value, ">", 0, "Got a time value" ); like($res->perf_output, "/sysUpTime.*$1/", "Got perfdata with value '$1' in it"); + $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:"); + cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" ); + like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); + $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0"); cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); -- 2.30.2