aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_snmp.c
diff options
context:
space:
mode:
authorGravatar Thomas Guyot-Sionnest <dermoth@aei.ca> 2010-03-30 22:31:20 -0400
committerGravatar Thomas Guyot-Sionnest <dermoth@aei.ca> 2010-03-30 22:31:20 -0400
commit120985853e71d6f20d598d1968f0df9db5163957 (patch)
tree32a7d29fd68cea965b1df25ae261d6a204ff169a /plugins/check_snmp.c
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.
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r--plugins/check_snmp.c12
1 files changed, 10 insertions, 2 deletions
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)
int result = STATE_UNKNOWN;
int return_code = 0;
int external_error = 0;
+ double perftmp;
char **command_line = NULL;
char *cl_hidden_auth = NULL;
char *oidname = NULL;
@@ -351,10 +352,17 @@ main (int argc, char **argv)
if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
- if (is_numeric(show)) {
+ /* Try a two-way conversion of show and add perfdata only if we get
+ * something back at the end */
+ ptr = NULL;
+ perftmp = strtod(show, &ptr);
+ if (ptr != show) {
+ ptr = NULL;
+ asprintf(&ptr, "%0.9g", perftmp);
strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1);
strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
- strncat(perfstr, show, sizeof(perfstr)-strlen(perfstr)-1);
+ strncat(perfstr, ptr, sizeof(perfstr)-strlen(perfstr)-1);
+ free(ptr);
if (type)
strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);