mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
parent
17886b7296
commit
b3fd755527
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-snmp",
|
"name" : "node-red-node-snmp",
|
||||||
"version" : "0.0.15",
|
"version" : "0.0.16",
|
||||||
"description" : "A Node-RED node that looks for SNMP oids.",
|
"description" : "A Node-RED node that looks for SNMP oids.",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"net-snmp" : "^1.1.19"
|
"net-snmp" : "^1.1.19"
|
||||||
|
@ -9,10 +9,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-version"><i class="fa fa-bookmark"></i> Version</label>
|
<label for="node-input-version"><i class="fa fa-bookmark"></i> Version</label>
|
||||||
<select type="text" id="node-input-version" style="width: 150px;">
|
<select type="text" id="node-input-version" style="width:150px;">
|
||||||
<option value="1">v1</option>
|
<option value="1">v1</option>
|
||||||
<option value="2c">v2c</option>
|
<option value="2c">v2c</option>
|
||||||
</select>
|
</select>
|
||||||
|
<span style="margin-left:50px;">Timeout</span>
|
||||||
|
<input type="text" id="node-input-timeout" placeholder="secs" style="width:50px; direction:rtl; vertical-align:baseline;"> S
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-oids"><i class="fa fa-tags"></i> OIDs</label>
|
<label for="node-input-oids"><i class="fa fa-tags"></i> OIDs</label>
|
||||||
@ -42,6 +44,7 @@
|
|||||||
community: { value: "public" },
|
community: { value: "public" },
|
||||||
version: { value: "1", required: true },
|
version: { value: "1", required: true },
|
||||||
oids: { value: "" },
|
oids: { value: "" },
|
||||||
|
timeout: { value: 5 },
|
||||||
name: { value: "" }
|
name: { value: "" }
|
||||||
},
|
},
|
||||||
inputs: 1,
|
inputs: 1,
|
||||||
@ -72,6 +75,8 @@
|
|||||||
<option value="1">v1</option>
|
<option value="1">v1</option>
|
||||||
<option value="2c">v2c</option>
|
<option value="2c">v2c</option>
|
||||||
</select>
|
</select>
|
||||||
|
<span style="margin-left:50px;">Timeout</span>
|
||||||
|
<input type="text" id="node-input-timeout" placeholder="secs" style="width:50px; direction:rtl; vertical-align:baseline;"> S
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-varbinds"><i class="fa fa-tags"></i> Varbinds</label>
|
<label for="node-input-varbinds"><i class="fa fa-tags"></i> Varbinds</label>
|
||||||
@ -140,6 +145,8 @@
|
|||||||
<option value="1">v1</option>
|
<option value="1">v1</option>
|
||||||
<option value="2c">v2c</option>
|
<option value="2c">v2c</option>
|
||||||
</select>
|
</select>
|
||||||
|
<span style="margin-left:50px;">Timeout</span>
|
||||||
|
<input type="text" id="node-input-timeout" placeholder="secs" style="width:50px; direction:rtl; vertical-align:baseline;"> S
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-oids"><i class="fa fa-tags"></i> OID</label>
|
<label for="node-input-oids"><i class="fa fa-tags"></i> OID</label>
|
||||||
@ -169,6 +176,7 @@
|
|||||||
community: { value: "public" },
|
community: { value: "public" },
|
||||||
version: { value: "1", required: true },
|
version: { value: "1", required: true },
|
||||||
oids: { value: "" },
|
oids: { value: "" },
|
||||||
|
timeout: { value: 5 },
|
||||||
name: { value: "" }
|
name: { value: "" }
|
||||||
},
|
},
|
||||||
inputs: 1,
|
inputs: 1,
|
||||||
@ -199,6 +207,8 @@
|
|||||||
<option value="1">v1</option>
|
<option value="1">v1</option>
|
||||||
<option value="2c">v2c</option>
|
<option value="2c">v2c</option>
|
||||||
</select>
|
</select>
|
||||||
|
<span style="margin-left:50px;">Timeout</span>
|
||||||
|
<input type="text" id="node-input-timeout" placeholder="secs" style="width:50px; direction:rtl; vertical-align:baseline;"> S
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-oids"><i class="fa fa-tags"></i> OID</label>
|
<label for="node-input-oids"><i class="fa fa-tags"></i> OID</label>
|
||||||
@ -228,6 +238,7 @@
|
|||||||
community: { value: "public" },
|
community: { value: "public" },
|
||||||
version: { value: "1", required: true },
|
version: { value: "1", required: true },
|
||||||
oids: { value: "" },
|
oids: { value: "" },
|
||||||
|
timeout: { value: 5 },
|
||||||
name: { value: "" }
|
name: { value: "" }
|
||||||
},
|
},
|
||||||
inputs: 1,
|
inputs: 1,
|
||||||
@ -260,6 +271,8 @@
|
|||||||
<option value="1">v1</option>
|
<option value="1">v1</option>
|
||||||
<option value="2c">v2c</option>
|
<option value="2c">v2c</option>
|
||||||
</select>
|
</select>
|
||||||
|
<span style="margin-left:50px;">Timeout</span>
|
||||||
|
<input type="text" id="node-input-timeout" placeholder="secs" style="width:50px; direction:rtl; vertical-align:baseline;"> S
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-oids"><i class="fa fa-tags"></i> OID</label>
|
<label for="node-input-oids"><i class="fa fa-tags"></i> OID</label>
|
||||||
@ -289,6 +302,7 @@
|
|||||||
community: { value: "public" },
|
community: { value: "public" },
|
||||||
version: { value: "1", required: true },
|
version: { value: "1", required: true },
|
||||||
oids: { value: "" },
|
oids: { value: "" },
|
||||||
|
timeout: { value: 5 },
|
||||||
name: { value: "" }
|
name: { value: "" }
|
||||||
},
|
},
|
||||||
inputs: 1,
|
inputs: 1,
|
||||||
|
@ -5,10 +5,10 @@ module.exports = function (RED) {
|
|||||||
|
|
||||||
var sessions = {};
|
var sessions = {};
|
||||||
|
|
||||||
function getSession(host, community, version) {
|
function getSession(host, community, version, timeout) {
|
||||||
var sessionKey = host + ":" + community + ":" + version;
|
var sessionKey = host + ":" + community + ":" + version;
|
||||||
if (!(sessionKey in sessions)) {
|
if (!(sessionKey in sessions)) {
|
||||||
sessions[sessionKey] = snmp.createSession(host, community, { version: version });
|
sessions[sessionKey] = snmp.createSession(host, community, { version:version, timeout:(timeout || 5000) });
|
||||||
}
|
}
|
||||||
return sessions[sessionKey];
|
return sessions[sessionKey];
|
||||||
}
|
}
|
||||||
@ -19,6 +19,7 @@ module.exports = function (RED) {
|
|||||||
this.host = n.host;
|
this.host = n.host;
|
||||||
this.version = (n.version === "2c") ? snmp.Version2c : snmp.Version1;
|
this.version = (n.version === "2c") ? snmp.Version2c : snmp.Version1;
|
||||||
this.oids = n.oids.replace(/\s/g, "");
|
this.oids = n.oids.replace(/\s/g, "");
|
||||||
|
this.timeout = Number(n.timeout || 5) * 1000;
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
this.on("input", function (msg) {
|
this.on("input", function (msg) {
|
||||||
@ -26,7 +27,7 @@ module.exports = function (RED) {
|
|||||||
var community = node.community || msg.community;
|
var community = node.community || msg.community;
|
||||||
var oids = node.oids || msg.oid;
|
var oids = node.oids || msg.oid;
|
||||||
if (oids) {
|
if (oids) {
|
||||||
getSession(host, community, node.version).get(oids.split(","), function (error, varbinds) {
|
getSession(host, community, node.version, node.timeout).get(oids.split(","), function (error, varbinds) {
|
||||||
if (error) {
|
if (error) {
|
||||||
node.error(error.toString(), msg);
|
node.error(error.toString(), msg);
|
||||||
}
|
}
|
||||||
@ -54,13 +55,13 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
RED.nodes.registerType("snmp", SnmpNode);
|
RED.nodes.registerType("snmp", SnmpNode);
|
||||||
|
|
||||||
|
|
||||||
function SnmpSNode(n) {
|
function SnmpSNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
this.community = n.community;
|
this.community = n.community;
|
||||||
this.host = n.host;
|
this.host = n.host;
|
||||||
this.version = (n.version === "2c") ? snmp.Version2c : snmp.Version1;
|
this.version = (n.version === "2c") ? snmp.Version2c : snmp.Version1;
|
||||||
this.varbinds = n.varbinds;
|
this.varbinds = n.varbinds;
|
||||||
|
this.timeout = Number(n.timeout || 5) * 1000;
|
||||||
var node = this;
|
var node = this;
|
||||||
this.on("input", function (msg) {
|
this.on("input", function (msg) {
|
||||||
var host = node.host || msg.host;
|
var host = node.host || msg.host;
|
||||||
@ -70,7 +71,7 @@ module.exports = function (RED) {
|
|||||||
for (var i = 0; i < varbinds.length; i++) {
|
for (var i = 0; i < varbinds.length; i++) {
|
||||||
varbinds[i].type = snmp.ObjectType[varbinds[i].type];
|
varbinds[i].type = snmp.ObjectType[varbinds[i].type];
|
||||||
}
|
}
|
||||||
getSession(host, community, node.version).set(varbinds, function (error, varbinds) {
|
getSession(host, community, node.version, node.timeout).set(varbinds, function (error, varbinds) {
|
||||||
if (error) {
|
if (error) {
|
||||||
node.error(error.toString(), msg);
|
node.error(error.toString(), msg);
|
||||||
}
|
}
|
||||||
@ -93,14 +94,13 @@ module.exports = function (RED) {
|
|||||||
RED.nodes.registerType("snmp set", SnmpSNode);
|
RED.nodes.registerType("snmp set", SnmpSNode);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function SnmpTNode(n) {
|
function SnmpTNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
this.community = n.community;
|
this.community = n.community;
|
||||||
this.host = n.host;
|
this.host = n.host;
|
||||||
this.version = (n.version === "2c") ? snmp.Version2c : snmp.Version1;
|
this.version = (n.version === "2c") ? snmp.Version2c : snmp.Version1;
|
||||||
this.oids = n.oids.replace(/\s/g, "");
|
this.oids = n.oids.replace(/\s/g, "");
|
||||||
|
this.timeout = Number(n.timeout || 5) * 1000;
|
||||||
var node = this;
|
var node = this;
|
||||||
var maxRepetitions = 20;
|
var maxRepetitions = 20;
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ module.exports = function (RED) {
|
|||||||
var oids = node.oids || msg.oid;
|
var oids = node.oids || msg.oid;
|
||||||
if (oids) {
|
if (oids) {
|
||||||
msg.oid = oids;
|
msg.oid = oids;
|
||||||
getSession(host, community, node.version).table(oids, maxRepetitions, function (error, table) {
|
getSession(host, community, node.version, node.timeout).table(oids, maxRepetitions, function (error, table) {
|
||||||
if (error) {
|
if (error) {
|
||||||
node.error(error.toString(), msg);
|
node.error(error.toString(), msg);
|
||||||
}
|
}
|
||||||
@ -153,12 +153,14 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
RED.nodes.registerType("snmp table", SnmpTNode);
|
RED.nodes.registerType("snmp table", SnmpTNode);
|
||||||
|
|
||||||
|
|
||||||
function SnmpSubtreeNode(n) {
|
function SnmpSubtreeNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
this.community = n.community;
|
this.community = n.community;
|
||||||
this.host = n.host;
|
this.host = n.host;
|
||||||
this.version = (n.version === "2c") ? snmp.Version2c : snmp.Version1;
|
this.version = (n.version === "2c") ? snmp.Version2c : snmp.Version1;
|
||||||
this.oids = n.oids.replace(/\s/g, "");
|
this.oids = n.oids.replace(/\s/g, "");
|
||||||
|
this.timeout = Number(n.timeout || 5) * 1000;
|
||||||
var node = this;
|
var node = this;
|
||||||
var maxRepetitions = 20;
|
var maxRepetitions = 20;
|
||||||
var response = [];
|
var response = [];
|
||||||
@ -181,7 +183,7 @@ module.exports = function (RED) {
|
|||||||
var oids = node.oids || msg.oid;
|
var oids = node.oids || msg.oid;
|
||||||
if (oids) {
|
if (oids) {
|
||||||
msg.oid = oids;
|
msg.oid = oids;
|
||||||
getSession(host, community, node.version).subtree(msg.oid, maxRepetitions, feedCb, function (error) {
|
getSession(host, community, node.version, node.timeout).subtree(msg.oid, maxRepetitions, feedCb, function (error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
node.error(error.toString(), msg);
|
node.error(error.toString(), msg);
|
||||||
}
|
}
|
||||||
@ -200,12 +202,14 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
RED.nodes.registerType("snmp subtree", SnmpSubtreeNode);
|
RED.nodes.registerType("snmp subtree", SnmpSubtreeNode);
|
||||||
|
|
||||||
|
|
||||||
function SnmpWalkerNode(n) {
|
function SnmpWalkerNode(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
this.community = n.community;
|
this.community = n.community;
|
||||||
this.host = n.host;
|
this.host = n.host;
|
||||||
this.version = (n.version === "2c") ? snmp.Version2c : snmp.Version1;
|
this.version = (n.version === "2c") ? snmp.Version2c : snmp.Version1;
|
||||||
this.oids = n.oids.replace(/\s/g, "");
|
this.oids = n.oids.replace(/\s/g, "");
|
||||||
|
this.timeout = Number(n.timeout || 5) * 1000;
|
||||||
var node = this;
|
var node = this;
|
||||||
var maxRepetitions = 20;
|
var maxRepetitions = 20;
|
||||||
var response = [];
|
var response = [];
|
||||||
@ -229,7 +233,7 @@ module.exports = function (RED) {
|
|||||||
var community = node.community || msg.community;
|
var community = node.community || msg.community;
|
||||||
if (oids) {
|
if (oids) {
|
||||||
msg.oid = oids;
|
msg.oid = oids;
|
||||||
getSession(host, community, node.version).walk(msg.oid, maxRepetitions, feedCb, function (error) {
|
getSession(host, community, node.version, node.timeout).walk(msg.oid, maxRepetitions, feedCb, function (error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
node.error(error.toString(), msg);
|
node.error(error.toString(), msg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user