From a3211a5e8005e05a294908791d4fdf6d1db0f4a8 Mon Sep 17 00:00:00 2001 From: bimalyn-IBM Date: Sat, 22 Apr 2017 09:53:04 -0500 Subject: [PATCH] Update documentation for snmp nodes (#301) * I've modified the snmp libraries so that the server and the community can be defined by the msg. Error will be thrown if you try to override what was defined in the node. Verified that the contents of msg is no longer clobbered. Signed-off-by: Bryan Malyn * Replaced tabs with 4 spaces. Signed-off-by: Bryan Malyn * fix extra spacing Signed-off-by: Bryan Malyn * Standardise node.error to include msg so that errors can caught Signed-off-by: Bryan Malyn * Update documentation for snmp nodes fixed documentation as noted, removed conflict and iff from documention remove node.warns if host or community are set in both the node config and msg Signed-off-by: Bryan Malyn --- io/snmp/README.md | 59 ++++++++++++++++++++++++++++++++++++++++++++--- io/snmp/snmp.html | 8 +++++++ io/snmp/snmp.js | 38 +++++++++++------------------- 3 files changed, 77 insertions(+), 28 deletions(-) diff --git a/io/snmp/README.md b/io/snmp/README.md index 5fb58999..b228c81d 100644 --- a/io/snmp/README.md +++ b/io/snmp/README.md @@ -18,9 +18,17 @@ Usage SNMP oids fetcher. Can fetch a single or comma separated list of oids. Triggered by any input. +`msg.host` may contain the host. + +`msg.community` may contain the community. + `msg.oid` may contain a comma separated list of oids to search for. (no spaces) -The oids confgured in the edit config will override `msg.oid`. Leave blank if you +The host configured in the edit config will override `msg.host`. Leave blank if you want to use `msg.host` to provide input. + +The community configured in the edit config will override `msg.community`. Leave blank if you want to use `msg.community` to provide input. + +The oids configured in the edit config will override `msg.oid`. Leave blank if you want to use `msg.oid` to provide input. Outputs `msg.payload` containing a table of objects, and the requested `msg.oid`. @@ -29,9 +37,38 @@ Values depends on the oids being requested. ### snmp-table Simple SNMP table oid fetcher. Triggered by any input. + +`msg.host` may contain the host. + +`msg.community` may contain the community. + `msg.oid` may contain the oid of a single table to search for. -The oid confgured in the edit config will override `msg.oid`. Leave blank if you +The host configured in the edit config will override `msg.host`. Leave blank if you want to use `msg.host` to provide input. + +The community configured in the edit config will override `msg.community`. Leave blank if you want to use `msg.community` to provide input. + +The oid configured in the edit config will override `msg.oid`. Leave blank if you +want to use `msg.oid` to provide input. + +Outputs `msg.payload` containing the table of objects, and the requested `msg.oid`. +Values depends on the oids being requested. + +### snmp-subtree + +Simple SNMP oid subtree fetcher. Triggered by any input. + +`msg.host` may contain the host. + +`msg.community` may contain the community. + +`msg.oid` may contain the oid of a single table to search for. + +The host configured in the edit config will override `msg.host`. Leave blank if you want to use `msg.host` to provide input. + +The community configured in the edit config will override `msg.community`. Leave blank if you want to use `msg.community` to provide input. + +The oid configured in the edit config will override `msg.oid`. Leave blank if you want to use `msg.oid` to provide input. Outputs `msg.payload` containing the table of objects, and the requested `msg.oid`. @@ -39,4 +76,20 @@ Values depends on the oids being requested. ### snmp-walker -### snmp-subtree +Simple SNMP oid walker fetcher. Triggered by any input. + +`msg.host` may contain the host. + +`msg.community` may contain the community. + +`msg.oid` may contain the oid of a single table to search for. + +The host configured in the edit config will override `msg.host`. Leave blank if you want to use `msg.host` to provide input. + +The community configured in the edit config will override `msg.community`. Leave blank if you want to use `msg.community` to provide input. + +The oid configured in the edit config will override `msg.oid`. Leave blank if you +want to use `msg.oid` to provide input. + +Outputs `msg.payload` containing the table of objects, and the requested `msg.oid`. +Values depends on the oids being requested. diff --git a/io/snmp/snmp.html b/io/snmp/snmp.html index c0c45574..1621e724 100644 --- a/io/snmp/snmp.html +++ b/io/snmp/snmp.html @@ -28,6 +28,8 @@ @@ -85,6 +87,8 @@ @@ -141,6 +145,8 @@ @@ -199,6 +205,8 @@ diff --git a/io/snmp/snmp.js b/io/snmp/snmp.js index c3e90bf6..a1159ac0 100644 --- a/io/snmp/snmp.js +++ b/io/snmp/snmp.js @@ -12,13 +12,10 @@ module.exports = function(RED) { var node = this; this.on("input",function(msg) { + var host = node.host || msg.host; + var community = node.community || msg.community; var oids = node.oids || msg.oid; if (oids) { - if (msg.host && node.host || msg.community && node.community) { - node.warn(RED._("common.errors.nooverride")); - } - var host = node.host || msg.host; - var community = node.community || msg.community; node.session = snmp.createSession(host, community, {version: node.version}); node.session.get(oids.split(","), function(error, varbinds) { if (error) { @@ -70,18 +67,15 @@ module.exports = function(RED) { } this.on("input",function(msg) { + var host = node.host || msg.host; + var community = node.community || msg.community; var oids = node.oids || msg.oid; if (oids) { msg.oid = oids; - if (msg.host && node.host || msg.community && node.community) { - node.warn(RED._("common.errors.nooverride")); - } - var host = node.host || msg.host; - var community = node.community || msg.community; node.session = snmp.createSession(host, community, {version: node.version}); node.session.table(oids, maxRepetitions, function(error, table) { if (error) { - node.error(error.toString()); + node.error(error.toString(), msg); } else { var indexes = []; @@ -135,7 +129,7 @@ module.exports = function(RED) { function feedCb(varbinds) { for (var i = 0; i < varbinds.length; i++) { if (snmp.isVarbindError(varbinds[i])) { - node.error(snmp.varbindError(varbinds[i])); + node.error(snmp.varbindError(varbinds[i]), msg); } else { //console.log(varbinds[i].oid + "|" + varbinds[i].value); @@ -145,18 +139,15 @@ module.exports = function(RED) { } this.on("input",function(msg) { + var host = node.host || msg.host; + var community = node.community || msg.community; var oids = node.oids || msg.oid; if (oids) { msg.oid = oids; - if (msg.host && node.host || msg.community && node.community) { - node.warn(RED._("common.errors.nooverride")); - } - var host = node.host || msg.host; - var community = node.community || msg.community; node.session = snmp.createSession(host, community, {version: node.version}); node.session.subtree(msg.oid, maxRepetitions, feedCb, function(error) { if (error) { - node.error(error.toString()); + node.error(error.toString(), msg); } else { msg.payload = response; @@ -192,7 +183,7 @@ module.exports = function(RED) { function feedCb(varbinds) { for (var i = 0; i < varbinds.length; i++) { if (snmp.isVarbindError(varbinds[i])) { - node.error(snmp.varbindError(varbinds[i])); + node.error(snmp.varbindError(varbinds[i]), msg); } else { //console.log(varbinds[i].oid + "|" + varbinds[i].value); @@ -204,17 +195,14 @@ module.exports = function(RED) { this.on("input",function(msg) { node.msg = msg; var oids = node.oids || msg.oid; + var host = node.host || msg.host; + var community = node.community || msg.community; if (oids) { msg.oid = oids; - if (msg.host && node.host || msg.community && node.community) { - node.warn(RED._("common.errors.nooverride")); - } - var host = node.host || msg.host; - var community = node.community || msg.community; node.session = snmp.createSession(host, community, {version: node.version}); node.session.walk(msg.oid, maxRepetitions, feedCb, function(error) { if (error) { - node.error(error.toString()); + node.error(error.toString(), msg); } else { msg.payload = response;