From a8220ab2d293bb7f4b014b79d16b2fb05090fa93 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Feb 2021 12:45:55 +0100 Subject: Adding upstream version 1.29.0. Signed-off-by: Daniel Baumann --- collectors/node.d.plugin/snmp/README.md | 353 +++++++++++++++++------------ collectors/node.d.plugin/snmp/snmp.node.js | 199 ++++++++-------- 2 files changed, 316 insertions(+), 236 deletions(-) (limited to 'collectors/node.d.plugin/snmp') diff --git a/collectors/node.d.plugin/snmp/README.md b/collectors/node.d.plugin/snmp/README.md index c661bac8c..93ade5e64 100644 --- a/collectors/node.d.plugin/snmp/README.md +++ b/collectors/node.d.plugin/snmp/README.md @@ -1,15 +1,26 @@ -# SNMP Data Collector + -Using this collector, Netdata can collect data from any SNMP device. +# SNMP device monitoring with Netdata -This collector supports: +Collects data from any SNMP device and uses the [net-snmp](https://github.com/markabrahams/node-net-snmp) module. +It supports: + +- all SNMP versions: SNMPv1, SNMPv2c and SNMPv3 - any number of SNMP devices - each SNMP device can be used to collect data for any number of charts - each chart may have any number of dimensions - each SNMP device may have a different update frequency - each SNMP device will accept one or more batches to report values (you can set `max_request_size` per SNMP server, to control the size of batches). +## Requirements + +- `nodejs` minimum required version 4 + ## Configuration You will need to create the file `/etc/netdata/node.d/snmp.conf` with data like the following. @@ -32,7 +43,9 @@ In this example: "community": "public", "update_every": 10, "max_request_size": 50, - "options": { "timeout": 10000 }, + "options": { + "timeout": 10000 + }, "charts": { "snmp_switch.bandwidth_port1": { "title": "Switch Bandwidth for port 1", @@ -109,7 +122,9 @@ If you need to define many charts using incremental OIDs, you can use something "hostname": "10.11.12.8", "community": "public", "update_every": 10, - "options": { "timeout": 20000 }, + "options": { + "timeout": 20000 + }, "charts": { "snmp_switch.bandwidth_port": { "title": "Switch Bandwidth for port ", @@ -117,7 +132,10 @@ If you need to define many charts using incremental OIDs, you can use something "type": "area", "priority": 1, "family": "ports", - "multiply_range": [ 1, 24 ], + "multiply_range": [ + 1, + 24 + ], "dimensions": { "in": { "oid": "1.3.6.1.2.1.2.2.1.10.", @@ -152,11 +170,55 @@ Each of the 24 new charts will have its id (1-24) appended at: The `options` given for each server, are: -- `timeout`, the time to wait for the SNMP device to respond. The default is 5000 ms. -- `version`, the SNMP version to use. `0` is Version 1, `1` is Version 2c. The default is Version 1 (`0`). -- `transport`, the default is `udp4`. -- `port`, the port of the SNMP device to connect to. The default is `161`. -- `retries`, the number of attempts to make to fetch the data. The default is `1`. +- `port` - UDP port to send requests too. Defaults to `161`. +- `retries` - number of times to re-send a request. Defaults to `1`. +- `sourceAddress` - IP address from which SNMP requests should originate, there is no default for this option, the operating system will select an appropriate source address when the SNMP request is sent. +- `sourcePort` - UDP port from which SNMP requests should originate, defaults to an ephemeral port selected by the operation system. +- `timeout` - number of milliseconds to wait for a response before re-trying or failing. Defaults to `5000`. +- `transport` - specify the transport to use, can be either `udp4` or `udp6`. Defaults to `udp4`. +- `version` - either `0` (v1) or `1` (v2) or `3` (v3). Defaults to `0`. +- `idBitsSize` - either `16` or `32`. Defaults to `32`. Used to reduce the size of the generated id for compatibility with some older devices. + +## SNMPv3 + +To use SNMPv3: + +- set `version` to 3 +- use `user` instead of `community` + +User syntax: + +```json +{ + "user": { + "name": "userName", + "level": 3, + "authProtocol": "3", + "authKey": "authKey", + "privProtocol": "2", + "privKey": "privKey" + } +} +``` + +Security levels: + +- 1 is `noAuthNoPriv` +- 2 is `authNoPriv` +- 3 is `authPriv` + +Authentication protocols: + +- "1" is `none` +- "2" is `md5` +- "3" is `sha` + +Privacy protocols: + +- "1" is `none` +- "2" is `des` + +For additional details please see [net-snmp module readme](https://github.com/markabrahams/node-net-snmp#snmpcreatev3session-target-user-options). ## Retrieving names from snmp @@ -218,145 +280,152 @@ This switch has a very slow SNMP processors. To respond, it needs about 8 second "enable_autodetect": false, "update_every": 5, "servers": [ - { - "hostname": "10.11.12.8", - "community": "public", - "update_every": 15, - "options": { "timeout": 20000, "version": 1 }, - "charts": { - "snmp_switch.power": { - "title": "Switch Power Supply", - "units": "watts", - "type": "line", - "priority": 10, - "family": "power", - "dimensions": { - "supply": { - "oid": ".1.3.6.1.2.1.105.1.3.1.1.2.1", - "algorithm": "absolute", - "multiplier": 1, - "divisor": 1, - "offset": 0 - }, - "used": { - "oid": ".1.3.6.1.2.1.105.1.3.1.1.4.1", - "algorithm": "absolute", - "multiplier": 1, - "divisor": 1, - "offset": 0 - } - } - } - , "snmp_switch.input": { - "title": "Switch Packets Input", - "units": "packets/s", - "type": "area", - "priority": 20, - "family": "IP", - "dimensions": { - "receives": { - "oid": ".1.3.6.1.2.1.4.3.0", - "algorithm": "incremental", - "multiplier": 1, - "divisor": 1, - "offset": 0 - } - , "discards": { - "oid": ".1.3.6.1.2.1.4.8.0", - "algorithm": "incremental", - "multiplier": 1, - "divisor": 1, - "offset": 0 - } - } - } - , "snmp_switch.input_errors": { - "title": "Switch Received Packets with Errors", - "units": "packets/s", - "type": "line", - "priority": 30, - "family": "IP", - "dimensions": { - "bad_header": { - "oid": ".1.3.6.1.2.1.4.4.0", - "algorithm": "incremental", - "multiplier": 1, - "divisor": 1, - "offset": 0 - } - , "bad_address": { - "oid": ".1.3.6.1.2.1.4.5.0", - "algorithm": "incremental", - "multiplier": 1, - "divisor": 1, - "offset": 0 - } - , "unknown_protocol": { - "oid": ".1.3.6.1.2.1.4.7.0", - "algorithm": "incremental", - "multiplier": 1, - "divisor": 1, - "offset": 0 - } - } - } - , "snmp_switch.output": { - "title": "Switch Output Packets", - "units": "packets/s", - "type": "line", - "priority": 40, - "family": "IP", - "dimensions": { - "requests": { - "oid": ".1.3.6.1.2.1.4.10.0", - "algorithm": "incremental", - "multiplier": 1, - "divisor": 1, - "offset": 0 + { + "hostname": "10.11.12.8", + "community": "public", + "update_every": 15, + "options": { + "timeout": 20000, + "version": 1 + }, + "charts": { + "snmp_switch.power": { + "title": "Switch Power Supply", + "units": "watts", + "type": "line", + "priority": 10, + "family": "power", + "dimensions": { + "supply": { + "oid": ".1.3.6.1.2.1.105.1.3.1.1.2.1", + "algorithm": "absolute", + "multiplier": 1, + "divisor": 1, + "offset": 0 + }, + "used": { + "oid": ".1.3.6.1.2.1.105.1.3.1.1.4.1", + "algorithm": "absolute", + "multiplier": 1, + "divisor": 1, + "offset": 0 + } } - , "discards": { - "oid": ".1.3.6.1.2.1.4.11.0", - "algorithm": "incremental", - "multiplier": -1, - "divisor": 1, - "offset": 0 + }, + "snmp_switch.input": { + "title": "Switch Packets Input", + "units": "packets/s", + "type": "area", + "priority": 20, + "family": "IP", + "dimensions": { + "receives": { + "oid": ".1.3.6.1.2.1.4.3.0", + "algorithm": "incremental", + "multiplier": 1, + "divisor": 1, + "offset": 0 + }, + "discards": { + "oid": ".1.3.6.1.2.1.4.8.0", + "algorithm": "incremental", + "multiplier": 1, + "divisor": 1, + "offset": 0 + } } - , "no_route": { - "oid": ".1.3.6.1.2.1.4.12.0", - "algorithm": "incremental", - "multiplier": -1, - "divisor": 1, - "offset": 0 + }, + "snmp_switch.input_errors": { + "title": "Switch Received Packets with Errors", + "units": "packets/s", + "type": "line", + "priority": 30, + "family": "IP", + "dimensions": { + "bad_header": { + "oid": ".1.3.6.1.2.1.4.4.0", + "algorithm": "incremental", + "multiplier": 1, + "divisor": 1, + "offset": 0 + }, + "bad_address": { + "oid": ".1.3.6.1.2.1.4.5.0", + "algorithm": "incremental", + "multiplier": 1, + "divisor": 1, + "offset": 0 + }, + "unknown_protocol": { + "oid": ".1.3.6.1.2.1.4.7.0", + "algorithm": "incremental", + "multiplier": 1, + "divisor": 1, + "offset": 0 + } } - } - } - , "snmp_switch.bandwidth_port": { - "title": "Switch Bandwidth for port ", - "titleoid": ".1.3.6.1.2.1.31.1.1.1.18.", - "units": "kilobits/s", - "type": "area", - "priority": 100, - "family": "ports", - "multiply_range": [ 1, 24 ], - "dimensions": { - "in": { - "oid": ".1.3.6.1.2.1.2.2.1.10.", - "algorithm": "incremental", - "multiplier": 8, - "divisor": 1024, - "offset": 0 + }, + "snmp_switch.output": { + "title": "Switch Output Packets", + "units": "packets/s", + "type": "line", + "priority": 40, + "family": "IP", + "dimensions": { + "requests": { + "oid": ".1.3.6.1.2.1.4.10.0", + "algorithm": "incremental", + "multiplier": 1, + "divisor": 1, + "offset": 0 + }, + "discards": { + "oid": ".1.3.6.1.2.1.4.11.0", + "algorithm": "incremental", + "multiplier": -1, + "divisor": 1, + "offset": 0 + }, + "no_route": { + "oid": ".1.3.6.1.2.1.4.12.0", + "algorithm": "incremental", + "multiplier": -1, + "divisor": 1, + "offset": 0 + } } - , "out": { - "oid": ".1.3.6.1.2.1.2.2.1.16.", - "algorithm": "incremental", - "multiplier": -8, - "divisor": 1024, - "offset": 0 + }, + "snmp_switch.bandwidth_port": { + "title": "Switch Bandwidth for port ", + "titleoid": ".1.3.6.1.2.1.31.1.1.1.18.", + "units": "kilobits/s", + "type": "area", + "priority": 100, + "family": "ports", + "multiply_range": [ + 1, + 24 + ], + "dimensions": { + "in": { + "oid": ".1.3.6.1.2.1.2.2.1.10.", + "algorithm": "incremental", + "multiplier": 8, + "divisor": 1024, + "offset": 0 + }, + "out": { + "oid": ".1.3.6.1.2.1.2.2.1.16.", + "algorithm": "incremental", + "multiplier": -8, + "divisor": 1024, + "offset": 0 + } } } } } - }], + ] } ``` diff --git a/collectors/node.d.plugin/snmp/snmp.node.js b/collectors/node.d.plugin/snmp/snmp.node.js index 6b33ae0d5..ca3f0bfbc 100644 --- a/collectors/node.d.plugin/snmp/snmp.node.js +++ b/collectors/node.d.plugin/snmp/snmp.node.js @@ -117,53 +117,53 @@ var net_snmp = require('net-snmp'); var extend = require('extend'); var netdata = require('netdata'); -if(netdata.options.DEBUG === true) netdata.debug('loaded', __filename, ' plugin'); +if (netdata.options.DEBUG === true) netdata.debug('loaded', __filename, ' plugin'); netdata.processors.snmp = { name: 'snmp', - fixoid: function(oid) { - if(typeof oid !== 'string') + fixoid: function (oid) { + if (typeof oid !== 'string') return oid; - if(oid.charAt(0) === '.') + if (oid.charAt(0) === '.') return oid.substring(1, oid.length); return oid; }, - prepare: function(service) { + prepare: function (service) { var __DEBUG = netdata.options.DEBUG; - if(typeof service.snmp_oids === 'undefined' || service.snmp_oids === null || service.snmp_oids.length === 0) { + if (typeof service.snmp_oids === 'undefined' || service.snmp_oids === null || service.snmp_oids.length === 0) { // this is the first time we see this service - if(__DEBUG === true) + if (__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': preparing ' + this.name + ' OIDs'); // build an index of all OIDs service.snmp_oids_index = {}; var chart_keys = Object.keys(service.request.charts); var chart_keys_len = chart_keys.length; - while(chart_keys_len--) { + while (chart_keys_len--) { var c = chart_keys[chart_keys_len]; var chart = service.request.charts[c]; // for each chart - if(__DEBUG === true) + if (__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': indexing ' + this.name + ' chart: ' + c); - if(typeof chart.titleoid !== 'undefined') { - service.snmp_oids_index[this.fixoid(chart.titleoid)] = { - type: 'title', - link: chart - }; - } + if (typeof chart.titleoid !== 'undefined') { + service.snmp_oids_index[this.fixoid(chart.titleoid)] = { + type: 'title', + link: chart + }; + } var dim_keys = Object.keys(chart.dimensions); var dim_keys_len = dim_keys.length; - while(dim_keys_len--) { + while (dim_keys_len--) { var d = dim_keys[dim_keys_len]; var dim = chart.dimensions[d]; @@ -172,7 +172,7 @@ netdata.processors.snmp = { var oid = this.fixoid(dim.oid); var oidname = this.fixoid(dim.oidname); - if(__DEBUG === true) + if (__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': indexing ' + this.name + ' chart: ' + c + ', dimension: ' + d + ', OID: ' + oid + ", OID name: " + oidname); // link it to the point we need to set the value to @@ -181,7 +181,7 @@ netdata.processors.snmp = { link: dim }; - if(typeof oidname !== 'undefined') + if (typeof oidname !== 'undefined') service.snmp_oids_index[oidname] = { type: 'name', link: dim @@ -192,18 +192,17 @@ netdata.processors.snmp = { } } - if(__DEBUG === true) + if (__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': indexed ' + this.name + ' OIDs: ' + netdata.stringify(service.snmp_oids_index)); // now create the array of OIDs needed by net-snmp service.snmp_oids = Object.keys(service.snmp_oids_index); - if(__DEBUG === true) + if (__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': final list of ' + this.name + ' OIDs: ' + netdata.stringify(service.snmp_oids)); service.snmp_oids_cleaned = 0; - } - else if(service.snmp_oids_cleaned === 0) { + } else if (service.snmp_oids_cleaned === 0) { service.snmp_oids_cleaned = 1; // the second time, keep only values @@ -211,87 +210,82 @@ netdata.processors.snmp = { service.snmp_oids = new Array(); var oid_keys = Object.keys(service.snmp_oids_index); var oid_keys_len = oid_keys.length; - while(oid_keys_len--) { + while (oid_keys_len--) { if (service.snmp_oids_index[oid_keys[oid_keys_len]].type === 'value') service.snmp_oids.push(oid_keys[oid_keys_len]); } } }, - getdata: function(service, index, ok, failed, callback) { + getdata: function (service, index, ok, failed, callback) { var __DEBUG = netdata.options.DEBUG; var that = this; - if(index >= service.snmp_oids.length) { - callback((ok > 0)?{ ok: ok, failed: failed }:null); + if (index >= service.snmp_oids.length) { + callback((ok > 0) ? {ok: ok, failed: failed} : null); return; } var slice; - if(service.snmp_oids.length <= service.request.max_request_size) { + if (service.snmp_oids.length <= service.request.max_request_size) { slice = service.snmp_oids; index = service.snmp_oids.length; - } - else if(service.snmp_oids.length - index <= service.request.max_request_size) { + } else if (service.snmp_oids.length - index <= service.request.max_request_size) { slice = service.snmp_oids.slice(index, service.snmp_oids.length); index = service.snmp_oids.length; - } - else { + } else { slice = service.snmp_oids.slice(index, index + service.request.max_request_size); index += service.request.max_request_size; } - if(__DEBUG === true) + if (__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': making ' + slice.length + ' entries request, max is: ' + service.request.max_request_size); - service.snmp_session.get(slice, function(error, varbinds) { - if(error) { + service.snmp_session.get(slice, function (error, varbinds) { + if (error) { service.error('Received error = ' + netdata.stringify(error) + ' varbinds = ' + netdata.stringify(varbinds)); // make all values null var len = slice.length; - while(len--) + while (len--) service.snmp_oids_index[slice[len]].value = null; - } - else { - if(__DEBUG === true) + } else { + if (__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': got valid ' + service.module.name + ' response: ' + netdata.stringify(varbinds)); var varbinds_len = varbinds.length; - for(var i = 0; i < varbinds_len ; i++) { + for (var i = 0; i < varbinds_len; i++) { var value = null; - if(net_snmp.isVarbindError(varbinds[i])) { - if(__DEBUG === true) + if (net_snmp.isVarbindError(varbinds[i])) { + if (__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': failed ' + service.module.name + ' get for OIDs ' + varbinds[i].oid); service.error('OID ' + varbinds[i].oid + ' gave error: ' + net_snmp.varbindError(varbinds[i])); value = null; failed++; - } - else { + } else { // test fom Counter64 // varbinds[i].type = net_snmp.ObjectType.Counter64; // varbinds[i].value = new Buffer([0x34, 0x49, 0x2e, 0xdc, 0xd1]); - switch(varbinds[i].type) { + switch (varbinds[i].type) { case net_snmp.ObjectType.OctetString: if (service.snmp_oids_index[varbinds[i].oid].type !== 'title' && service.snmp_oids_index[varbinds[i].oid].type !== 'name') { // 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 = " + value.toString() + " (parsed as float in string)"); - } - 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 = " + 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 = " + value.toString() + " (parsed as string)"); + 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 = " + value.toString() + " (parsed as string)"); } break; case net_snmp.ObjectType.Counter64: // copy the buffer value = '0x' + varbinds[i].value.toString('hex'); - 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 = " + value.toString() + " (parsed as buffer)"); + 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 = " + value.toString() + " (parsed as buffer)"); break; case net_snmp.ObjectType.Integer: @@ -299,55 +293,73 @@ netdata.processors.snmp = { 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 = " + value.toString() + " (parsed as number)"); + 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 = " + value.toString() + " (parsed as number)"); break; } ok++; } - if(value !== null) { - switch(service.snmp_oids_index[varbinds[i].oid].type) { - case 'title': service.snmp_oids_index[varbinds[i].oid].link.title += ' ' + value; break; - case 'name' : service.snmp_oids_index[varbinds[i].oid].link.name = value.toString().replace(/\W/g, '_'); break; - case 'value': service.snmp_oids_index[varbinds[i].oid].link.value = value; break; + if (value !== null) { + switch (service.snmp_oids_index[varbinds[i].oid].type) { + case 'title': + service.snmp_oids_index[varbinds[i].oid].link.title += ' ' + value; + break; + case 'name' : + service.snmp_oids_index[varbinds[i].oid].link.name = value.toString().replace(/\W/g, '_'); + break; + case 'value': + service.snmp_oids_index[varbinds[i].oid].link.value = value; + break; } } } - if(__DEBUG === true) + if (__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': finished ' + service.module.name + ' with ' + ok + ' successful and ' + failed + ' failed values'); } that.getdata(service, index, ok, failed, callback); }); }, - process: function(service, callback) { + process: function (service, callback) { var __DEBUG = netdata.options.DEBUG; this.prepare(service); - if(service.snmp_oids.length === 0) { + if (service.snmp_oids.length === 0) { // no OIDs found for this service - if(__DEBUG === true) + if (__DEBUG === true) service.error('no OIDs to process.'); callback(null); return; } - if(typeof service.snmp_session === 'undefined' || service.snmp_session === null) { + if (typeof service.snmp_session === 'undefined' || service.snmp_session === null) { // no SNMP session has been created for this service // the SNMP session is just the initialization of NET-SNMP - if(__DEBUG === true) - netdata.debug(service.module.name + ': ' + service.name + ': opening ' + this.name + ' session on ' + service.request.hostname + ' community ' + service.request.community + ' options ' + netdata.stringify(service.request.options)); + var snmp_version = (service.request.options && service.request.options.version) + ? service.request.options.version + : net_snmp.Version1; - // create the SNMP session - service.snmp_session = net_snmp.createSession (service.request.hostname, service.request.community, service.request.options); + if (snmp_version === net_snmp.Version3) { + if (__DEBUG === true) + netdata.debug(service.module.name + ': ' + service.name + ': opening ' + this.name + ' session on ' + service.request.hostname + ' user ' + service.request.user + ' options ' + netdata.stringify(service.request.options)); - if(__DEBUG === true) + // create the SNMP session + service.snmp_session = net_snmp.createV3Session(service.request.hostname, service.request.user, service.request.options); + } else { + if (__DEBUG === true) + netdata.debug(service.module.name + ': ' + service.name + ': opening ' + this.name + ' session on ' + service.request.hostname + ' community ' + service.request.community + ' options ' + netdata.stringify(service.request.options)); + + // create the SNMP session + service.snmp_session = net_snmp.createSession(service.request.hostname, service.request.community, service.request.options); + } + + if (__DEBUG === true) netdata.debug(service.module.name + ': ' + service.name + ': got ' + this.name + ' session: ' + netdata.stringify(service.snmp_session)); // if we later need traps, this is how to do it: @@ -369,18 +381,18 @@ var snmp = { charts: {}, - processResponse: function(service, data) { - if(data !== null) { - if(service.added !== true) + processResponse: function (service, data) { + if (data !== null) { + if (service.added !== true) service.commit(); var chart_keys = Object.keys(service.request.charts); var chart_keys_len = chart_keys.length; - for(var i = 0; i < chart_keys_len; i++) { + for (var i = 0; i < chart_keys_len; i++) { var c = chart_keys[i]; var chart = snmp.charts[c]; - if(typeof chart === 'undefined') { + if (typeof chart === 'undefined') { chart = service.chart(c, service.request.charts[c]); snmp.charts[c] = chart; } @@ -390,11 +402,11 @@ var snmp = { var dimensions = service.request.charts[c].dimensions; var dim_keys = Object.keys(dimensions); var dim_keys_len = dim_keys.length; - for(var j = 0; j < dim_keys_len ; j++) { + for (var j = 0; j < dim_keys_len; j++) { var d = dim_keys[j]; if (dimensions[d].value !== null) { - if(typeof dimensions[d].offset === 'number' && typeof dimensions[d].value === 'number') + if (typeof dimensions[d].offset === 'number' && typeof dimensions[d].value === 'number') service.set(d, dimensions[d].value + dimensions[d].offset); else service.set(d, dimensions[d].value); @@ -410,10 +422,10 @@ var snmp = { // this function is called only from this module // its purpose is to prepare the request and call // netdata.serviceExecute() - serviceExecute: function(conf) { + serviceExecute: function (conf) { var __DEBUG = netdata.options.DEBUG; - if(__DEBUG === true) + if (__DEBUG === true) netdata.debug(this.name + ': snmp hostname: ' + conf.hostname + ', update_every: ' + conf.update_every); var service = netdata.service({ @@ -427,41 +439,41 @@ var snmp = { // multiply the charts, if required var chart_keys = Object.keys(service.request.charts); var chart_keys_len = chart_keys.length; - for( var i = 0; i < chart_keys_len ; i++ ) { + for (var i = 0; i < chart_keys_len; i++) { var c = chart_keys[i]; var service_request_chart = service.request.charts[c]; - if(__DEBUG === true) + if (__DEBUG === true) netdata.debug(this.name + ': snmp hostname: ' + conf.hostname + ', examining chart: ' + c); - if(typeof service_request_chart.update_every === 'undefined') + if (typeof service_request_chart.update_every === 'undefined') service_request_chart.update_every = service.update_every; - if(typeof service_request_chart.multiply_range !== 'undefined') { + if (typeof service_request_chart.multiply_range !== 'undefined') { var from = service_request_chart.multiply_range[0]; var to = service_request_chart.multiply_range[1]; var prio = service_request_chart.priority || 1; - if(prio < snmp.base_priority) prio += snmp.base_priority; + if (prio < snmp.base_priority) prio += snmp.base_priority; - while(from <= to) { + while (from <= to) { var id = c + from.toString(); var chart = extend(true, {}, service_request_chart); chart.title += from.toString(); - if(typeof chart.titleoid !== 'undefined') + if (typeof chart.titleoid !== 'undefined') chart.titleoid += from.toString(); chart.priority = prio++; var dim_keys = Object.keys(chart.dimensions); var dim_keys_len = dim_keys.length; - for(var j = 0; j < dim_keys_len ; j++) { + for (var j = 0; j < dim_keys_len; j++) { var d = dim_keys[j]; chart.dimensions[d].oid += from.toString(); - if(typeof chart.dimensions[d].oidname !== 'undefined') + if (typeof chart.dimensions[d].oidname !== 'undefined') chart.dimensions[d].oidname += from.toString(); } service.request.charts[id] = chart; @@ -469,9 +481,8 @@ var snmp = { } delete service.request.charts[c]; - } - else { - if(service.request.charts[c].priority < snmp.base_priority) + } else { + if (service.request.charts[c].priority < snmp.base_priority) service.request.charts[c].priority += snmp.base_priority; } } @@ -479,19 +490,19 @@ var snmp = { service.execute(this.processResponse); }, - configure: function(config) { + configure: function (config) { var added = 0; - if(typeof config.max_request_size === 'undefined') + if (typeof config.max_request_size === 'undefined') config.max_request_size = 50; - if(typeof(config.servers) !== 'undefined') { + if (typeof (config.servers) !== 'undefined') { var len = config.servers.length; - while(len--) { - if(typeof config.servers[len].update_every === 'undefined') + while (len--) { + if (typeof config.servers[len].update_every === 'undefined') config.servers[len].update_every = this.update_every; - if(typeof config.servers[len].max_request_size === 'undefined') + if (typeof config.servers[len].max_request_size === 'undefined') config.servers[len].max_request_size = config.max_request_size; this.serviceExecute(config.servers[len]); @@ -505,8 +516,8 @@ var snmp = { // module.update() // this is called repeatidly to collect data, by calling // service.execute() - update: function(service, callback) { - service.execute(function(serv, data) { + update: function (service, callback) { + service.execute(function (serv, data) { service.module.processResponse(serv, data); callback(); }); -- cgit v1.2.3