diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-09 02:07:32 +0200 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-09-09 02:07:32 +0200 |
commit | fbd60d6a9d9ba5b45879280dcfda92379dec65da (patch) | |
tree | a7c0e428be10bb27b6344c6531b804451c4d40cc /plugins/tests/check_snmp.t | |
parent | b54869391faab7ef91586c81de21f18a61bac5aa (diff) | |
parent | 615fec347cd575c0ee4343aa17ee99962f375f64 (diff) | |
download | monitoring-plugins-fbd60d6a9d9ba5b45879280dcfda92379dec65da.tar.gz |
Merge branch 'master' into refactor/check_curl
Diffstat (limited to 'plugins/tests/check_snmp.t')
-rwxr-xr-x | plugins/tests/check_snmp.t | 159 |
1 files changed, 75 insertions, 84 deletions
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index bfe42e16..26d67898 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t | |||
@@ -4,12 +4,13 @@ | |||
4 | # | 4 | # |
5 | 5 | ||
6 | use strict; | 6 | use strict; |
7 | use warnings; | ||
7 | use Test::More; | 8 | use Test::More; |
8 | use NPTest; | 9 | use NPTest; |
9 | use FindBin qw($Bin); | 10 | use FindBin qw($Bin); |
10 | use POSIX qw/strftime/; | 11 | use POSIX qw/strftime/; |
11 | 12 | ||
12 | my $tests = 81; | 13 | my $tests = 75; |
13 | # Check that all dependent modules are available | 14 | # Check that all dependent modules are available |
14 | eval { | 15 | eval { |
15 | require NetSNMP::OID; | 16 | require NetSNMP::OID; |
@@ -76,49 +77,36 @@ my $res; | |||
76 | 77 | ||
77 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0"); | 78 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0"); |
78 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" ); | 79 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" ); |
79 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | 80 | like($res->output, '/.*Cisco Internetwork Operating System Software.*/m', "String contains all lines"); |
80 | like($res->output, '/'.quotemeta('SNMP OK - Cisco Internetwork Operating System Software | | ||
81 | .1.3.6.1.4.1.8072.3.2.67.0: | ||
82 | "Cisco Internetwork Operating System Software | ||
83 | IOS (tm) Catalyst 4000 \"L3\" Switch Software (cat4000-I9K91S-M), Version | ||
84 | 12.2(20)EWA, RELEASE SOFTWARE (fc1) | ||
85 | Technical Support: http://www.cisco.com/techsupport | ||
86 | Copyright (c) 1986-2004 by cisco Systems, Inc. | ||
87 | "').'/m', "String contains all lines"); | ||
88 | 81 | ||
89 | # sysContact.0 is "Alice" (from our snmpd.conf) | 82 | # sysContact.0 is "Alice" (from our snmpd.conf) |
90 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0 -o sysContact.0 -o .1.3.6.1.4.1.8072.3.2.67.1"); | 83 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0 -o sysContact.0 -o .1.3.6.1.4.1.8072.3.2.67.1"); |
91 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); | 84 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); |
92 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | 85 | # like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); |
93 | like($res->output, '/'.quotemeta('SNMP OK - Cisco Internetwork Operating System Software ').'"?Alice"?'.quotemeta(' Kisco Outernetwork Oserating Gystem Totware | | 86 | like($res->output, '/.*Cisco Internetwork Operating System Software.*/m', "String contains all lines with multiple OIDs"); |
94 | .1.3.6.1.4.1.8072.3.2.67.0: | 87 | like($res->output, '/.*Alice.*/m', "String contains all lines with multiple OIDs"); |
95 | "Cisco Internetwork Operating System Software | 88 | like($res->output, '/.*Kisco Outernetwork Oserating Gystem Totware.*/m', "String contains all lines with multiple OIDs"); |
96 | IOS (tm) Catalyst 4000 \"L3\" Switch Software (cat4000-I9K91S-M), Version | ||
97 | 12.2(20)EWA, RELEASE SOFTWARE (fc1) | ||
98 | Technical Support: http://www.cisco.com/techsupport | ||
99 | Copyright (c) 1986-2004 by cisco Systems, Inc. | ||
100 | " | ||
101 | .1.3.6.1.4.1.8072.3.2.67.1: | ||
102 | "Kisco Outernetwork Oserating Gystem Totware | ||
103 | Copyleft (c) 2400-2689 by kisco Systrems, Inc."').'/m', "String contains all lines with multiple OIDs"); | ||
104 | 89 | ||
105 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.2"); | 90 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.2"); |
106 | like($res->output, '/'.quotemeta('SNMP OK - This should not confuse check_snmp \"parser\" | | 91 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); |
107 | .1.3.6.1.4.1.8072.3.2.67.2: | 92 | # like($res->output, '/'.quotemeta('This should not confuse check_snmp \"parser\" | |
108 | "This should not confuse check_snmp \"parser\" | 93 | # .1.3.6.1.4.1.8072.3.2.67.2: |
109 | into thinking there is no 2nd line"').'/m', "Attempt to confuse parser No.1"); | 94 | # "This should not confuse check_snmp \"parser\" |
95 | # into thinking there is no 2nd line"').'/m', "Attempt to confuse parser No.1"); | ||
110 | 96 | ||
111 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.3"); | 97 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.3"); |
112 | like($res->output, '/'.quotemeta('SNMP OK - It\'s getting even harder if the line | | 98 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); |
113 | .1.3.6.1.4.1.8072.3.2.67.3: | 99 | # like($res->output, '/'.quotemeta('It\'s getting even harder if the line | |
114 | "It\'s getting even harder if the line | 100 | # .1.3.6.1.4.1.8072.3.2.67.3: |
115 | ends with with this: C:\\\\"').'/m', "Attempt to confuse parser No.2"); | 101 | # "It\'s getting even harder if the line |
102 | # ends with with this: C:\\\\"').'/m', "Attempt to confuse parser No.2"); | ||
116 | 103 | ||
117 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.4"); | 104 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.4"); |
118 | like($res->output, '/'.quotemeta('SNMP OK - And now have fun with with this: \"C:\\\\\" | | 105 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); |
119 | .1.3.6.1.4.1.8072.3.2.67.4: | 106 | # like($res->output, '/'.quotemeta('And now have fun with with this: \"C:\\\\\" | |
120 | "And now have fun with with this: \"C:\\\\\" | 107 | # .1.3.6.1.4.1.8072.3.2.67.4: |
121 | because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); | 108 | # "And now have fun with with this: \"C:\\\\\" |
109 | # because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); | ||
122 | 110 | ||
123 | system("rm -f ".$ENV{'MP_STATE_PATH'}."/*/check_snmp/*"); | 111 | system("rm -f ".$ENV{'MP_STATE_PATH'}."/*/check_snmp/*"); |
124 | 112 | ||
@@ -131,156 +119,159 @@ SKIP: { | |||
131 | my $ts = time(); | 119 | my $ts = time(); |
132 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | 120 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); |
133 | is($res->return_code, 0, "Returns OK"); | 121 | is($res->return_code, 0, "Returns OK"); |
134 | is($res->output, "No previous data to calculate rate - assume okay"); | 122 | like($res->output, "/.*No previous data to calculate rate - assume okay.*/"); |
135 | 123 | ||
136 | # test rate 1 second later | 124 | # test rate 1 second later |
137 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | 125 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); |
138 | is($res->return_code, 1, "WARNING - due to going above rate calculation" ); | 126 | is($res->return_code, 1, "WARNING - due to going above rate calculation" ); |
139 | is($res->output, "SNMP RATE WARNING - *666* | iso.3.6.1.4.1.8072.3.2.67.10=666;600 "); | 127 | like($res->output, "/.*=666.*/"); |
140 | 128 | ||
141 | # test rate with same time | 129 | # test rate with same time |
142 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); | 130 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -w 600" ); |
143 | is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); | 131 | is($res->return_code, 3, "UNKNOWN - basically the divide by zero error" ); |
144 | is($res->output, "Time duration between plugin calls is invalid"); | 132 | like($res->output, "/.*Time duration between plugin calls is invalid.*/"); |
145 | 133 | ||
146 | 134 | ||
147 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | 135 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); |
148 | is($res->return_code, 0, "OK for first call" ); | 136 | is($res->return_code, 0, "OK for first call" ); |
149 | is($res->output, "No previous data to calculate rate - assume okay" ); | 137 | like($res->output, "/.*No previous data to calculate rate - assume okay.*/" ); |
150 | 138 | ||
151 | # test rate 1 second later | 139 | # test rate 1 second later |
152 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | 140 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); |
153 | is($res->return_code, 0, "OK as no thresholds" ); | 141 | is($res->return_code, 0, "OK as no thresholds" ); |
154 | is($res->output, "SNMP RATE OK - inoctets 666 | inoctets=666 ", "Check label"); | 142 | like($res->output, "/.*inoctets.*=666.*/m", "Check label"); |
155 | 143 | ||
156 | # test rate 3 seconds later | 144 | # test rate 3 seconds later |
157 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+3))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); | 145 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+3))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets" ); |
158 | is($res->return_code, 0, "OK as no thresholds" ); | 146 | is($res->return_code, 0, "OK as no thresholds" ); |
159 | is($res->output, "SNMP RATE OK - inoctets 333 | inoctets=333 ", "Check rate decreases due to longer interval"); | 147 | like($res->output, "/.*inoctets.*333.*/", "Check rate decreases due to longer interval"); |
160 | 148 | ||
161 | 149 | ||
162 | # label performance data check | 150 | # label performance data check |
163 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test" ); | 151 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test" ); |
164 | is($res->return_code, 0, "OK as no thresholds" ); | 152 | is($res->return_code, 0, "OK as no thresholds" ); |
165 | is($res->output, "SNMP OK - test 67996 | test=67996c ", "Check label"); | 153 | like($res->output, "/.*test.?=67996c/", "Check label"); |
166 | 154 | ||
167 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l \"test'test\"" ); | 155 | # following test is deactivated since it was not valid due to the guidelines (no single quote in label allowed) |
168 | is($res->return_code, 0, "OK as no thresholds" ); | 156 | # $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l \"test'test\"" ); |
169 | is($res->output, "SNMP OK - test'test 68662 | \"test'test\"=68662c ", "Check label"); | 157 | # is($res->return_code, 0, "OK as no thresholds" ); |
158 | # is($res->output, "test'test 68662 | \"test'test\"=68662c ", "Check label"); | ||
170 | 159 | ||
171 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test\"test'" ); | 160 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test\"test'" ); |
172 | is($res->return_code, 0, "OK as no thresholds" ); | 161 | is($res->return_code, 0, "OK as no thresholds" ); |
173 | is($res->output, "SNMP OK - test\"test 69328 | 'test\"test'=69328c ", "Check label"); | 162 | like($res->output, "/.*'test\"test'=68662c.*/", "Check label"); |
174 | 163 | ||
175 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test -O" ); | 164 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l test -O" ); |
176 | is($res->return_code, 0, "OK as no thresholds" ); | 165 | is($res->return_code, 0, "OK as no thresholds" ); |
177 | is($res->output, "SNMP OK - test 69994 | iso.3.6.1.4.1.8072.3.2.67.10=69994c ", "Check label"); | 166 | like($res->output, "/.*.67.10.?=69328c.*/", "Check label"); |
178 | 167 | ||
179 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10" ); | 168 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10" ); |
180 | is($res->return_code, 0, "OK as no thresholds" ); | 169 | is($res->return_code, 0, "OK as no thresholds" ); |
181 | is($res->output, "SNMP OK - 70660 | iso.3.6.1.4.1.8072.3.2.67.10=70660c ", "Check label"); | 170 | like($res->output, "/.*8072.3.2.67.10.?=69994c.*/", "Check label"); |
182 | 171 | ||
183 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test test'" ); | 172 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 -l 'test test'" ); |
184 | is($res->return_code, 0, "OK as no thresholds" ); | 173 | is($res->return_code, 0, "OK as no thresholds" ); |
185 | is($res->output, "SNMP OK - test test 71326 | 'test test'=71326c ", "Check label"); | 174 | like($res->output, "/.*'test test'=70660c/", "Check label"); |
186 | 175 | ||
187 | 176 | ||
188 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); | 177 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); |
189 | is($res->return_code, 0, "OK for first call" ); | 178 | is($res->return_code, 0, "OK for first call" ); |
190 | is($res->output, "No previous data to calculate rate - assume okay" ); | 179 | like($res->output, "/.*No previous data to calculate rate - assume okay.*/" ); |
191 | 180 | ||
192 | # test 1 second later | 181 | # test 1 second later |
193 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); | 182 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10 --rate -l inoctets_per_minute --rate-multiplier=60" ); |
194 | is($res->return_code, 0, "OK as no thresholds" ); | 183 | is($res->return_code, 0, "OK as no thresholds" ); |
195 | is($res->output, "SNMP RATE OK - inoctets_per_minute 39960 | inoctets_per_minute=39960 ", "Checking multiplier"); | 184 | like($res->output, "/.*inoctets_per_minute.*=39960/", "Checking multiplier"); |
196 | }; | 185 | }; |
197 | 186 | ||
198 | 187 | ||
199 | 188 | ||
200 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 -s '\"stringtests\"'" ); | 189 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 -s 'stringtests'" ); |
201 | is($res->return_code, 0, "OK as string matches" ); | 190 | is($res->return_code, 0, "OK as string matches" ); |
202 | is($res->output, 'SNMP OK - "stringtests" | ', "Good string match" ); | 191 | like($res->output, '/.*stringtests.*/', "Good string match" ); |
203 | 192 | ||
204 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 -s ring" ); | 193 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 -s ring" ); |
205 | is($res->return_code, 2, "CRITICAL as string doesn't match (though is a substring)" ); | 194 | is($res->return_code, 2, "CRITICAL as string doesn't match (though is a substring)" ); |
206 | is($res->output, 'SNMP CRITICAL - *"stringtests"* | ', "Failed string match" ); | 195 | like($res->output, '/.*stringtests.*/', "Failed string match" ); |
207 | 196 | ||
208 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 --invert-search -s '\"stringtests\"'" ); | 197 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 --invert-search -s 'stringtests'" ); |
209 | is($res->return_code, 2, "CRITICAL as string matches but inverted" ); | 198 | is($res->return_code, 2, "CRITICAL as string matches but inverted" ); |
210 | is($res->output, 'SNMP CRITICAL - *"stringtests"* | ', "Inverted string match" ); | 199 | like($res->output, '/.*"stringtests".*/', "Inverted string match" ); |
211 | 200 | ||
212 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 --invert-search -s ring" ); | 201 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.11 --invert-search -s ring" ); |
213 | is($res->return_code, 0, "OK as string doesn't match but inverted" ); | 202 | is($res->return_code, 0, "OK as string doesn't match but inverted" ); |
214 | is($res->output, 'SNMP OK - "stringtests" | ', "OK as inverted string no match" ); | 203 | like($res->output, '/.*"stringtests".*/', "OK as inverted string no match" ); |
215 | 204 | ||
216 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.12 -w 4:5" ); | 205 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.12 -w 4:5" ); |
217 | is($res->return_code, 1, "Numeric in string test" ); | 206 | # a string is a string and not a number |
218 | is($res->output, 'SNMP WARNING - *3.5* | iso.3.6.1.4.1.8072.3.2.67.12=3.5;4:5 ', "WARNING threshold checks for string masquerading as number" ); | 207 | is($res->return_code, 0, "Numeric in string test" ); |
208 | like($res->output, '/.*3.5.*| iso.3.6.1.4.1.8072.3.2.67.12=3.5;4:5/', "WARNING threshold checks for string masquerading as number" ); | ||
219 | 209 | ||
220 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.13" ); | 210 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.13" ); |
221 | is($res->return_code, 0, "Not really numeric test" ); | 211 | is($res->return_code, 0, "Not really numeric test" ); |
222 | is($res->output, 'SNMP OK - "87.4startswithnumberbutshouldbestring" | ', "Check string with numeric start is still string" ); | 212 | like($res->output, '/.*"87.4startswithnumberbutshouldbestring".*/', "Check string with numeric start is still string" ); |
223 | 213 | ||
224 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.14" ); | 214 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.14" ); |
225 | is($res->return_code, 0, "Not really numeric test (trying best to fool it)" ); | 215 | is($res->return_code, 0, "Not really numeric test (trying best to fool it)" ); |
226 | is($res->output, 'SNMP OK - "555\"I said\"" | ', "Check string with a double quote following is still a string (looks like the perl routine will always escape though)" ); | 216 | like($res->output, '/.*\'555"I said"\'.*/', "Check string with a double quote following is still a string (looks like the perl routine will always escape though)" ); |
227 | 217 | ||
228 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.15 -r 'CUSTOM CHECK OK'" ); | 218 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.15 -r 'CUSTOM CHECK OK'" ); |
229 | is($res->return_code, 0, "String check should check whole string, not a parsed number" ); | 219 | is($res->return_code, 0, "String check should check whole string, not a parsed number" ); |
230 | is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check with numbers returns whole string"); | 220 | like($res->output, '/.*CUSTOM CHECK OK: foo is 12345.*/', "String check with numbers returns whole string"); |
231 | 221 | ||
232 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); | 222 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); |
233 | is($res->return_code, 0, "Negative integer check OK" ); | 223 | is($res->return_code, 0, "Negative integer check OK" ); |
234 | is($res->output, 'SNMP OK - -2 | iso.3.6.1.4.1.8072.3.2.67.16=-2;-2:;-3: ', "Negative integer check OK output" ); | 224 | like($res->output, '/.*-2.*| iso.3.6.1.4.1.8072.3.2.67.16=-2;-2:;-3:/', "Negative integer check OK output" ); |
235 | 225 | ||
236 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); | 226 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); |
237 | is($res->return_code, 1, "Negative integer check WARNING" ); | 227 | is($res->return_code, 1, "Negative integer check WARNING" ); |
238 | is($res->output, 'SNMP WARNING - *-3* | iso.3.6.1.4.1.8072.3.2.67.16=-3;-2:;-3: ', "Negative integer check WARNING output" ); | 228 | like($res->output, '/.*-3.*| iso.3.6.1.4.1.8072.3.2.67.16=-3;-2:;-3:/', "Negative integer check WARNING output" ); |
239 | 229 | ||
240 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); | 230 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" ); |
241 | is($res->return_code, 2, "Negative integer check CRITICAL" ); | 231 | is($res->return_code, 2, "Negative integer check CRITICAL" ); |
242 | is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.16=-4;-2:;-3: ', "Negative integer check CRITICAL output" ); | 232 | like($res->output, '/.*-4.*| iso.3.6.1.4.1.8072.3.2.67.16=-4;-2:;-3:/', "Negative integer check CRITICAL output" ); |
243 | 233 | ||
244 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -3: -c -6:" ); | 234 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -3: -c -6:" ); |
245 | is($res->return_code, 1, "Negative integer as string, WARNING" ); | 235 | is($res->return_code, 1, "Negative integer as string, WARNING" ); |
246 | is($res->output, 'SNMP WARNING - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-3:;-6: ', "Negative integer as string, WARNING output" ); | 236 | like($res->output, '/.*-4.*| iso.3.6.1.4.1.8072.3.2.67.17=-4;-3:;-6:/', "Negative integer as string, WARNING output" ); |
247 | 237 | ||
248 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -2: -c -3:" ); | 238 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.17 -w -2: -c -3:" ); |
249 | is($res->return_code, 2, "Negative integer as string, CRITICAL" ); | 239 | is($res->return_code, 2, "Negative integer as string, CRITICAL" ); |
250 | is($res->output, 'SNMP CRITICAL - *-4* | iso.3.6.1.4.1.8072.3.2.67.17=-4;-2:;-3: ', "Negative integer as string, CRITICAL output" ); | 240 | like($res->output, '/.*-4.*| iso.3.6.1.4.1.8072.3.2.67.17=-4;-2:;-3:/', "Negative integer as string, CRITICAL output" ); |
251 | 241 | ||
252 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c '~:-6.5'" ); | 242 | # deactivated since the perl agent api of snmpd really does not allow floats |
253 | is($res->return_code, 0, "Negative float OK" ); | 243 | # $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -c '~:-6.5'" ); |
254 | is($res->output, 'SNMP OK - -6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;@-6.5:~ ', "Negative float OK output" ); | 244 | # is($res->return_code, 0, "Negative float OK" ); |
245 | # is($res->output, '-6.6 | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;;@-6.5:~ ', "Negative float OK output" ); | ||
255 | 246 | ||
256 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w '~:-6.65' -c '~:-6.55'" ); | 247 | # $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.18 -w '~:-6.65' -c '~:-6.55'" ); |
257 | is($res->return_code, 1, "Negative float WARNING" ); | 248 | # is($res->return_code, 1, "Negative float WARNING" ); |
258 | is($res->output, 'SNMP WARNING - *-6.6* | iso.3.6.1.4.1.8072.3.2.67.18=-6.6;@-6.65:~;@-6.55:~ ', "Negative float WARNING output" ); | 249 | # like($res->output, '/-6.6.*| .*67.18=-6.6;@-6.65:~;@-6.55:~/', "Negative float WARNING output" ); |
259 | 250 | ||
260 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-10:20' -c '2:200000,-20:30'" ); | 251 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-10:20' -c '2:200000,-20:30'" ); |
261 | is($res->return_code, 0, "Multiple OIDs with thresholds" ); | 252 | is($res->return_code, 0, "Multiple OIDs with thresholds" ); |
262 | like($res->output, '/SNMP OK - \d+ -4 | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); | 253 | like($res->output, '/-4.*| .*67.10=\d+c;1:100000;2:200000 .*67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); |
263 | 254 | ||
264 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-1:2' -c '2:200000,-20:30'" ); | 255 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w '1:100000,-1:2' -c '2:200000,-20:30'" ); |
265 | is($res->return_code, 1, "Multiple OIDs with thresholds" ); | 256 | is($res->return_code, 1, "Multiple OIDs with thresholds" ); |
266 | like($res->output, '/SNMP WARNING - \d+ \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); | 257 | like($res->output, '/-4.*| iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1:100000;2:200000 iso.3.6.1.4.1.8072.3.2.67.17=-4;-10:20;-20:30/', "Multiple OIDs with thresholds output" ); |
267 | 258 | ||
268 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w 1,2 -c 1" ); | 259 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.10,.1.3.6.1.4.1.8072.3.2.67.17 -w 1,2 -c 1 -O" ); |
269 | is($res->return_code, 2, "Multiple OIDs with some thresholds" ); | 260 | is($res->return_code, 2, "Multiple OIDs with some thresholds" ); |
270 | like($res->output, '/SNMP CRITICAL - \*\d+\* \*-4\* | iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1;2 iso.3.6.1.4.1.8072.3.2.67.17=-4;;/', "Multiple OIDs with thresholds output" ); | 261 | like($res->output, '/.*-4.*| iso.3.6.1.4.1.8072.3.2.67.10=\d+c;1;2 iso.3.6.1.4.1.8072.3.2.67.17=-4;;/', "Multiple OIDs with thresholds output" ); |
271 | 262 | ||
272 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19"); | 263 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19"); |
273 | is($res->return_code, 0, "Test plain .1.3.6.1.4.1.8072.3.2.67.6 RC" ); | 264 | is($res->return_code, 0, "Test plain .1.3.6.1.4.1.8072.3.2.67.6 RC" ); |
274 | is($res->output,'SNMP OK - 42 | iso.3.6.1.4.1.8072.3.2.67.19=42 ', "Test plain value of .1.3.6.1.4.1.8072.3.2.67.1" ); | 265 | like($res->output,'/.*42.*| iso.3.6.1.4.1.8072.3.2.67.19=42/', "Test plain value of .1.3.6.1.4.1.8072.3.2.67.1" ); |
275 | 266 | ||
276 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 -M .1"); | 267 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 -M .1"); |
277 | is($res->return_code, 0, "Test multiply RC" ); | 268 | is($res->return_code, 0, "Test multiply RC" ); |
278 | is($res->output,'SNMP OK - 4.200000 | iso.3.6.1.4.1.8072.3.2.67.19=4.200000 ' , "Test multiply .1 output" ); | 269 | like($res->output,'/.*4.200000.*| iso.3.6.1.4.1.8072.3.2.67.19=4.200000/' , "Test multiply .1 output" ); |
279 | 270 | ||
280 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1 -f '%.2f' "); | 271 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1"); |
281 | is($res->return_code, 0, "Test multiply RC + format" ); | 272 | is($res->return_code, 0, "Test multiply RC" ); |
282 | is($res->output, 'SNMP OK - 4.20 | iso.3.6.1.4.1.8072.3.2.67.19=4.20 ', "Test multiply .1 output + format" ); | 273 | like($res->output, '/.*4.20.*| iso.3.6.1.4.1.8072.3.2.67.19=4.20/', "Test multiply .1 output" ); |
283 | 274 | ||
284 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1 -f '%.2f' -w 1"); | 275 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.19 --multiplier=.1 -w 1"); |
285 | is($res->return_code, 1, "Test multiply RC + format + thresholds" ); | 276 | is($res->return_code, 1, "Test multiply RC + thresholds" ); |
286 | is($res->output, 'SNMP WARNING - *4.20* | iso.3.6.1.4.1.8072.3.2.67.19=4.20;1 ', "Test multiply .1 output + format + thresholds" ); | 277 | like($res->output, '/.*4.20.* | iso.3.6.1.4.1.8072.3.2.67.19=4.20+;1/', "Test multiply .1 output + thresholds" ); |