handle each snmp value type individually; copy Buffers returned; #2362
Costa Tsaousis (ktsaou) committed
Aug 26, 2017 at 02:44 UTC
6d35680bb99d8616c198d650c27e44aa7352a572
1 file changed
+30
-7
node.d/snmp.node.js
+30
-7
@@ -269,13 +269,36 @@ netdata.processors.snmp = {
269
failed++;
270
}
271
else {
272
- if(__DEBUG === true)
273
- netdata.debug(service.module.name + ': ' + service.name + ': found ' + service.module.name + ' value of OIDs ' + varbinds[i].oid + ", ObjectType " + net_snmp.ObjectType[varbinds[i].type] + " (" + netdata.stringify(varbinds[i].type) + "), typeof(" + typeof(varbinds[i].value) + "), in JSON: " + netdata.stringify(varbinds[i].value) + ", value = '" + varbinds[i].value.toString() + "'");
274
-
275
- if(varbinds[i].type === net_snmp.ObjectType.OctetString && service.snmp_oids_index[varbinds[i].oid].type !== 'title')
276
- value = parseFloat(varbinds[i].value) * 1000;
277
- else
278
- value = varbinds[i].value;
272
+ // test fom Counter64
273
+ // varbinds[i].type = net_snmp.ObjectType.Counter64;
274
+ // varbinds[i].value = new Buffer([0x34, 0x49, 0x2e, 0xdc, 0xd1]);
275
+
276
+ switch(varbinds[i].type) {
277
+ case net_snmp.ObjectType.OctetString:
278
+ if(service.snmp_oids_index[varbinds[i].oid].type !== 'title')
279
+ // parse floating point values, exposed as strings
280
+ value = parseFloat(varbinds[i].value) * 1000;
281
+ if(__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': found ' + service.module.name + ' value of OIDs ' + varbinds[i].oid + ", ObjectType " + net_snmp.ObjectType[varbinds[i].type] + " (" + netdata.stringify(varbinds[i].type) + "), typeof(" + typeof(varbinds[i].value) + "), in JSON: " + netdata.stringify(varbinds[i].value) + ", value = '" + varbinds[i].value.toString() + "' (parsed as float in string)");
282
+ else
283
+ // just use the string
284
+ value = varbinds[i].value;
285
+ if(__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': found ' + service.module.name + ' value of OIDs ' + varbinds[i].oid + ", ObjectType " + net_snmp.ObjectType[varbinds[i].type] + " (" + netdata.stringify(varbinds[i].type) + "), typeof(" + typeof(varbinds[i].value) + "), in JSON: " + netdata.stringify(varbinds[i].value) + ", value = '" + varbinds[i].value.toString() + "' (parsed as string)");
286
+ break;
287
+
288
+ case net_snmp.ObjectType.Counter64:
289
+ // copy the buffer
290
+ value = new Buffer.from(varbinds[i].value);
291
+ if(__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': found ' + service.module.name + ' value of OIDs ' + varbinds[i].oid + ", ObjectType " + net_snmp.ObjectType[varbinds[i].type] + " (" + netdata.stringify(varbinds[i].type) + "), typeof(" + typeof(varbinds[i].value) + "), in JSON: " + netdata.stringify(varbinds[i].value) + ", value = '0x" + varbinds[i].value.toString('hex') + "' (parsed as buffer)");
292
+ break;
293
+
294
+ case net_snmp.ObjectType.Integer:
295
+ case net_snmp.ObjectType.Counter:
296
+ case net_snmp.ObjectType.Gauge:
297
+ default:
298
+ value = varbinds[i].value;
299
+ if(__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': found ' + service.module.name + ' value of OIDs ' + varbinds[i].oid + ", ObjectType " + net_snmp.ObjectType[varbinds[i].type] + " (" + netdata.stringify(varbinds[i].type) + "), typeof(" + typeof(varbinds[i].value) + "), in JSON: " + netdata.stringify(varbinds[i].value) + ", value = '" + varbinds[i].value.toString() + "' (parsed as number)");
300
+ break;
301
+ }
302
303
ok++;
304
}