net-snmp 3.9.9 → 3.10.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 +34 -0
- package/example/snmp-agent.js +7 -2
- package/example/test.js +9 -11
- package/index.js +103 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -83,6 +83,7 @@ for each shown in this table:
|
|
83
83
|
* SNMPv3 context support
|
84
84
|
* Notification receiver for traps and informs
|
85
85
|
* MIB parsing and MIB module store
|
86
|
+
* Translation between numeric and named OIDs
|
86
87
|
* SNMP agent with MIB management for both scalar and tabular data
|
87
88
|
* Agent table index support for non-integer keys, foreign keys, composite keys and table augmentation
|
88
89
|
* Agent support for "RowStatus" protocol-based creation and deletion of table rows
|
@@ -323,6 +324,11 @@ Actions
|
|
323
324
|
- `12 - EResponseNotHandled`
|
324
325
|
- `13 - EUnexpectedResponse`
|
325
326
|
|
327
|
+
## snmp.OidFormat
|
328
|
+
- `oid - oid`
|
329
|
+
- `path - path`
|
330
|
+
- `module - module`
|
331
|
+
|
326
332
|
# OID Strings & Varbinds
|
327
333
|
|
328
334
|
Some parts of this module accept simple OID strings, e.g.:
|
@@ -2475,6 +2481,26 @@ objects contained in the named MIB module. The list of provider definitions are
|
|
2475
2481
|
ready to be registered to an agent's MIB by using the `agent.getMib().registerProviders()`
|
2476
2482
|
call.
|
2477
2483
|
|
2484
|
+
## store.translate (oid, destinationFormat)
|
2485
|
+
|
2486
|
+
Takes an OID in one of the three supported formats (the library automatically detects the given OID's format):
|
2487
|
+
- **OidFormat.oid** - canonical (numerical) OID format e.g. 1.3.6.1.2.1.1.1
|
2488
|
+
- **OidFormat.path** - named OID path format e.g. iso.org.dod.internet.mgmt.mib-2.system.sysDescr
|
2489
|
+
- **OidFormat.module** - module-qualified format e.g. SNMPv2-MIB::sysDescr
|
2490
|
+
|
2491
|
+
Returns the given OID translated to the provided destination format - also one of the above three formats.
|
2492
|
+
|
2493
|
+
For example:
|
2494
|
+
|
2495
|
+
```js
|
2496
|
+
var numericOid = store.translate ('SNMPv2-MIB::sysDescr', snmp.OidFormat.oid);
|
2497
|
+
=> '1.3.6.1.2.1.1.1'
|
2498
|
+
var moduleQualifiedName = store.translate ('1.3.6.1.2.1.1.1', snmp.OidFormat.module);
|
2499
|
+
=> 'SNMPv2-MIB::sysDescr'
|
2500
|
+
var namedOid = store.translate ('1.3.6.1.2.1.1.1', snmp.OidFormat.path);
|
2501
|
+
=> 'iso.org.dod.internet.mgmt.mib-2.system.sysDescr'
|
2502
|
+
```
|
2503
|
+
|
2478
2504
|
# Forwarder Module
|
2479
2505
|
|
2480
2506
|
An `Agent` instance, when created, in turn creates an instance of the `Forwarder` class.
|
@@ -3313,6 +3339,14 @@ Example programs are included under the module's `example` directory.
|
|
3313
3339
|
|
3314
3340
|
* Add SMIv1 integer enumeration support
|
3315
3341
|
|
3342
|
+
## Version 3.10.0 - 17/01/2024
|
3343
|
+
|
3344
|
+
* Add numeric/named OID translate function
|
3345
|
+
|
3346
|
+
## Version 3.10.1 - 30/01/2024
|
3347
|
+
|
3348
|
+
* Fix table column type in provider definition with column type constraints
|
3349
|
+
|
3316
3350
|
# License
|
3317
3351
|
|
3318
3352
|
Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
|
package/example/snmp-agent.js
CHANGED
@@ -190,8 +190,13 @@ var tableProvider = {
|
|
190
190
|
number: 2,
|
191
191
|
name: "ifDescr",
|
192
192
|
type: snmp.ObjectType.OctetString,
|
193
|
-
|
194
|
-
|
193
|
+
maxAccess: snmp.MaxAccess['read-write'],
|
194
|
+
constraints: {
|
195
|
+
sizes: [
|
196
|
+
{ min: 1, max: 255 },
|
197
|
+
]
|
198
|
+
},
|
199
|
+
defVal: "Hello world!"
|
195
200
|
},
|
196
201
|
{
|
197
202
|
number: 3,
|
package/example/test.js
CHANGED
@@ -2,20 +2,18 @@ const snmp = require("../");
|
|
2
2
|
|
3
3
|
const store = snmp.createModuleStore();
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
//store.loadFromFile("/home/mark/snmp/test/CISCO-CONFIG-MAN-MIB.MIB");
|
8
|
-
store.loadFromFile("/home/mark/snmp/test/smiv1.mib");
|
9
|
-
// store.loadFromFile("/home/mark/snmp/test/smiv2.mib");
|
5
|
+
store.loadFromFile("/var/tmp/mibs/IANAifType-MIB.mib");
|
6
|
+
store.loadFromFile("/var/tmp/mibs/IF-MIB.mib");
|
10
7
|
|
11
|
-
const
|
12
|
-
// const mod2 = store.getModule("SMIv2-TEST-MIB");
|
8
|
+
// const mod = store.getModule("IF-MIB");
|
13
9
|
|
14
|
-
//
|
15
|
-
//
|
10
|
+
//Object.keys(mod)
|
11
|
+
// .forEach(key => console.log(key));
|
12
|
+
|
13
|
+
//console.log(JSON.stringify(mod, null, 2));
|
14
|
+
const provs = store.getProvidersForModule('IF-MIB');
|
15
|
+
console.log(JSON.stringify(provs, null, 2));
|
16
16
|
|
17
|
-
console.log(JSON.stringify(mod1, null, 2));
|
18
|
-
// console.log(JSON.stringify(mod2, null, 2));
|
19
17
|
|
20
18
|
//const mod = store.getModule("CISCO-CONFIG-MAN-MIB");
|
21
19
|
//console.log(mod);
|
package/index.js
CHANGED
@@ -264,6 +264,12 @@ var ResponseInvalidCode = {
|
|
264
264
|
|
265
265
|
_expandConstantObject (ResponseInvalidCode);
|
266
266
|
|
267
|
+
var OidFormat = {
|
268
|
+
"oid": "oid",
|
269
|
+
"path": "path",
|
270
|
+
"module": "module"
|
271
|
+
};
|
272
|
+
|
267
273
|
/*****************************************************************************
|
268
274
|
** Exception class definitions
|
269
275
|
**/
|
@@ -3149,6 +3155,14 @@ Receiver.create = function (options, callback) {
|
|
3149
3155
|
|
3150
3156
|
var ModuleStore = function () {
|
3151
3157
|
this.parser = mibparser ();
|
3158
|
+
this.translations = {
|
3159
|
+
oidToPath: {},
|
3160
|
+
oidToModule: {},
|
3161
|
+
pathToOid: {},
|
3162
|
+
pathToModule: {},
|
3163
|
+
moduleToOid: {},
|
3164
|
+
moduleToPath: {}
|
3165
|
+
};
|
3152
3166
|
};
|
3153
3167
|
|
3154
3168
|
ModuleStore.prototype.getSyntaxTypes = function () {
|
@@ -3174,8 +3188,44 @@ ModuleStore.prototype.getSyntaxTypes = function () {
|
|
3174
3188
|
};
|
3175
3189
|
|
3176
3190
|
ModuleStore.prototype.loadFromFile = function (fileName) {
|
3191
|
+
var modulesBeforeLoad = this.getModuleNames();
|
3177
3192
|
this.parser.Import (fileName);
|
3178
3193
|
this.parser.Serialize ();
|
3194
|
+
var modulesAfterLoad = this.getModuleNames();
|
3195
|
+
var newModulesForTranslation = modulesAfterLoad.filter (moduleName => modulesBeforeLoad.indexOf (moduleName) === -1);
|
3196
|
+
newModulesForTranslation.forEach ( moduleName => this.addTranslationsForModule (moduleName) );
|
3197
|
+
};
|
3198
|
+
|
3199
|
+
ModuleStore.prototype.addTranslationsForModule = function (moduleName) {
|
3200
|
+
var mibModule = this.parser.Modules[moduleName];
|
3201
|
+
|
3202
|
+
if ( ! mibModule ) {
|
3203
|
+
throw new ReferenceError ("MIB module " + moduleName + " not loaded");
|
3204
|
+
}
|
3205
|
+
var entryArray = Object.values (mibModule);
|
3206
|
+
for ( var i = 0; i < entryArray.length ; i++ ) {
|
3207
|
+
var mibEntry = entryArray[i];
|
3208
|
+
var oid = mibEntry.OID;
|
3209
|
+
var namedPath = mibEntry.NameSpace;
|
3210
|
+
var moduleQualifiedName;
|
3211
|
+
if ( mibEntry.ObjectName ) {
|
3212
|
+
moduleQualifiedName = moduleName + "::" + mibEntry.ObjectName;
|
3213
|
+
} else {
|
3214
|
+
moduleQualifiedName = undefined;
|
3215
|
+
}
|
3216
|
+
if ( oid && namedPath ) {
|
3217
|
+
this.translations.oidToPath[oid] = namedPath;
|
3218
|
+
this.translations.pathToOid[namedPath] = oid;
|
3219
|
+
}
|
3220
|
+
if ( oid && moduleQualifiedName ) {
|
3221
|
+
this.translations.oidToModule[oid] = moduleQualifiedName;
|
3222
|
+
this.translations.moduleToOid[moduleQualifiedName] = oid;
|
3223
|
+
}
|
3224
|
+
if ( namedPath && moduleQualifiedName ) {
|
3225
|
+
this.translations.pathToModule[namedPath] = moduleQualifiedName;
|
3226
|
+
this.translations.moduleToPath[moduleQualifiedName] = namedPath;
|
3227
|
+
}
|
3228
|
+
}
|
3179
3229
|
};
|
3180
3230
|
|
3181
3231
|
ModuleStore.prototype.getModule = function (moduleName) {
|
@@ -3300,10 +3350,14 @@ ModuleStore.prototype.getProvidersForModule = function (moduleName) {
|
|
3300
3350
|
}
|
3301
3351
|
} else if ( parentOid == currentTableProvider.name ) {
|
3302
3352
|
// table column
|
3353
|
+
let columnType = syntaxTypes[syntax];
|
3354
|
+
if (typeof columnType === 'object') {
|
3355
|
+
columnType = syntaxTypes[Object.keys(columnType)[0]];
|
3356
|
+
}
|
3303
3357
|
var columnDefinition = {
|
3304
3358
|
number: parseInt (mibEntry["OBJECT IDENTIFIER"].split (" ")[1]),
|
3305
3359
|
name: mibEntry.ObjectName,
|
3306
|
-
type:
|
3360
|
+
type: columnType,
|
3307
3361
|
maxAccess: MaxAccess[maxAccess]
|
3308
3362
|
};
|
3309
3363
|
if ( constraints ) {
|
@@ -3338,8 +3392,9 @@ ModuleStore.prototype.getProvidersForModule = function (moduleName) {
|
|
3338
3392
|
} else if ( mibEntry.MACRO == "OBJECT-TYPE" ) {
|
3339
3393
|
// OBJECT-TYPE entries not in a table are scalars
|
3340
3394
|
let scalarType = syntaxTypes[syntax];
|
3341
|
-
if (typeof scalarType === 'object')
|
3395
|
+
if (typeof scalarType === 'object') {
|
3342
3396
|
scalarType = syntaxTypes[Object.keys(scalarType)[0]];
|
3397
|
+
}
|
3343
3398
|
var scalarDefinition = {
|
3344
3399
|
name: mibEntry.ObjectName,
|
3345
3400
|
type: MibProviderType.Scalar,
|
@@ -3368,6 +3423,7 @@ ModuleStore.prototype.loadBaseModules = function () {
|
|
3368
3423
|
this.parser.Import (__dirname + "/lib/mibs/" + mibModule + ".mib");
|
3369
3424
|
}
|
3370
3425
|
this.parser.Serialize ();
|
3426
|
+
this.getModuleNames (true).forEach( moduleName => this.addTranslationsForModule (moduleName) );
|
3371
3427
|
};
|
3372
3428
|
|
3373
3429
|
ModuleStore.getConstraintsFromSyntax = function (syntax, syntaxTypes) {
|
@@ -3403,6 +3459,50 @@ ModuleStore.getConstraintsFromSyntax = function (syntax, syntaxTypes) {
|
|
3403
3459
|
};
|
3404
3460
|
};
|
3405
3461
|
|
3462
|
+
ModuleStore.prototype.translate = function (name, destinationFormat) {
|
3463
|
+
var sourceFormat;
|
3464
|
+
if ( name.includes ("::") ) {
|
3465
|
+
sourceFormat = OidFormat.module;
|
3466
|
+
} else if ( name.startsWith ("1.") ) {
|
3467
|
+
sourceFormat = OidFormat.oid;
|
3468
|
+
} else {
|
3469
|
+
sourceFormat = OidFormat.path;
|
3470
|
+
}
|
3471
|
+
var lowercaseDestinationFormat = destinationFormat.toLowerCase();
|
3472
|
+
if ( sourceFormat === lowercaseDestinationFormat ) {
|
3473
|
+
var testMap;
|
3474
|
+
switch ( sourceFormat ) {
|
3475
|
+
case OidFormat.oid: {
|
3476
|
+
testMap = "oidToPath";
|
3477
|
+
break;
|
3478
|
+
}
|
3479
|
+
case OidFormat.path: {
|
3480
|
+
testMap = "pathToOid";
|
3481
|
+
break;
|
3482
|
+
}
|
3483
|
+
case OidFormat.module: {
|
3484
|
+
testMap = "moduleToOid";
|
3485
|
+
break;
|
3486
|
+
}
|
3487
|
+
}
|
3488
|
+
var entryExists = this.translations[testMap][name];
|
3489
|
+
if ( entryExists === undefined ) {
|
3490
|
+
throw new Error ("No translation found for " + name);
|
3491
|
+
} else {
|
3492
|
+
return name;
|
3493
|
+
}
|
3494
|
+
} else {
|
3495
|
+
var capitalizedDestinationFormat = destinationFormat.charAt(0).toUpperCase() + destinationFormat.slice(1).toLowerCase();
|
3496
|
+
var translationMap = sourceFormat + "To" + capitalizedDestinationFormat;
|
3497
|
+
var translation = this.translations[translationMap][name];
|
3498
|
+
if ( ! translation ) {
|
3499
|
+
throw new Error ("No '" + destinationFormat + "' translation found for " + name);
|
3500
|
+
} else {
|
3501
|
+
return translation;
|
3502
|
+
}
|
3503
|
+
}
|
3504
|
+
};
|
3505
|
+
|
3406
3506
|
ModuleStore.create = function () {
|
3407
3507
|
var store = new ModuleStore ();
|
3408
3508
|
store.loadBaseModules ();
|
@@ -6233,6 +6333,7 @@ exports.AccessControlModelType = AccessControlModelType;
|
|
6233
6333
|
exports.AccessLevel = AccessLevel;
|
6234
6334
|
exports.MaxAccess = MaxAccess;
|
6235
6335
|
exports.RowStatus = RowStatus;
|
6336
|
+
exports.OidFormat = OidFormat;
|
6236
6337
|
|
6237
6338
|
exports.ResponseInvalidCode = ResponseInvalidCode;
|
6238
6339
|
exports.ResponseInvalidError = ResponseInvalidError;
|