X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsnmp.c;h=07465ddd26d1a951addd40b0ea28f9a7cad6b409;hb=92445ff3363441d0f515de4a3ab92a504cfc0366;hp=6f11af045a7f7627b1e7feadf40e100ebb9f76aa;hpb=4e6812d3e5073e5b4bd7eaef9f2539c8c9dd28a4;p=collectd.git diff --git a/src/snmp.c b/src/snmp.c index 6f11af04..07465ddd 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -708,14 +708,18 @@ static value_t csnmp_value_list_to_value (struct variable_list *vl, int type, || (vl->type == ASN_GAUGE)) { temp = (uint32_t) *vl->val.integer; - DEBUG ("snmp plugin: Parsed int32 value is %llu.", temp); + DEBUG ("snmp plugin: Parsed int32 value is %"PRIu64".", temp); } else if (vl->type == ASN_COUNTER64) { temp = (uint32_t) vl->val.counter64->high; temp = temp << 32; temp += (uint32_t) vl->val.counter64->low; - DEBUG ("snmp plugin: Parsed int64 value is %llu.", temp); + DEBUG ("snmp plugin: Parsed int64 value is %"PRIu64".", temp); + } + else if (vl->type == ASN_OCTET_STR) + { + /* We'll handle this later.. */ } else { @@ -723,7 +727,32 @@ static value_t csnmp_value_list_to_value (struct variable_list *vl, int 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; } @@ -780,7 +809,7 @@ static int csnmp_check_res_left_subtree (const host_definition_t *host, if (vb == NULL) { ERROR ("snmp plugin: host %s: Expected one more variable for " - "the instance.."); + "the instance..", host->name); return (-1); } @@ -907,7 +936,7 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat } sstrncpy (vl.host, host->name, sizeof (vl.host)); - strcpy (vl.plugin, "snmp"); + sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin)); vl.interval = host->interval; vl.time = time (NULL); @@ -1296,7 +1325,7 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) } sstrncpy (vl.host, host->name, sizeof (vl.host)); - strcpy (vl.plugin, "snmp"); + sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin)); sstrncpy (vl.type, data->type, sizeof (vl.type)); sstrncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance)); @@ -1395,8 +1424,8 @@ static int csnmp_read_host (host_definition_t *host) if ((time_end - time_start) > host->interval) { WARNING ("snmp plugin: Host `%s' should be queried every %i seconds, " - "but reading all values takes %i seconds.", - host->name, host->interval, time_end - time_start); + "but reading all values takes %u seconds.", + host->name, host->interval, (unsigned int) (time_end - time_start)); } return (0);