Merge branch 'collectd-4.4'
[collectd.git] / src / snmp.c
index d19493d..07465dd 100644 (file)
@@ -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;
   }
@@ -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 %lu seconds.",
-       host->name, host->interval, (unsigned long)(time_end - time_start));
+       "but reading all values takes %u seconds.",
+       host->name, host->interval, (unsigned int) (time_end - time_start));
   }
 
   return (0);