diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-08-26 02:44:56 +0300 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-08-26 02:44:56 +0300 |
commit | 6d35680bb99d8616c198d650c27e44aa7352a572 (patch) | |
tree | fc54faf48a287c279bf597c5cd6b5cc68ff0f1e7 /node.d | |
parent | 26dae246062697627380867b368fa79d8e602a0f (diff) |
handle each snmp value type individually; copy Buffers returned; #2362
Diffstat (limited to 'node.d')
-rw-r--r-- | node.d/snmp.node.js | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/node.d/snmp.node.js b/node.d/snmp.node.js index 0c57aec6e2..de867ca631 100644 --- a/node.d/snmp.node.js +++ b/node.d/snmp.node.js @@ -269,13 +269,36 @@ netdata.processors.snmp = { failed++; } else { - 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() + "'"); - - if(varbinds[i].type === net_snmp.ObjectType.OctetString && service.snmp_oids_index[varbinds[i].oid].type !== 'title') - value = parseFloat(varbinds[i].value) * 1000; - else - value = varbinds[i].value; + // test fom Counter64 + // varbinds[i].type = net_snmp.ObjectType.Counter64; + // varbinds[i].value = new Buffer([0x34, 0x49, 0x2e, 0xdc, 0xd1]); + + switch(varbinds[i].type) { + case net_snmp.ObjectType.OctetString: + if(service.snmp_oids_index[varbinds[i].oid].type !== 'title') + // parse floating point values, exposed as strings + value = parseFloat(varbinds[i].value) * 1000; + 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)"); + else + // just use the string + value = varbinds[i].value; + 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)"); + break; + + case net_snmp.ObjectType.Counter64: + // copy the buffer + value = new Buffer.from(varbinds[i].value); + 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)"); + break; + + case net_snmp.ObjectType.Integer: + case net_snmp.ObjectType.Counter: + case net_snmp.ObjectType.Gauge: + default: + value = varbinds[i].value; + 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)"); + break; + } ok++; } |