Răsfoiți Sursa

check_snmp: Add some verbose output and tests

Thomas Guyot-Sionnest 16 ani în urmă
părinte
comite
43571dba91
2 a modificat fișierele cu 10 adăugiri și 3 ștergeri
  1. 5 2
      plugins/check_snmp.c
  2. 5 1
      plugins/t/check_snmp.t

+ 5 - 2
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 */

+ 5 - 1
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");