node-red-snmp-node - snmp_walker
The code needs to change the following to better comply with net-snmp example.
The code will break out of its branches and is limited to 20 GetNext replies.
May we discuss the merits of the sub-package this is built on and consider one that we can implement bulk request and tables.
var maxRepetitions = 20;
getSession(host, community, node.version, node.timeout).walk(msg.oid, maxRepetitions, feedCb, function (error)
function SnmpWalkerNode(n) {
RED.nodes.createNode(this, n);
this.community = n.community;
this.host = n.host;
this.version = (n.version === "2c") ? snmp.Version2c : snmp.Version1;
this.oids = n.oids.replace(/\s/g, "");
this.timeout = Number(n.timeout || 5) * 1000;
var node = this;
var maxRepetitions = 20;
var response = [];
function feedCb(varbinds) {
for (var i = 0; i < varbinds.length; i++) {
if (snmp.isVarbindError(varbinds[i])) {
node.error(snmp.varbindError(varbinds[i]), msg);
}
else {
//console.log(varbinds[i].oid + "|" + varbinds[i].value);
response.push({ oid: varbinds[i].oid, value: varbinds[i].value });
}
}
}
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;
getSession(host, community, node.version, node.timeout).walk(msg.oid, maxRepetitions, feedCb, function (error) {
if (error) {
node.error(error.toString(), msg);
}
else {
// Clone the array
msg.payload = response.slice(0);
node.send(msg);
//Clears response
response.length = 0;
}
});
}
else {
node.warn("No oid to search for");
}
});
}
var oids = [
"1.3.6.1.2.1.1.1.0",
"1.3.6.1.2.1.1.4.0"
];
session.getNext (oids, function (error, varbinds) {
if (error) {
console.error (error.toString ());
} else {
for (var i = 0; i < varbinds.length; i++) {
// for version 1 we can assume all OIDs were successful
console.log (varbinds[i].oid + "|" + varbinds[i].value);
// for version 2c we must check each OID for an error condition
if (snmp.isVarbindError (varbinds[i]))
console.error (snmp.varbindError (varbinds[i]));
else
console.log (varbinds[i].oid + "|" + varbinds[i].value);
}
}
});
Hi @vlturner
we provide an issue template that we kindly ask you to use as it helps ensure enough information is provided with the issue.
It also says that we prefer discussions around feature enhancements to happen on the forum or slack in the first instance.
Pasting a screenful of code into an issue isn't the ideal way to start a conversation around a possible enhancement as we can't see what actual changes you are proposing.
- what problem are you trying to solve?
- why does the current node not satisfying that requirement?
- you say the code needs to change to "better comply with net-snmp example" - can you expand on that? Is there a link to something for context?
So the node in question is the top code, and the code below is the example from the authors of the included module net-snmp.
The top module is limited to 20 iterations and that is just wrong.
Sorry I submitted as I did still trying to familiarize myself here.
The code isn't working against my windows 10 SNMP agent and using wireshaark I can see the request and response, but the node isn't processing correctly. So then looking at the code it is clear that the nodes need a rework and that brings me to considering where to start.
Compliance to the nospaceships code isn't being followed and if there is a rework consideration of node-net-snmp seriously needs to be considered over the nospaceships code.
The bottom code is the nospaceships example in their documentation showing how GetNext needs to be coded to support V1 and V2c
In node-net-snmp we could get the V3 operational.