net-snmp 3.4.2 → 3.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +7 -16
- package/README.md +47 -6
- package/example/option-parser.js +5 -5
- package/example/snmp-receiver.js +5 -2
- package/example/test.js +52 -19
- package/index.js +16 -5
- package/lib/mib.js +4 -1
- package/package.json +1 -1
- package/test/snmp-test.sh +3 -3
package/.vscode/launch.json
CHANGED
@@ -127,14 +127,14 @@
|
|
127
127
|
],
|
128
128
|
"program": "${workspaceFolder}/example/snmp-trap.js",
|
129
129
|
"args": [
|
130
|
-
"-e", "
|
130
|
+
"-e", "0x010203040a",
|
131
131
|
"-v", "3",
|
132
|
-
"-u", "
|
132
|
+
"-u", "barney",
|
133
133
|
"-l", "authPriv",
|
134
|
-
"-a", "
|
135
|
-
"-A", "
|
136
|
-
"-x", "
|
137
|
-
"-X", "
|
134
|
+
"-a", "sha",
|
135
|
+
"-A", "illhavesomeauth",
|
136
|
+
"-x", "aes",
|
137
|
+
"-X", "andsomepriv",
|
138
138
|
"127.0.0.1",
|
139
139
|
"1.3.6.1.6.3.1.1.5.1"
|
140
140
|
]
|
@@ -259,16 +259,7 @@
|
|
259
259
|
],
|
260
260
|
"program": "${workspaceFolder}/example/test.js",
|
261
261
|
"args": [
|
262
|
-
"-
|
263
|
-
"-v", "3",
|
264
|
-
"-l", "authPriv",
|
265
|
-
"-u", "test256",
|
266
|
-
"-a", "sha",
|
267
|
-
"-A", "maybeitsok",
|
268
|
-
"-x", "aes256b",
|
269
|
-
"-X", "maybeitsok",
|
270
|
-
"127.0.0.1",
|
271
|
-
"1.3.6.1.2.1.1.1.0"
|
262
|
+
"-p", "1161"
|
272
263
|
]
|
273
264
|
},
|
274
265
|
{
|
package/README.md
CHANGED
@@ -292,7 +292,7 @@ The Agent Extensibility (AgentX) Protocol specifies these PDUs in RFC 2741:
|
|
292
292
|
- `3 - read-write`
|
293
293
|
- `4 - read-create`
|
294
294
|
|
295
|
-
|
295
|
+
## snmp.RowStatus
|
296
296
|
Status values
|
297
297
|
- `1 - active`
|
298
298
|
- `2 - notInService`
|
@@ -303,6 +303,21 @@ Actions
|
|
303
303
|
- `5 - createAndWait`
|
304
304
|
- `6 - destroy`
|
305
305
|
|
306
|
+
## snmp.ResponseInvalidCode
|
307
|
+
- `1 - EIp4AddressSize`
|
308
|
+
- `2 - EUnknownObjectType`
|
309
|
+
- `3 - EUnknownPduType`
|
310
|
+
- `4 - ECouldNotDecrypt`
|
311
|
+
- `5 - EAuthFailure`
|
312
|
+
- `6 - EReqResOidNoMatch`
|
313
|
+
- `7 - ENonRepeaterCountMismatch`
|
314
|
+
- `8 - EOutOfOrder`
|
315
|
+
- `9 - EVersionNoMatch`
|
316
|
+
- `10 - ECommunityNoMatch`
|
317
|
+
- `11 - EUnexpectedReport`
|
318
|
+
- `12 - EResponseNotHandled`
|
319
|
+
- `13 - EUnexpectedResponse`
|
320
|
+
|
306
321
|
# OID Strings & Varbinds
|
307
322
|
|
308
323
|
Some parts of this module accept simple OID strings, e.g.:
|
@@ -376,7 +391,7 @@ function responseCb (error, varbinds) {
|
|
376
391
|
}
|
377
392
|
```
|
378
393
|
|
379
|
-
When defined, the error parameter is always an instance of the `Error` class,
|
394
|
+
When defined, the `error` parameter is always an instance of the `Error` class,
|
380
395
|
or a sub-class described in one of the sub-sections contained in this section.
|
381
396
|
|
382
397
|
The semantics of error handling is slightly different between SNMP version
|
@@ -485,8 +500,17 @@ exposed `message` attribute will contain the value `Request timed out`.
|
|
485
500
|
|
486
501
|
## snmp.ResponseInvalidError
|
487
502
|
|
488
|
-
This error indicates a failure to parse a response message.
|
489
|
-
`message` attribute will contain a detailed error message
|
503
|
+
This error indicates a failure to parse a response message. The
|
504
|
+
exposed `message` attribute will contain a detailed error message, and
|
505
|
+
as a sub-class of Error, its `toString()` method will yield that
|
506
|
+
`message` attribute.
|
507
|
+
|
508
|
+
An error of this class will always additionally include a `code`
|
509
|
+
attribute (one of the values in `ResponseInvalidCode`); and in some
|
510
|
+
cases, also have an `info` attribute which provides `code`-specific
|
511
|
+
supplemental information. An authentication error, for example -- code
|
512
|
+
`ResponseInvalidCode.EAuthFailure` -- will contain a map in `info`
|
513
|
+
with the attempted authentication data which failed to authenticate.
|
490
514
|
|
491
515
|
# Using This Module: Command & Notification Generator
|
492
516
|
|
@@ -567,6 +591,7 @@ var options = {
|
|
567
591
|
transport: "udp4",
|
568
592
|
trapPort: 162,
|
569
593
|
version: snmp.Version3,
|
594
|
+
engineID: "8000B98380XXXXXXXXXXXXXXXXXXXXXXXX", // where the X's are random hex digits
|
570
595
|
idBitsSize: 32,
|
571
596
|
context: ""
|
572
597
|
};
|
@@ -1428,7 +1453,7 @@ var options = {
|
|
1428
1453
|
port: 162,
|
1429
1454
|
disableAuthorization: false,
|
1430
1455
|
accessControlModelType: snmp.AccessControlModelType.None,
|
1431
|
-
engineID: "
|
1456
|
+
engineID: "8000B98380XXXXXXXXXXXXXXXXXXXXXXXX", // where the X's are random hex digits
|
1432
1457
|
address: null,
|
1433
1458
|
transport: "udp4"
|
1434
1459
|
};
|
@@ -1538,7 +1563,7 @@ var options = {
|
|
1538
1563
|
port: 161,
|
1539
1564
|
disableAuthorization: false,
|
1540
1565
|
accessControlModelType: snmp.AccessControlModelType.None,
|
1541
|
-
engineID: "
|
1566
|
+
engineID: "8000B98380XXXXXXXXXXXXXXXXXXXXXXXX", // where the X's are random hex digits
|
1542
1567
|
address: null,
|
1543
1568
|
transport: "udp4"
|
1544
1569
|
};
|
@@ -3101,6 +3126,22 @@ Example programs are included under the module's `example` directory.
|
|
3101
3126
|
|
3102
3127
|
* Add error codes to ResponseInvalidError
|
3103
3128
|
|
3129
|
+
## Version 3.4.3 - 06/02/2021
|
3130
|
+
|
3131
|
+
* Add documentation for ResponseInvalidError error codes
|
3132
|
+
|
3133
|
+
## Version 3.5.0 - 28/02/2021
|
3134
|
+
|
3135
|
+
* Add engineID option to v3 session
|
3136
|
+
|
3137
|
+
## Version 3.5.1 - 28/02/2021
|
3138
|
+
|
3139
|
+
* Fix MIB parsing of sized integers without whitespace
|
3140
|
+
|
3141
|
+
## Version 3.5.2 - 02/03/2021
|
3142
|
+
|
3143
|
+
* Fix MIB table index handling of Buffer type
|
3144
|
+
|
3104
3145
|
# License
|
3105
3146
|
|
3106
3147
|
Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
|
package/example/option-parser.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
var snmp = require ("../");
|
2
2
|
var getopts = require ("getopts");
|
3
3
|
|
4
|
-
var options = getopts(process.argv.slice(2)
|
4
|
+
var options = getopts(process.argv.slice(2), {
|
5
|
+
string: ["e"]
|
6
|
+
});
|
5
7
|
var community;
|
6
8
|
var user;
|
7
9
|
var session;
|
@@ -20,14 +22,12 @@ snmpOptions.version = snmp.Version[options.v];
|
|
20
22
|
snmpOptions.debug = options.d;
|
21
23
|
snmpOptions.transport = options.t;
|
22
24
|
if ( snmpOptions.version == snmp.Version3 ) {
|
23
|
-
var engineID;
|
24
25
|
if ( options.e ) {
|
25
|
-
engineID =
|
26
|
+
snmpOptions.engineID = options.e.toString();
|
26
27
|
}
|
27
28
|
user = {
|
28
29
|
name: options.u,
|
29
|
-
level: snmp.SecurityLevel[options.l]
|
30
|
-
engineID: engineID
|
30
|
+
level: snmp.SecurityLevel[options.l]
|
31
31
|
};
|
32
32
|
if ( options.a ) {
|
33
33
|
user.authProtocol = snmp.AuthProtocols[options.a.toLowerCase()];
|
package/example/snmp-receiver.js
CHANGED
@@ -6,6 +6,7 @@ var verbose = options.v;
|
|
6
6
|
var snmpOptions = {
|
7
7
|
disableAuthorization: options.n,
|
8
8
|
port: options.p,
|
9
|
+
transport: options.t,
|
9
10
|
engineID: options.e
|
10
11
|
};
|
11
12
|
|
@@ -22,8 +23,10 @@ var cb = function(error, trap) {
|
|
22
23
|
} else {
|
23
24
|
if (trap.pdu.type == snmp.PduType.Trap ) {
|
24
25
|
console.log (now + ": " + trapType + ": " + trap.rinfo.address + " : " + trap.pdu.enterprise);
|
25
|
-
|
26
|
-
|
26
|
+
} else {
|
27
|
+
for (var i = 0; i < trap.pdu.varbinds.length; i++) {
|
28
|
+
console.log (now + ": " + trapType + ": " + trap.rinfo.address + " : " + trap.pdu.varbinds[i].oid + " -> " + trap.pdu.varbinds[i].value);
|
29
|
+
}
|
27
30
|
}
|
28
31
|
}
|
29
32
|
}
|
package/example/test.js
CHANGED
@@ -1,21 +1,54 @@
|
|
1
|
-
|
2
|
-
// Copyright 2013 Stephen Vickers
|
1
|
+
/* eslint-disable no-unused-vars */
|
3
2
|
|
4
3
|
var snmp = require ("../");
|
5
|
-
var
|
6
|
-
|
7
|
-
var
|
8
|
-
var
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
4
|
+
var getopts = require ("getopts");
|
5
|
+
|
6
|
+
var options = getopts(process.argv.slice(2));
|
7
|
+
var providers;
|
8
|
+
var mibDir = '/var/tmp/mibs/';
|
9
|
+
|
10
|
+
var counter64 = function (num) {
|
11
|
+
var buf = Buffer.alloc (4);
|
12
|
+
buf.writeUInt32BE (num);
|
13
|
+
return buf;
|
14
|
+
};
|
15
|
+
|
16
|
+
var snmpOptions = {
|
17
|
+
disableAuthorization: options.n,
|
18
|
+
port: options.p,
|
19
|
+
engineID: options.e,
|
20
|
+
debug: options.d
|
21
|
+
};
|
22
|
+
|
23
|
+
var callback = function (error, data) {
|
24
|
+
if ( error ) {
|
25
|
+
console.error (error);
|
26
|
+
} else {
|
27
|
+
console.log (data.pdu.varbinds[0].oid);
|
28
|
+
}
|
29
|
+
};
|
30
|
+
|
31
|
+
var store = snmp.createModuleStore ();
|
32
|
+
var agent = snmp.createAgent (snmpOptions, callback);
|
33
|
+
var mib = agent.getMib ();
|
34
|
+
|
35
|
+
var authorizer = agent.getAuthorizer ();
|
36
|
+
authorizer.addCommunity ("public");
|
37
|
+
|
38
|
+
// IF-MIB load and providers registration
|
39
|
+
store.loadFromFile (mibDir + "IPv6-TC.mib");
|
40
|
+
store.loadFromFile (mibDir + "IPv6-MIB.mib");
|
41
|
+
providers = store.getProvidersForModule ("IPV6-MIB");
|
42
|
+
mib.registerProviders (providers);
|
43
|
+
|
44
|
+
// agent.getMib ().dumpProviders ();
|
45
|
+
|
46
|
+
// mib.dump ();
|
47
|
+
|
48
|
+
var modules = store.getModules (true);
|
49
|
+
var one = store.getModule ("IPV6-MIB");
|
50
|
+
var names = store.getModuleNames (true);
|
51
|
+
|
52
|
+
// console.log("All modules: ", JSON.stringify(modules, '', 2));
|
53
|
+
console.log("Modules: ", names);
|
54
|
+
console.log("Single module definition: ", JSON.stringify(one, '', 2));
|
package/index.js
CHANGED
@@ -1812,7 +1812,7 @@ var Session = function (target, authenticator, options) {
|
|
1812
1812
|
|
1813
1813
|
DEBUG = options.debug;
|
1814
1814
|
|
1815
|
-
this.engine = new Engine ();
|
1815
|
+
this.engine = new Engine (options.engineID);
|
1816
1816
|
this.reqs = {};
|
1817
1817
|
this.reqCount = 0;
|
1818
1818
|
|
@@ -2586,7 +2586,7 @@ Session.prototype.trap = function () {
|
|
2586
2586
|
|
2587
2587
|
if ( this.version == Version3 ) {
|
2588
2588
|
var msgSecurityParameters = {
|
2589
|
-
msgAuthoritativeEngineID: this.
|
2589
|
+
msgAuthoritativeEngineID: this.engine.engineID,
|
2590
2590
|
msgAuthoritativeEngineBoots: 0,
|
2591
2591
|
msgAuthoritativeEngineTime: 0
|
2592
2592
|
};
|
@@ -2777,7 +2777,12 @@ Session.createV3 = function (target, user, options) {
|
|
2777
2777
|
|
2778
2778
|
var Engine = function (engineID, engineBoots, engineTime) {
|
2779
2779
|
if ( engineID ) {
|
2780
|
-
|
2780
|
+
if ( ! (engineID instanceof Buffer) ) {
|
2781
|
+
engineID = engineID.replace('0x', '');
|
2782
|
+
this.engineID = Buffer.from((engineID.toString().length % 2 == 1 ? '0' : '') + engineID.toString(), 'hex');
|
2783
|
+
} else {
|
2784
|
+
this.engineID = engineID;
|
2785
|
+
}
|
2781
2786
|
} else {
|
2782
2787
|
this.generateEngineID ();
|
2783
2788
|
}
|
@@ -2787,7 +2792,7 @@ var Engine = function (engineID, engineBoots, engineTime) {
|
|
2787
2792
|
|
2788
2793
|
Engine.prototype.generateEngineID = function() {
|
2789
2794
|
// generate a 17-byte engine ID in the following format:
|
2790
|
-
// 0x80
|
2795
|
+
// 0x80 | 0x00B983 (enterprise OID) | 0x80 (enterprise-specific format) | 12 bytes of random
|
2791
2796
|
this.engineID = Buffer.alloc (17);
|
2792
2797
|
this.engineID.fill ('8000B98380', 'hex', 0, 5);
|
2793
2798
|
this.engineID.fill (crypto.randomBytes (12), 5, 17, 'hex');
|
@@ -4076,7 +4081,13 @@ Mib.prototype.getOidAddressFromValue = function (value, indexPart) {
|
|
4076
4081
|
oidComponents = value.split (".");
|
4077
4082
|
break;
|
4078
4083
|
case ObjectType.OctetString:
|
4079
|
-
|
4084
|
+
if ( value instanceof Buffer ) {
|
4085
|
+
// Buffer
|
4086
|
+
oidComponents = Array.prototype.slice.call (value);
|
4087
|
+
} else {
|
4088
|
+
// string
|
4089
|
+
oidComponents = [...value].map (c => c.charCodeAt());
|
4090
|
+
}
|
4080
4091
|
break;
|
4081
4092
|
case ObjectType.IpAddress:
|
4082
4093
|
return value.split (".");
|
package/lib/mib.js
CHANGED
@@ -168,7 +168,10 @@ var MIB = function (dir) {
|
|
168
168
|
this.CharBuffer.inGroup++;
|
169
169
|
}
|
170
170
|
}
|
171
|
-
if (this.CharBuffer.
|
171
|
+
if (this.CharBuffer.builder == 'INTEGER') {
|
172
|
+
this.CharBuffer.Fill(FileName, row, column);
|
173
|
+
this.CharBuffer.Append(char);
|
174
|
+
} else if (this.CharBuffer.isComment || ((this.CharBuffer.isOID || this.CharBuffer.nested > 0) && (!this.CharBuffer.isList || this.CharBuffer.inGroup > 0))) {
|
172
175
|
this.CharBuffer.Append(char);
|
173
176
|
} else {
|
174
177
|
this.CharBuffer.Fill(FileName, row, column);
|
package/package.json
CHANGED
package/test/snmp-test.sh
CHANGED
@@ -8,7 +8,7 @@ HOME_DIR=.
|
|
8
8
|
HOST=localhost
|
9
9
|
LEVEL=authpriv
|
10
10
|
PRINT_ONLY=0
|
11
|
-
TRAP_ENGINEID="
|
11
|
+
TRAP_ENGINEID="010203040a"
|
12
12
|
IPV6=0
|
13
13
|
CMDS=/var/tmp/snmp-test.$$
|
14
14
|
|
@@ -20,7 +20,7 @@ USER_AUTH=betty
|
|
20
20
|
USER_PRIV=barney
|
21
21
|
USER_TRAP_NONE=fred
|
22
22
|
USER_TRAP_AUTH=betty
|
23
|
-
USER_TRAP_PRIV=
|
23
|
+
USER_TRAP_PRIV=wilma
|
24
24
|
USER_SET_NONE=trapnone
|
25
25
|
USER_SET_AUTH=trapshaonly
|
26
26
|
USER_SET_PRIV=trapshades
|
@@ -99,7 +99,7 @@ node ${HOME_DIR}/example/snmp-subtree.js ${PARAMS} ${HOST} 1.3.6.1.6.3.16.1.5.2.
|
|
99
99
|
node ${HOME_DIR}/example/snmp-table.js ${PARAMS} ${HOST} 1.3.6.1.2.1.1.9
|
100
100
|
node ${HOME_DIR}/example/snmp-table-columns.js ${PARAMS} ${HOST} 1.3.6.1.2.1.2.2 2
|
101
101
|
node ${HOME_DIR}/example/snmp-set.js ${SET_PARAMS} ${HOST} 1.3.6.1.2.1.1.6.0 OctetString Auckland
|
102
|
-
node ${HOME_DIR}/example/snmp-trap.js -e ${
|
102
|
+
node ${HOME_DIR}/example/snmp-trap.js -e ${TRAP_ENGINEID} ${TRAP_PARAMS} ${HOST} 1.3.6.1.6.3.1.1.5.2
|
103
103
|
node ${HOME_DIR}/example/snmp-inform.js ${PARAMS} ${HOST} 1.3.6.1.6.3.1.1.5.2
|
104
104
|
ENDOFCMDS
|
105
105
|
|