summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2010-03-30 22:31:20 -0400
committerThomas Guyot-Sionnest <dermoth@aei.ca>2010-03-30 22:31:20 -0400
commit120985853e71d6f20d598d1968f0df9db5163957 (patch)
tree32a7d29fd68cea965b1df25ae261d6a204ff169a
parent08d8d119411fc875de56fac645b17152425eee46 (diff)
downloadmonitoring-plugins-120985853e71d6f20d598d1968f0df9db5163957.tar.gz
check_snmp: Fix regression introduced in #1867716
Bug #1867716 fixed what it meant to fix: broken perfdata strings. Unfortunately some users relied on half-broken perfdata string where at least the first token was OK. This patch do a two-way conversion (string to double then back to string) instead and use the conversion result for the performance data. A possible caveat is that the string may change where it normally shouldn't but the result should be somewhat similar.
-rw-r--r--NEWS1
-rw-r--r--plugins/check_snmp.c12
2 files changed, 11 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 58768d39..e261abfd 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ This file documents the major additions and syntax changes between releases.
11 Try to detect arguments passed via --with-ping[6]-command and set options accordingly (#2908236) 11 Try to detect arguments passed via --with-ping[6]-command and set options accordingly (#2908236)
12 Fix memory leak in check_http for large pages (Jimmy Bergman - #2957455) 12 Fix memory leak in check_http for large pages (Jimmy Bergman - #2957455)
13 Fix compilation with GCC 2.96 (Konstantin Khomoutov - #2977105) 13 Fix compilation with GCC 2.96 (Konstantin Khomoutov - #2977105)
14 Fix regression introduced in #1867716 where partially valid performance strings would not be printed anymore
14 WARNINGS 15 WARNINGS
15 Updated developer documentation to say that performance labels should not have an equals sign or 16 Updated developer documentation to say that performance labels should not have an equals sign or
16 single quote in the label 17 single quote in the label
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index dcb31386..ce3919d1 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -122,6 +122,7 @@ main (int argc, char **argv)
122 int result = STATE_UNKNOWN; 122 int result = STATE_UNKNOWN;
123 int return_code = 0; 123 int return_code = 0;
124 int external_error = 0; 124 int external_error = 0;
125 double perftmp;
125 char **command_line = NULL; 126 char **command_line = NULL;
126 char *cl_hidden_auth = NULL; 127 char *cl_hidden_auth = NULL;
127 char *oidname = NULL; 128 char *oidname = NULL;
@@ -351,10 +352,17 @@ main (int argc, char **argv)
351 if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL) 352 if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
352 asprintf (&outbuff, "%s %s", outbuff, unitv[i]); 353 asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
353 354
354 if (is_numeric(show)) { 355 /* Try a two-way conversion of show and add perfdata only if we get
356 * something back at the end */
357 ptr = NULL;
358 perftmp = strtod(show, &ptr);
359 if (ptr != show) {
360 ptr = NULL;
361 asprintf(&ptr, "%0.9g", perftmp);
355 strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1); 362 strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1);
356 strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1); 363 strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
357 strncat(perfstr, show, sizeof(perfstr)-strlen(perfstr)-1); 364 strncat(perfstr, ptr, sizeof(perfstr)-strlen(perfstr)-1);
365 free(ptr);
358 366
359 if (type) 367 if (type)
360 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); 368 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);