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

fix snmp node linting

This commit is contained in:
Dave Conway-Jones 2022-07-22 10:18:18 +01:00
parent 67611f6bb6
commit 7a5c39ce7b
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 26 additions and 24 deletions

View File

@ -1,9 +1,9 @@
{ {
"name" : "node-red-node-snmp", "name" : "node-red-node-snmp",
"version" : "1.0.1", "version" : "1.0.2",
"description" : "A Node-RED node that gets and sets SNMP oid values. Supports v1, v2c and v3", "description" : "A Node-RED node that gets and sets SNMP oid values. Supports v1, v2c and v3",
"dependencies" : { "dependencies" : {
"net-snmp" : "^3.6.3" "net-snmp" : "^3.8.2"
}, },
"repository" : { "repository" : {
"type":"git", "type":"git",

View File

@ -141,7 +141,7 @@ module.exports = function (RED) {
const IPV6_DOUBLE_COL_PAT = /^\[{0,1}([0-9a-f:]*)::([0-9a-f:]*)(?:\]:(\d+)){0,1}$/g; const IPV6_DOUBLE_COL_PAT = /^\[{0,1}([0-9a-f:]*)::([0-9a-f:]*)(?:\]:(\d+)){0,1}$/g;
const ipv4Matcher = IPV4_PAT.exec(ip); const ipv4Matcher = IPV4_PAT.exec(ip);
let hex = ""; let hex = "";
let port = undefined; let port;
let ipOnly = []; let ipOnly = [];
try { try {
@ -392,15 +392,6 @@ module.exports = function (RED) {
node.on("input", function (msg) { node.on("input", function (msg) {
const oids = node.oids || msg.oid; const oids = node.oids || msg.oid;
const { host, sessionid, user, options } = prepareSnmpOptions(node, msg); const { host, sessionid, user, options } = prepareSnmpOptions(node, msg);
if (oids) {
msg.oid = oids;
let sess = openSession(sessionid, host, user, options);
sess.on("error", function (err) {
node.error(err, msg);
})
//move response array & feedCb to inside `node.on("input",` to avoid subsequent
// calls overwriting results from previous operations (each call gets own result/response)
const response = [];
function feedCb(varbinds) { function feedCb(varbinds) {
for (let i = 0; i < varbinds.length; i++) { for (let i = 0; i < varbinds.length; i++) {
if (SNMP.isVarbindError(varbinds[i])) { if (SNMP.isVarbindError(varbinds[i])) {
@ -410,6 +401,16 @@ module.exports = function (RED) {
} }
} }
} }
if (oids) {
msg.oid = oids;
let sess = openSession(sessionid, host, user, options);
sess.on("error", function (err) {
node.error(err, msg);
})
//move response array & feedCb to inside `node.on("input",` to avoid subsequent
// calls overwriting results from previous operations (each call gets own result/response)
const response = [];
sess.subtree(msg.oid, maxRepetitions, feedCb, function (error) { sess.subtree(msg.oid, maxRepetitions, feedCb, function (error) {
if (error) { if (error) {
node.error(error.toString(), msg); node.error(error.toString(), msg);
@ -442,15 +443,6 @@ module.exports = function (RED) {
node.on("input", function (msg) { node.on("input", function (msg) {
const oids = node.oids || msg.oid; const oids = node.oids || msg.oid;
const { host, sessionid, user, options } = prepareSnmpOptions(node, msg); const { host, sessionid, user, options } = prepareSnmpOptions(node, msg);
if (oids) {
msg.oid = oids;
let sess = openSession(sessionid, host, user, options);
sess.on("error", function (err) {
node.error(err, msg);
})
//move response array & feedCb to inside `node.on("input",` to avoid subsequent
// calls overwriting results from previous operations (each call gets own result/response)
const response = [];
function feedCb(varbinds) { function feedCb(varbinds) {
for (let i = 0; i < varbinds.length; i++) { for (let i = 0; i < varbinds.length; i++) {
if (SNMP.isVarbindError(varbinds[i])) { if (SNMP.isVarbindError(varbinds[i])) {
@ -460,6 +452,16 @@ module.exports = function (RED) {
} }
} }
} }
if (oids) {
msg.oid = oids;
let sess = openSession(sessionid, host, user, options);
sess.on("error", function (err) {
node.error(err, msg);
})
//move response array & feedCb to inside `node.on("input",` to avoid subsequent
// calls overwriting results from previous operations (each call gets own result/response)
const response = [];
sess.walk(msg.oid, maxRepetitions, feedCb, function (error) { sess.walk(msg.oid, maxRepetitions, feedCb, function (error) {
if (error) { if (error) {
node.error(error.toString(), msg); node.error(error.toString(), msg);