summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 654783a)
raw | patch | inline | side by side (parent: 654783a)
author | Florian Forster <octo@noris.net> | |
Mon, 14 Jul 2008 09:49:06 +0000 (11:49 +0200) | ||
committer | Florian Forster <octo@noris.net> | |
Mon, 14 Jul 2008 09:49:06 +0000 (11:49 +0200) |
Some broken SNMP implementations returns numbers as a string, e. g. a
temperature could would be returned as "19.2 C". This change uses the
data source type, i. e. `counter' or `gauge' to convert that string into
an integer or a floating point number using strtoll or strtod. In case
of an error (string-pointer is NULL or no conversion could take place)
either zero or NAN is returned.
temperature could would be returned as "19.2 C". This change uses the
data source type, i. e. `counter' or `gauge' to convert that string into
an integer or a floating point number using strtoll or strtod. In case
of an error (string-pointer is NULL or no conversion could take place)
either zero or NAN is returned.
src/snmp.c | patch | blob | history |
diff --git a/src/snmp.c b/src/snmp.c
index d19493df9a53d5e4aefee9190cdc36cc6396afb3..05612576837dcbb1f8be3801af197adebd86694f 100644 (file)
--- a/src/snmp.c
+++ b/src/snmp.c
temp += (uint32_t) vl->val.counter64->low;
DEBUG ("snmp plugin: Parsed int64 value is %llu.", temp);
}
+ else if (vl->type == ASN_OCTET_STR)
+ {
+ /* We'll handle this later.. */
+ }
else
{
WARNING ("snmp plugin: I don't know the ASN type `%i'", (int) vl->type);
defined = 0;
}
- if (type == DS_TYPE_COUNTER)
+ if (vl->type == ASN_OCTET_STR)
+ {
+ char *string;
+ char *endptr;
+
+ string = (char *) vl->val.string;
+ endptr = NULL;
+
+ if (string != NULL)
+ {
+ if (type == DS_TYPE_COUNTER)
+ ret.counter = (counter_t) strtoll (string, &endptr, /* base = */ 0);
+ else if (type == DS_TYPE_GAUGE)
+ ret.gauge = (gauge_t) strtod (string, &endptr);
+ }
+
+ /* Check if an error occurred */
+ if ((string == NULL) || (endptr == string))
+ {
+ if (type == DS_TYPE_COUNTER)
+ ret.counter = 0;
+ else if (type == DS_TYPE_GAUGE)
+ ret.gauge = NAN;
+ }
+ }
+ else if (type == DS_TYPE_COUNTER)
{
ret.counter = temp;
}