diff options
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | plugins/check_snmp.c | 12 | ||||
-rw-r--r-- | plugins/t/check_snmp.t | 9 |
3 files changed, 15 insertions, 9 deletions
@@ -12,6 +12,9 @@ This file documents the major additions and syntax changes between releases. | |||
12 | Fix check_disk free space calculation if blocksizes differ within a disk group (Bekar - #2973603) | 12 | Fix check_disk free space calculation if blocksizes differ within a disk group (Bekar - #2973603) |
13 | check_disk_smb now handles NT_STATUS_ACCESS_DENIED properly (Debian #601696) | 13 | check_disk_smb now handles NT_STATUS_ACCESS_DENIED properly (Debian #601696) |
14 | 14 | ||
15 | FIXES | ||
16 | Make check_snmp work more like v1.4.14 with regard to using special values (Timeticks, STRING) as numeric thresholds. | ||
17 | |||
15 | 1.4.15 27th July 2010 | 18 | 1.4.15 27th July 2010 |
16 | ENHANCEMENTS | 19 | ENHANCEMENTS |
17 | New check_ntp_peer -m and -n options to check the number of usable time sources ("truechimers") | 20 | New check_ntp_peer -m and -n options to check the number of usable time sources ("truechimers") |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 9d919422..cb7fb7a0 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -170,7 +170,6 @@ main (int argc, char **argv) | |||
170 | char *state_string=NULL; | 170 | char *state_string=NULL; |
171 | size_t response_length, current_length, string_length; | 171 | size_t response_length, current_length, string_length; |
172 | char *temp_string=NULL; | 172 | char *temp_string=NULL; |
173 | int is_numeric=0; | ||
174 | time_t current_time; | 173 | time_t current_time; |
175 | double temp_double; | 174 | double temp_double; |
176 | time_t duration; | 175 | time_t duration; |
@@ -336,29 +335,24 @@ main (int argc, char **argv) | |||
336 | /* We strip out the datatype indicator for PHBs */ | 335 | /* We strip out the datatype indicator for PHBs */ |
337 | if (strstr (response, "Gauge: ")) { | 336 | if (strstr (response, "Gauge: ")) { |
338 | show = strstr (response, "Gauge: ") + 7; | 337 | show = strstr (response, "Gauge: ") + 7; |
339 | is_numeric++; | ||
340 | } | 338 | } |
341 | else if (strstr (response, "Gauge32: ")) { | 339 | else if (strstr (response, "Gauge32: ")) { |
342 | show = strstr (response, "Gauge32: ") + 9; | 340 | show = strstr (response, "Gauge32: ") + 9; |
343 | is_numeric++; | ||
344 | } | 341 | } |
345 | else if (strstr (response, "Counter32: ")) { | 342 | else if (strstr (response, "Counter32: ")) { |
346 | show = strstr (response, "Counter32: ") + 11; | 343 | show = strstr (response, "Counter32: ") + 11; |
347 | is_numeric++; | ||
348 | is_counter=1; | 344 | is_counter=1; |
349 | if(!calculate_rate) | 345 | if(!calculate_rate) |
350 | strcpy(type, "c"); | 346 | strcpy(type, "c"); |
351 | } | 347 | } |
352 | else if (strstr (response, "Counter64: ")) { | 348 | else if (strstr (response, "Counter64: ")) { |
353 | show = strstr (response, "Counter64: ") + 11; | 349 | show = strstr (response, "Counter64: ") + 11; |
354 | is_numeric++; | ||
355 | is_counter=1; | 350 | is_counter=1; |
356 | if(!calculate_rate) | 351 | if(!calculate_rate) |
357 | strcpy(type, "c"); | 352 | strcpy(type, "c"); |
358 | } | 353 | } |
359 | else if (strstr (response, "INTEGER: ")) { | 354 | else if (strstr (response, "INTEGER: ")) { |
360 | show = strstr (response, "INTEGER: ") + 9; | 355 | show = strstr (response, "INTEGER: ") + 9; |
361 | is_numeric++; | ||
362 | } | 356 | } |
363 | else if (strstr (response, "STRING: ")) { | 357 | else if (strstr (response, "STRING: ")) { |
364 | show = strstr (response, "STRING: ") + 8; | 358 | show = strstr (response, "STRING: ") + 8; |
@@ -410,15 +404,17 @@ main (int argc, char **argv) | |||
410 | } | 404 | } |
411 | 405 | ||
412 | } | 406 | } |
413 | else if (strstr (response, "Timeticks: ")) | 407 | else if (strstr (response, "Timeticks: ")) { |
414 | show = strstr (response, "Timeticks: "); | 408 | show = strstr (response, "Timeticks: "); |
409 | } | ||
415 | else | 410 | else |
416 | show = response; | 411 | show = response; |
417 | 412 | ||
418 | iresult = STATE_DEPENDENT; | 413 | iresult = STATE_DEPENDENT; |
419 | 414 | ||
420 | /* Process this block for numeric comparisons */ | 415 | /* Process this block for numeric comparisons */ |
421 | if (is_numeric) { | 416 | /* Make some special values,like Timeticks numeric only if a threshold is defined */ |
417 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { | ||
422 | ptr = strpbrk (show, "0123456789"); | 418 | ptr = strpbrk (show, "0123456789"); |
423 | if (ptr == NULL) | 419 | if (ptr == NULL) |
424 | die (STATE_UNKNOWN,_("No valid data returned")); | 420 | die (STATE_UNKNOWN,_("No valid data returned")); |
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index 004ba1ae..25a2999d 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 = 8+38+2+2; | 11 | my $tests = 8+42+2+2; |
12 | plan tests => $tests; | 12 | plan tests => $tests; |
13 | my $res; | 13 | my $res; |
14 | 14 | ||
@@ -124,6 +124,13 @@ SKIP: { | |||
124 | cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds"); | 124 | cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds"); |
125 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed"); | 125 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed"); |
126 | 126 | ||
127 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000: -u '1/100 sec'"); | ||
128 | cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold"); | ||
129 | like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric"); | ||
130 | |||
131 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0"); | ||
132 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); | ||
133 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); | ||
127 | } | 134 | } |
128 | 135 | ||
129 | # These checks need a complete command line. An invalid community is used so | 136 | # These checks need a complete command line. An invalid community is used so |