]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Allow non-DS_COUNTER values for Count option 3504/head
authorEdgar Fuß <ef@math.uni-bonn.de>
Tue, 14 Jul 2020 16:51:02 +0000 (18:51 +0200)
committerGitHub <noreply@github.com>
Tue, 14 Jul 2020 16:51:02 +0000 (18:51 +0200)
Allow the value to be of an type other than DS_COUNTER when using the Count option.
I'm sure this can be done more elgantly.

src/snmp.c

index 16fd143dfad937c3416c2e4dad5acaeb7fa6437a..17e4b4cf49b1a981259e742aa7e805d9e13d38e5 100644 (file)
@@ -1568,6 +1568,8 @@ static int csnmp_dispatch_table(host_definition_t *host,
   } /* while (have_more) */
 
   if (count_values) {
+    /* the first `ds' means `data set', the second means `data source' */
+    int type = ds->ds[0].type;
     sstrncpy(vl.host, host->name, sizeof(vl.host));
     sstrncpy(vl.plugin, data->plugin_name, sizeof(vl.plugin));
     sstrncpy(vl.type, data->type, sizeof(vl.type));
@@ -1581,7 +1583,24 @@ static int csnmp_dispatch_table(host_definition_t *host,
     vl.values = malloc(sizeof(*vl.values));
     if (vl.values == NULL)
       return -1;
-    vl.values[0].counter = count;
+    switch (type) {
+    case DS_TYPE_COUNTER:
+      vl.values[0].counter = count;
+      break;
+    case DS_TYPE_GAUGE:
+      vl.values[0].gauge = count;
+      break;
+    case DS_TYPE_DERIVE:
+      vl.values[0].derive = count;
+      break;
+    case DS_TYPE_ABSOLUTE:
+      vl.values[0].absolute = count;
+      break;
+    default:
+      ERROR("snmp plugin: csnmp_dispatch_table: Unknown "
+            "data source type: %i.",
+            type);
+    }
     plugin_dispatch_values(&vl);
     sfree(vl.values);
   }
@@ -1655,13 +1674,6 @@ static int csnmp_read_table(host_definition_t *host, data_definition_t *data) {
             data->type, ds->ds_num);
       return -1;
     }
-    /* the first `ds' means `data set', the second means `data source' */
-    if (ds->ds->type != DS_TYPE_COUNTER) {
-      ERROR("snmp plugin: DataSet `%s' needs to be of COUNTER"
-            " type for `Count' option",
-            data->type);
-      return -1;
-    }
   } else {
     if (ds->ds_num != data->values_len) {
       ERROR("snmp plugin: DataSet `%s' requires %" PRIsz