1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

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 <bimalyn@us.ibm.com>

* Replaced tabs with 4 spaces.
Signed-off-by: Bryan Malyn <bimalyn@us.ibm.com>

* fix extra spacing

Signed-off-by: Bryan Malyn <bimalyn@us.ibm.com>

* Standardise node.error to include msg so that errors can caught

Signed-off-by: Bryan Malyn <bimalyn@us.ibm.com>

* 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 <bimalyn@us.ibm.com>
This commit is contained in:
bimalyn-IBM 2017-04-22 09:53:04 -05:00 committed by Dave Conway-Jones
parent 2023bddf97
commit a3211a5e80
3 changed files with 77 additions and 28 deletions

View File

@ -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.

View File

@ -28,6 +28,8 @@
<script type="text/x-red" data-help-name="snmp">
<p>Simple SNMP oid or oid list fetcher. Triggered by any input.</p>
<p><code>msg.host</code> may contain the host.</p>
<p><code>msg.community</code> may contain the community.</p>
<p><code>msg.oid</code> may contain a comma separated list of oids to request. (no spaces)</p>
<p>The node will output <code>msg.payload</code> and <code>msg.oid</code>.</p>
</script>
@ -85,6 +87,8 @@
<script type="text/x-red" data-help-name="snmp table">
<p>Simple SNMP oid table fetcher. Triggered by any input.</p>
<p><code>msg.host</code> may contain the host.</p>
<p><code>msg.community</code> may contain the community.</p>
<p><code>msg.oid</code> may contain the oid of a table to request.</p>
<p>The node will output <code>msg.payload</code> and <code>msg.oid</code>.</p>
</script>
@ -141,6 +145,8 @@
<script type="text/x-red" data-help-name="snmp subtree">
<p>Simple SNMP oid subtree fetcher. Triggered by any input.</p>
<p><code>msg.host</code> may contain the host.</p>
<p><code>msg.community</code> may contain the community.</p>
<p><code>msg.oid</code> may contain the oid of a table to request.</p>
<p>The node will output <code>msg.payload</code> and <code>msg.oid</code>.</p>
</script>
@ -199,6 +205,8 @@
<script type="text/x-red" data-help-name="snmp walker">
<p>Simple SNMP oid walker fetcher. Triggered by any input.</p>
<p><code>msg.host</code> may contain the host.</p>
<p><code>msg.community</code> may contain the community.</p>
<p><code>msg.oid</code> may contain the oid of a table to request.</p>
<p>The node will output <code>msg.payload</code> and <code>msg.oid</code>.</p>
</script>

View File

@ -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;