diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_snmp.c | 2 | ||||
-rw-r--r-- | plugins/t/check_snmp.t | 26 |
2 files changed, 18 insertions, 10 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index db16462..dcb3138 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -506,7 +506,7 @@ process_arguments (int argc, char **argv) | |||
506 | */ | 506 | */ |
507 | needmibs = TRUE; | 507 | needmibs = TRUE; |
508 | } | 508 | } |
509 | oids = calloc(MAX_OIDS, sizeof (char *)); | 509 | if (!oids) oids = calloc(MAX_OIDS, sizeof (char *)); |
510 | for (ptr = strtok(optarg, ", "); ptr != NULL && j < MAX_OIDS; ptr = strtok(NULL, ", "), j++) { | 510 | for (ptr = strtok(optarg, ", "); ptr != NULL && j < MAX_OIDS; ptr = strtok(NULL, ", "), j++) { |
511 | oids[j] = strdup(ptr); | 511 | oids[j] = strdup(ptr); |
512 | } | 512 | } |
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index d65fd0b..004ba1a 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t | |||
@@ -8,7 +8,7 @@ use strict; | |||
8 | use Test::More; | 8 | use Test::More; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | my $tests = 46; | 11 | my $tests = 8+38+2+2; |
12 | plan tests => $tests; | 12 | plan tests => $tests; |
13 | my $res; | 13 | my $res; |
14 | 14 | ||
@@ -44,10 +44,10 @@ SKIP: { | |||
44 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); | 44 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); |
45 | 45 | ||
46 | SKIP: { | 46 | SKIP: { |
47 | skip "no snmp host defined", 34 if ( ! $host_snmp ); | 47 | skip "no snmp host defined", 38 if ( ! $host_snmp ); |
48 | 48 | ||
49 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); | 49 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); |
50 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); | 50 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); |
51 | like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK"); | 51 | like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK"); |
52 | $res->output =~ /^SNMP OK - (\d+)/; | 52 | $res->output =~ /^SNMP OK - (\d+)/; |
53 | my $value = $1; | 53 | my $value = $1; |
@@ -59,19 +59,27 @@ SKIP: { | |||
59 | like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); | 59 | like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); |
60 | 60 | ||
61 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0"); | 61 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0"); |
62 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); | 62 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); |
63 | unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); | 63 | unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); |
64 | 64 | ||
65 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0"); | ||
66 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" ); | ||
67 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | ||
68 | |||
69 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0"); | ||
70 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" ); | ||
71 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | ||
72 | |||
65 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"); | 73 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"); |
66 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); | 74 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); |
67 | like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format"); | 75 | like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format"); |
68 | 76 | ||
69 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"); | 77 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"); |
70 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); | 78 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); |
71 | like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format"); | 79 | like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format"); |
72 | 80 | ||
73 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); | 81 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); |
74 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); | 82 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); |
75 | like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format"); | 83 | like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format"); |
76 | 84 | ||
77 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2"); | 85 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2"); |
@@ -123,14 +131,14 @@ SKIP: { | |||
123 | SKIP: { | 131 | SKIP: { |
124 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); | 132 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); |
125 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | 133 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); |
126 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); | 134 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); |
127 | like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem"); | 135 | like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem"); |
128 | } | 136 | } |
129 | 137 | ||
130 | SKIP: { | 138 | SKIP: { |
131 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); | 139 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); |
132 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | 140 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); |
133 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); | 141 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); |
134 | like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host"); | 142 | like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host"); |
135 | } | 143 | } |
136 | 144 | ||