summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_snmp.c23
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];
144int perf_labels = 1; 144int perf_labels = 1;
145 145
146 146
147static char *fix_snmp_range(char *th)
148{
149 double left, right;
150 char *colon, *ret;
151 if (!(colon = strchr(th, ':')))
152 return th;
153 *colon = 0;
154
155 left = strtod(th, NULL);
156 right = strtod(colon + 1, NULL);
157 if (right >= left) {
158 return th;
159 }
160 ret = malloc(strlen(th) + strlen(colon + 1) + 2);
161 sprintf(ret, "@%s:%s", colon + 1, th);
162 free(th);
163 return ret;
164}
165
147int 166int
148main (int argc, char **argv) 167main (int argc, char **argv)
149{ 168{
@@ -228,6 +247,10 @@ main (int argc, char **argv)
228 for (i=0; i<numoids; i++) { 247 for (i=0; i<numoids; i++) {
229 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; 248 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL;
230 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; 249 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL;
250 /* translate "2:1" to "@1:2" for backwards compatibility */
251 w = w ? fix_snmp_range(w) : NULL;
252 c = c ? fix_snmp_range(c) : NULL;
253
231 /* Skip empty thresholds, while avoiding segfault */ 254 /* Skip empty thresholds, while avoiding segfault */
232 set_thresholds(&thlds[i], 255 set_thresholds(&thlds[i],
233 w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL, 256 w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL,