Merge branch 'collectd-4.4'
[collectd.git] / src / snmp.c
index 6f11af0..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;
   }
@@ -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);