net-snmp 3.21.0 → 3.21.1
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/README.md +4 -0
- package/example/snmp-agent-snmpv2mib.js +44 -0
- package/example/snmp-agent.js +1 -1
- package/index.js +12 -7
- package/package.json +1 -1
- package/test/mib.test.js +1 -1
package/README.md
CHANGED
@@ -3521,6 +3521,10 @@ Example programs are included under the module's `example` directory.
|
|
3521
3521
|
|
3522
3522
|
* Add AgentX subagent mib and mibOptions on initialization
|
3523
3523
|
|
3524
|
+
# Version 3.21.1 - 26/04/2025
|
3525
|
+
|
3526
|
+
* Add better defval type handling, improved debug handling and simple agent example
|
3527
|
+
|
3524
3528
|
# License
|
3525
3529
|
|
3526
3530
|
Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
const snmp = require ("..");
|
2
|
+
|
3
|
+
// Create a module store, which contains SNMPv2-MIB and other modules
|
4
|
+
const store = snmp.createModuleStore ();
|
5
|
+
|
6
|
+
// Fetch MIB providers for SNMPv2-MIB, create an agent, and register the providers with the agent's MIB
|
7
|
+
const providers = store.getProvidersForModule ("SNMPv2-MIB");
|
8
|
+
const agentOptions = {
|
9
|
+
port: 1161
|
10
|
+
};
|
11
|
+
const agentCallback = function (error, data) {
|
12
|
+
if ( error ) {
|
13
|
+
console.error (error);
|
14
|
+
} else {
|
15
|
+
console.log (JSON.stringify(data, null, 2));
|
16
|
+
}
|
17
|
+
};
|
18
|
+
const agent = snmp.createAgent ( agentOptions, agentCallback );
|
19
|
+
const mib = agent.getMib ();
|
20
|
+
mib.registerProviders (providers);
|
21
|
+
|
22
|
+
// Add community and user to agent's authorizer
|
23
|
+
const authorizer = agent.getAuthorizer ();
|
24
|
+
authorizer.addCommunity ("private");
|
25
|
+
authorizer.addUser ({
|
26
|
+
name: "wilma",
|
27
|
+
level: snmp.SecurityLevel.authPriv,
|
28
|
+
authProtocol: snmp.AuthProtocols.sha,
|
29
|
+
authKey: "illhavesomeauth",
|
30
|
+
privProtocol: snmp.PrivProtocols.aes,
|
31
|
+
privKey: "andsomepriv"
|
32
|
+
});
|
33
|
+
|
34
|
+
// Start adding data to the MIB through the registered providers using the `Mib` API calls
|
35
|
+
mib.setScalarValue ("sysDescr", "The most powerful system you can think of");
|
36
|
+
mib.setScalarValue ("sysObjectID", "1.3.6.1.4.1.8072.3.2.10");
|
37
|
+
mib.setScalarValue ("sysContact", "You");
|
38
|
+
mib.setScalarValue ("sysName", "megamind");
|
39
|
+
mib.setScalarValue ("sysLocation", "Yours");
|
40
|
+
mib.setScalarValue ("sysORLastChange", 710);
|
41
|
+
mib.addTableRow ("sysOREntry", [1, "1.3.6.1.4.1.47491.42.43.44.45", "I've dreamed up this MIB", 20]);
|
42
|
+
|
43
|
+
// Dump the resulting MIB to the console
|
44
|
+
mib.dump ();
|
package/example/snmp-agent.js
CHANGED
@@ -264,7 +264,7 @@ mib.dump ({
|
|
264
264
|
// var data = mib.getTableColumnCells ("ifTable", 2);
|
265
265
|
// var data = mib.getTableRowCells ("ifTable", [1]);
|
266
266
|
// mib.setTableSingleCell ("ifTable", 2, [2], "changed!");
|
267
|
-
mib.setTableSingleCell ("ifTable", 3, [2],
|
267
|
+
mib.setTableSingleCell ("ifTable", 3, [2], 24);
|
268
268
|
var data = mib.getTableSingleCell ("ifTable", 3, [2]);
|
269
269
|
// var data = mib.getScalarValue ("sysDescr");
|
270
270
|
|
package/index.js
CHANGED
@@ -21,9 +21,13 @@ const MAX_UNSIGNED_INT64 = 18446744073709551615;
|
|
21
21
|
|
22
22
|
const DES_IMPLEMENTATION = 'library';
|
23
23
|
|
24
|
-
|
24
|
+
// Use test harness trace or debug functions falling back to console.debug in normal mode.
|
25
|
+
// eslint-disable-next-line no-undef
|
26
|
+
var debugfn = typeof(global.debug) === 'function'? global.trace ?? global.debug : console.debug;
|
27
|
+
|
28
|
+
function debug () {
|
25
29
|
if ( DEBUG ) {
|
26
|
-
|
30
|
+
debugfn.apply (this, arguments);
|
27
31
|
}
|
28
32
|
}
|
29
33
|
|
@@ -2031,7 +2035,7 @@ var Session = function (target, authenticator, options) {
|
|
2031
2035
|
? options.reportOidMismatchErrors
|
2032
2036
|
: false;
|
2033
2037
|
|
2034
|
-
DEBUG
|
2038
|
+
DEBUG |= options.debug;
|
2035
2039
|
|
2036
2040
|
this.engine = new Engine ({
|
2037
2041
|
engineId: options.engineID
|
@@ -3348,7 +3352,7 @@ SimpleAccessControlModel.prototype.isAccessAllowed = function (securityModel, se
|
|
3348
3352
|
**/
|
3349
3353
|
|
3350
3354
|
var Receiver = function (options, callback) {
|
3351
|
-
DEBUG
|
3355
|
+
DEBUG |= options.debug;
|
3352
3356
|
this.authorizer = new Authorizer (options);
|
3353
3357
|
this.engine = new Engine ({
|
3354
3358
|
engineId: options.engineID
|
@@ -4272,7 +4276,8 @@ Mib.prototype.registerProvider = function (provider) {
|
|
4272
4276
|
if ( provider.constraints?.enumeration ) {
|
4273
4277
|
scalarValue = ObjectTypeUtil.getEnumerationNumberFromName (provider.constraints.enumeration, provider.defVal);
|
4274
4278
|
} else {
|
4275
|
-
|
4279
|
+
// Remove quotes from strings and resolve numeric strings to integers
|
4280
|
+
scalarValue = JSON.parse(provider.defVal);
|
4276
4281
|
}
|
4277
4282
|
this.setScalarValue (provider.name, scalarValue);
|
4278
4283
|
}
|
@@ -4865,7 +4870,7 @@ MibRequest.prototype.isTabular = function () {
|
|
4865
4870
|
};
|
4866
4871
|
|
4867
4872
|
var Agent = function (options, callback, mib) {
|
4868
|
-
DEBUG
|
4873
|
+
DEBUG |= options.debug;
|
4869
4874
|
this.listener = new Listener (options, this);
|
4870
4875
|
this.engine = new Engine ({
|
4871
4876
|
engineId: options.engineID
|
@@ -4986,7 +4991,7 @@ Agent.prototype.onMsg = function (socket, buffer, rinfo) {
|
|
4986
4991
|
}
|
4987
4992
|
|
4988
4993
|
// Request processing
|
4989
|
-
|
4994
|
+
debug (message.pdu);
|
4990
4995
|
if ( message.pdu.contextName && message.pdu.contextName != "" ) {
|
4991
4996
|
this.onProxyRequest (socket, message, rinfo);
|
4992
4997
|
} else if ( message.pdu.type == PduType.GetRequest ) {
|
package/package.json
CHANGED
package/test/mib.test.js
CHANGED
@@ -122,7 +122,7 @@ describe('MIB', function () {
|
|
122
122
|
};
|
123
123
|
mib = snmp.createMib(options);
|
124
124
|
mib.registerProviders(mibProviders);
|
125
|
-
assert.
|
125
|
+
assert.strictEqual(mib.getScalarValue('testScalarIntegerDefval'), 49);
|
126
126
|
});
|
127
127
|
});
|
128
128
|
|