[nagiosplug] Make check_snmp backwards compatible in how it ...

Nagios Plugin Development nagios-plugins at users.sourceforge.net
Sat Nov 3 03:30:23 CET 2012


    Module: nagiosplug
    Branch: master
    Commit: bd782990566eec91b8312cfc2765a7e2bd9e67da
    Author: Andreas Ericsson <ae at op5.se>
 Committer: Thomas Guyot-Sionnest <dermoth at aei.ca>
      Date: Fri Nov  2 14:44:16 2012 +0100
       URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=bd78299

Make check_snmp backwards compatible in how it parses thresholds

Once upon a time, check_snmp used to accept inverse ranges in the
format of '2:1' to mean "alert if value is inside this range".

Since commit 7cb3ae09334796f3b54e4e6438e38c2cc679b360, ranges such
as those have instead triggered the error "Range format incorrect"
and resulted in an UNKNOWN warning state. This patch attempts to
fix the situation so that the old-style ranges continues to mean
exactly what the once did and people with lots of snmp checks can
avoid a bazillion false positives from their environments.

Signed-off-by: Andreas Ericsson <ae at op5.se>

---

 plugins/check_snmp.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 2d9861b..0ddfb94 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -144,6 +144,25 @@ double previous_value[MAX_OIDS];
 int perf_labels = 1;
 
 
+static char *fix_snmp_range(char *th)
+{
+	double left, right;
+	char *colon, *ret;
+	if (!(colon = strchr(th, ':')))
+		return th;
+	*colon = 0;
+
+	left = strtod(th, NULL);
+	right = strtod(colon + 1, NULL);
+	if (right >= left) {
+		return th;
+	}
+	ret = malloc(strlen(th) + strlen(colon + 1) + 2);
+	sprintf(ret, "@%s:%s", colon + 1, th);
+	free(th);
+	return ret;
+}
+
 int
 main (int argc, char **argv)
 {
@@ -228,6 +247,10 @@ main (int argc, char **argv)
 	for (i=0; i<numoids; i++) {
 		char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL;
 		char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL;
+		/* translate "2:1" to "@1:2" for backwards compatibility */
+		w = w ? fix_snmp_range(w) : NULL;
+		c = c ? fix_snmp_range(c) : NULL;
+
 		/* Skip empty thresholds, while avoiding segfault */
 		set_thresholds(&thlds[i],
 		               w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL,





More information about the Commits mailing list