From: Edgar Fuß Date: Tue, 14 Jul 2020 16:51:02 +0000 (+0200) Subject: Allow non-DS_COUNTER values for Count option X-Git-Tag: collectd-5.12.0~22^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=74e77288b057a62b9d86a87b10d394b6ed6e79d1;p=thirdparty%2Fcollectd.git Allow non-DS_COUNTER values for Count option 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. --- diff --git a/src/snmp.c b/src/snmp.c index 16fd143df..17e4b4cf4 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -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