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 {
@ -165,7 +165,7 @@ module.exports = function (RED) {
const IPV6_PAT = new RegExp(ipv6Pattern); const IPV6_PAT = new RegExp(ipv6Pattern);
// IPV6, double colon // IPV6, double colon
const ipv6DoubleColonMatcher = IPV6_DOUBLE_COL_PAT.exec(ip); const ipv6DoubleColonMatcher = IPV6_DOUBLE_COL_PAT.exec(ip);
if (ipv6DoubleColonMatcher && ipv6DoubleColonMatcher.length) { if (ipv6DoubleColonMatcher && ipv6DoubleColonMatcher.length) {
let p1 = ipv6DoubleColonMatcher[1]; let p1 = ipv6DoubleColonMatcher[1];
@ -392,24 +392,25 @@ 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);
function feedCb(varbinds) {
for (let i = 0; i < varbinds.length; i++) {
if (SNMP.isVarbindError(varbinds[i])) {
node.error(SNMP.varbindError(varbinds[i]), msg);
} else {
response.push({ oid: varbinds[i].oid, value: varbinds[i].value });
}
}
}
if (oids) { if (oids) {
msg.oid = oids; msg.oid = oids;
let sess = openSession(sessionid, host, user, options); let sess = openSession(sessionid, host, user, options);
sess.on("error", function (err) { sess.on("error", function (err) {
node.error(err, msg); node.error(err, msg);
}) })
//move response array & feedCb to inside `node.on("input",` to avoid subsequent //move response array & feedCb to inside `node.on("input",` to avoid subsequent
// calls overwriting results from previous operations (each call gets own result/response) // calls overwriting results from previous operations (each call gets own result/response)
const response = []; const response = [];
function feedCb(varbinds) {
for (let i = 0; i < varbinds.length; i++) {
if (SNMP.isVarbindError(varbinds[i])) {
node.error(SNMP.varbindError(varbinds[i]), msg);
} else {
response.push({ oid: varbinds[i].oid, value: varbinds[i].value });
}
}
}
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,24 +443,25 @@ 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);
function feedCb(varbinds) {
for (let i = 0; i < varbinds.length; i++) {
if (SNMP.isVarbindError(varbinds[i])) {
node.error(SNMP.varbindError(varbinds[i]), msg);
} else {
response.push({ oid: varbinds[i].oid, value: varbinds[i].value });
}
}
}
if (oids) { if (oids) {
msg.oid = oids; msg.oid = oids;
let sess = openSession(sessionid, host, user, options); let sess = openSession(sessionid, host, user, options);
sess.on("error", function (err) { sess.on("error", function (err) {
node.error(err, msg); node.error(err, msg);
}) })
//move response array & feedCb to inside `node.on("input",` to avoid subsequent //move response array & feedCb to inside `node.on("input",` to avoid subsequent
// calls overwriting results from previous operations (each call gets own result/response) // calls overwriting results from previous operations (each call gets own result/response)
const response = []; const response = [];
function feedCb(varbinds) {
for (let i = 0; i < varbinds.length; i++) {
if (SNMP.isVarbindError(varbinds[i])) {
node.error(SNMP.varbindError(varbinds[i]), msg);
} else {
response.push({ oid: varbinds[i].oid, value: varbinds[i].value });
}
}
}
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);