Hello all.
This is probably really easy for somebody but I am struggling. I have read a bunch of stuff and never done any js stuff.
I am trying to use net-snmp in a function node. I need to eventually get snmp-v3 but for testing just v2.
I have it working so far and it returns the correct data in the debug window. But how do I get that same out put into the msg.payload?
Any help would be great. This is the code that I am running from the function node.
// NPM module exposed as variable, npm_module
var session = snmp.createSession ("192.168.10.250", "public");
var oids = ["1.3.6.1.2.1.1.1.0"];
session.get (oids, function (error, varbinds) {
if (error) {
console.error (error);
} else {
for (var i = 0; i < varbinds.length; i++) {
if (snmp.isVarbindError (varbinds[i])) {
console.error (snmp.varbindError (varbinds[i]));
} else {
console.log (varbinds[i].oid + " = " + varbinds[i].value);
}
}
}
session.close ();
});
return msg;
Firstly, is there a reason you are not using node-red-node-snmp?
Secondly, as you are running async code, you cannot return msg
you need to use node.send
e.g....
// NPM module exposed as variable, npm_module
const session = snmp.createSession ("192.168.10.250", "public");
const oids = ["1.3.6.1.2.1.1.1.0"];
session.get (oids, function (error, varbinds) {
if (error) {
node.error(error, msg);
} else {
for (let i = 0; i < varbinds.length; i++) {
const e = snmp.varbindError(varbinds[i]);
if (e) {
node.error(e, msg);
} else {
msg.payload = varbinds[i].value;
msg.topic = varbinds[i].oid;
node.send(msg)
}
}
}
session.close ();
});
/// return msg; << delete this
Thanks for the reply.
I wasnt using node-red-node-snmp because as far as I am aware I couldnt do snmpV3 which is where this will end up.
Am just trying to get it working before I move forward.
As i said I have been reading and getting it to this point and have no js experiance so it has been a bit of a learning curve.
I have shut the pc down now but Will give the changes ago tomorrow.
Thanks again.
Ah. The node-red-node-snmp uses net-snmp under the hood (which does support v3) however its dependency is on a really old version.
There is a pull request to add V3 support but the PR author has not addressed the review comments (so the PR has stalled)
system
Closed
7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.