Skip to content

Commit 041342d

Browse files
authored
better inplace upgrade of pre v1 (#908)
fixes #907
1 parent c77f13a commit 041342d

3 files changed

Lines changed: 42 additions & 27 deletions

File tree

io/snmp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "node-red-node-snmp",
3-
"version" : "1.0.0",
3+
"version" : "1.0.1",
44
"description" : "A Node-RED node that gets and sets SNMP oid values. Supports v1, v2c and v3",
55
"dependencies" : {
66
"net-snmp" : "^3.6.3"

io/snmp/snmp.html

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
<script type="text/javascript" id="node-red-node-snmp-common-script">
1313
const node_snmp_common = {
1414
oneditprepare: function (node) {
15+
const compat = { "v1": "1", "v2": "2c", "v2c": "2c", "v3": "3" };
16+
if(compat[node.version]) {
17+
node.version = compat[node.version];
18+
} else if(["1","2c","3"].indexOf(node.version) < 0) {
19+
node.version = "1";
20+
}
1521
$("#node-input-version").on("change", function(evt) {
16-
const isV3 = $("#node-input-version").val() === "v3";
22+
const isV3 = $("#node-input-version").val() === "3";
1723
$(".form-row-snmpv1v2").toggleClass("hidden", isV3);
1824
$(".form-row-snmpv3").toggleClass("hidden", !isV3);
1925
$("#node-input-auth").trigger("change");
2026
});
2127
$("#node-input-auth").on("change", function(evt) {
22-
const isV3 = $("#node-input-version").val() === "v3";
28+
const isV3 = $("#node-input-version").val() === "3";
2329
const auth = $("#node-input-auth").val();
2430
if(isV3) {
2531
switch (auth) {
@@ -38,6 +44,10 @@
3844
}
3945
}
4046
});
47+
$("#node-input-version").val(node.version);
48+
if(!$("#node-input-auth").val()) {
49+
$("#node-input-auth").val("noAuthNoPriv");
50+
}
4151
$("#node-input-version").trigger("change");
4252
}
4353
}
@@ -50,9 +60,9 @@
5060
<div class="form-row">
5161
<label for="node-input-version"><i class="fa fa-bookmark"></i> Version</label>
5262
<select type="text" id="node-input-version" style="width:150px;">
53-
<option value="v1">v1</option>
54-
<option value="v2c">v2c</option>
55-
<option value="v3">v3</option>
63+
<option value="1">v1</option>
64+
<option value="2c">v2c</option>
65+
<option value="3">v3</option>
5666
</select>
5767
<span style="margin-left:50px;">Timeout</span>
5868
<input type="text" id="node-input-timeout" placeholder="secs" style="width:50px; direction:rtl; vertical-align:baseline;">&nbsp;S
@@ -126,7 +136,7 @@
126136
color: "YellowGreen",
127137
defaults: {
128138
host: { value: "127.0.0.1" },
129-
version: { value: "v1", required: true },
139+
version: { value: "1", required: true },
130140
timeout: { value: 5 },
131141
community: { value: "public" },
132142
auth: { value: "noAuthNoPriv", required: true },
@@ -163,10 +173,10 @@
163173
<div class="form-row">
164174
<label for="node-input-version"><i class="fa fa-bookmark"></i> Version</label>
165175
<select type="text" id="node-input-version" style="width:150px;">
166-
<option value="v1">v1</option>
167-
<option value="v2c">v2c</option>
176+
<option value="1">v1</option>
177+
<option value="2c">v2c</option>
168178
<!-- Following Data is used for V3 Only -->
169-
<option value="v3">v3</option>
179+
<option value="3">v3</option>
170180
<!-- End of unique data for V3 -->
171181
</select>
172182
<span style="margin-left:50px;">Timeout</span>
@@ -251,7 +261,7 @@
251261
color: "YellowGreen",
252262
defaults: {
253263
host: { value: "127.0.0.1" },
254-
version: { value: "v1", required: true },
264+
version: { value: "1", required: true },
255265
timeout: { value: 5 },
256266
community: { value: "public" },
257267
auth: { value: "noAuthNoPriv", required: true },
@@ -295,10 +305,10 @@
295305
<div class="form-row">
296306
<label for="node-input-version"><i class="fa fa-bookmark"></i> Version</label>
297307
<select type="text" id="node-input-version" style="width:150px;">
298-
<option value="v1">v1</option>
299-
<option value="v2c">v2c</option>
308+
<option value="1">v1</option>
309+
<option value="2c">v2c</option>
300310
<!-- Following Data is used for V3 Only -->
301-
<option value="v3">v3</option>
311+
<option value="3">v3</option>
302312
<!-- End of unique data for V3 -->
303313
</select>
304314
<span style="margin-left:50px;">Timeout</span>
@@ -373,7 +383,7 @@
373383
color: "YellowGreen",
374384
defaults: {
375385
host: { value: "127.0.0.1" },
376-
version: { value: "v1", required: true },
386+
version: { value: "1", required: true },
377387
timeout: { value: 5 },
378388
community: { value: "public" },
379389
auth: { value: "noAuthNoPriv", required: true },
@@ -410,10 +420,10 @@
410420
<div class="form-row">
411421
<label for="node-input-version"><i class="fa fa-bookmark"></i> Version</label>
412422
<select type="text" id="node-input-version" style="width:150px;">
413-
<option value="v1">v1</option>
414-
<option value="v2c">v2c</option>
423+
<option value="1">v1</option>
424+
<option value="2c">v2c</option>
415425
<!-- Following Data is used for V3 Only -->
416-
<option value="v3">v3</option>
426+
<option value="3">v3</option>
417427
<!-- End of unique data for V3 -->
418428
</select>
419429
<span style="margin-left:50px;">Timeout</span>
@@ -488,7 +498,7 @@
488498
color: "YellowGreen",
489499
defaults: {
490500
host: { value: "127.0.0.1" },
491-
version: { value: "v1", required: true },
501+
version: { value: "1", required: true },
492502
timeout: { value: 5 },
493503
community: { value: "public" },
494504
auth: { value: "noAuthNoPriv", required: true },
@@ -526,10 +536,10 @@
526536
<div class="form-row">
527537
<label for="node-input-version"><i class="fa fa-bookmark"></i> Version</label>
528538
<select type="text" id="node-input-version" style="width:150px;">
529-
<option value="v1">v1</option>
530-
<option value="v2c">v2c</option>
539+
<option value="1">v1</option>
540+
<option value="2c">v2c</option>
531541
<!-- Following Data is used for V3 Only -->
532-
<option value="v3">v3</option>
542+
<option value="3">v3</option>
533543
<!-- End of unique data for V3 -->
534544
</select>
535545
<span style="margin-left:50px;">Timeout</span>
@@ -607,7 +617,7 @@
607617
color: "YellowGreen",
608618
defaults: {
609619
host: { value: "127.0.0.1" },
610-
version: { value: "v1", required: true },
620+
version: { value: "1", required: true },
611621
timeout: { value: 5 },
612622
community: { value: "public" },
613623
auth: { value: "noAuthNoPriv", required: true },

io/snmp/snmp.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,20 @@ module.exports = function (RED) {
6161
const sessionid = generateUUID();
6262
const user = {}
6363
const options = {};
64-
64+
const compat = { "v1": "1", "v2": "2c", "v2c": "2c", "v3": "3" };
65+
if(compat[node.version]) {
66+
node.version = compat[node.version];
67+
} else if(["1","2c","3"].indexOf(node.version) < 0) {
68+
node.version = "1";
69+
}
6570
options.version = node.version;
66-
if (node.version === "v1") {
71+
if (node.version === "1") {
6772
options.version = SNMP.Version1;
6873
user.community = node.community || msg.community;
69-
} else if (node.version === "v2c") {
74+
} else if (node.version === "2c") {
7075
options.version = SNMP.Version2c;
7176
user.community = node.community || msg.community;
72-
} else if (node.version === "v3") {
77+
} else if (node.version === "3") {
7378
user.name = node.username || msg.username || "";
7479
user.level = SNMP.SecurityLevel.noAuthNoPriv;
7580
user.authProtocol = SNMP.AuthProtocols.none;

0 commit comments

Comments
 (0)