summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2010-12-01 02:02:23 (GMT)
committerThomas Guyot-Sionnest <dermoth@aei.ca>2010-12-01 03:32:33 (GMT)
commitdf88f95fcaf65d58a9ea172c2b3e2b96d80dff33 (patch)
tree2ee4154b2f7e96cac96c8bfbc4e3fff5116095fa
parent9faccbb26106fc6f134c783c91d1871af581af02 (diff)
downloadmonitoring-plugins-df88f95fcaf65d58a9ea172c2b3e2b96d80dff33.tar.gz
check_snmp: Remove that is_numeric madness
Original patch to make Timeticks works as in check_snmp v1.4.14, it turns out is_numeric isn't so useful and treating all types as numeric works best for backwards-compatibility. This is how it used to work in 1.4.14. As a special case, I also make calculate_rate look up for numeric values as it would otherwise return the last value instead.
-rw-r--r--NEWS3
-rw-r--r--plugins/check_snmp.c12
-rw-r--r--plugins/t/check_snmp.t9
3 files changed, 15 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index cf4b404..fb130ce 100644
--- a/NEWS
+++ b/NEWS
@@ -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
151.4.15 27th July 2010 181.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 9d91942..cb7fb7a 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 004ba1a..25a2999 100644
--- a/plugins/t/check_snmp.t
+++ b/plugins/t/check_snmp.t
@@ -8,7 +8,7 @@ use strict;
8use Test::More; 8use Test::More;
9use NPTest; 9use NPTest;
10 10
11my $tests = 8+38+2+2; 11my $tests = 8+42+2+2;
12plan tests => $tests; 12plan tests => $tests;
13my $res; 13my $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