Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#548 check_snmp threshold breaks with negative values

open
nobody
None
5
2012-07-31
2012-07-31
Cálestyo
No

Hi.

This is from the old / soon to be disabled again Nagios Plugins bug tracker that used to be at Nagios itself.
I've just copied this bug over. I'm not the original reporter and have no idea about the thoughts about this bug.

This used to be: http://tracker.nagios.org/view.php?id=265
--------------------------------------------------------------------------------
candlerb:
--------------------------------------------------------------------------------
The INTEGER type in SNMP is a signed 32-bit value. However check_snmp breaks with negative values.

(1) The negative sign is dropped as soon as you apply -w or -c command line flags.

# /usr/lib/nagios/plugins/check_snmp -vvv -H 192.168.5.119 -C public -o .1.3.6.1.2.1.25.2.3.1.5.2
/usr/bin/snmpget -t 1 -r 5 -m '' -v 1 [authpriv] 192.168.5.119:161 .1.3.6.1.2.1.25.2.3.1.5.2
iso.3.6.1.2.1.25.2.3.1.5.2 = INTEGER: -632823937
Processing line 1
oidname: iso.3.6.1.2.1.25.2.3.1.5.2
response: = INTEGER: -632823937
SNMP OK - -632823937 | iso.3.6.1.2.1.25.2.3.1.5.2=-632823937

# /usr/lib/nagios/plugins/check_snmp -vvv -H 192.168.5.119 -C public -o .1.3.6.1.2.1.25.2.3.1.5.2 -w 0
/usr/bin/snmpget -t 1 -r 5 -m '' -v 1 [authpriv] 192.168.5.119:161 .1.3.6.1.2.1.25.2.3.1.5.2
iso.3.6.1.2.1.25.2.3.1.5.2 = INTEGER: -632823937
Processing line 1
oidname: iso.3.6.1.2.1.25.2.3.1.5.2
response: = INTEGER: -632823937
SNMP WARNING - *632823937* | iso.3.6.1.2.1.25.2.3.1.5.2=632823937 <<< NOTE!

(2) Any threshold with a negative value is rejected as invalid

# /usr/lib/nagios/plugins/check_snmp -vvv -H 192.168.5.119 -C public -o .1.3.6.1.2.1.25.2.3.1.5.2 -w -5:-3
Range format incorrect

I am guessing problem (1) could be fixed like this:

--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -401,7 +401,7 @@ main (int argc, char **argv)
/* Process this block for numeric comparisons */
/* Make some special values,like Timeticks numeric only if a thr
if (thlds[i]->warning || thlds[i]->critical || calculate_rate) {
- ptr = strpbrk (show, "0123456789");
+ ptr = strpbrk (show, "-0123456789");
if (ptr == NULL)
die (STATE_UNKNOWN,_("No valid data returned"));
response_value[i] = strtod (ptr, NULL);

and that problem (2) could be fixed like this:

--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -62,7 +62,7 @@ int check_range(double, range *);
int get_status(double, thresholds *);

/* All possible characters in a threshold range */
-#define NP_THRESHOLDS_CHARS "0123456789.:@~"
+#define NP_THRESHOLDS_CHARS "-0123456789.:@~"

char *np_escaped_string (const char *);

--------------------------------------------------------------------------------
candlerb:
--------------------------------------------------------------------------------
I have rebuild check_snmp from source, and those two one-line changes do appear to fix the problem.

Discussion