net-snmp 3.9.9 → 3.10.0
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 +30 -0
- package/example/test.js +20 -0
- package/index.js +96 -0
- 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. RFC1158-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,10 @@ 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
|
+
|
3316
3346
|
# License
|
3317
3347
|
|
3318
3348
|
Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
|
package/example/test.js
CHANGED
@@ -25,3 +25,23 @@ console.log(JSON.stringify(mod1, null, 2));
|
|
25
25
|
//console.log(JSON.stringify(mod.HistoryEventMedium, null, 2));
|
26
26
|
//console.log(JSON.stringify(mod.ccmHistoryRunningLastChanged, null, 2));
|
27
27
|
//console.log(JSON.stringify(mod.ccmHistoryRunningLastSaved, null, 2));
|
28
|
+
|
29
|
+
// console.log(JSON.stringify(store.translations.moduleToOid, null, 2));
|
30
|
+
// console.log(JSON.stringify(store.translations.moduleToPath, null, 2));
|
31
|
+
// console.log(JSON.stringify(store.translations.oidToPath, null, 2));
|
32
|
+
// console.log(JSON.stringify(store.translations.oidToModule, null, 2));
|
33
|
+
// console.log(JSON.stringify(store.translations.pathToOid, null, 2));
|
34
|
+
// console.log(JSON.stringify(store.translations.pathToModule, null, 2));
|
35
|
+
|
36
|
+
console.log('iso.org.dod.internet.snmpV2.snmpModules.snmpMIB.snmpMIBObjects.snmpTraps.warmStart => ' + store.translate('iso.org.dod.internet.snmpV2.snmpModules.snmpMIB.snmpMIBObjects.snmpTraps.warmStart', 'oid'));
|
37
|
+
console.log('iso.org.dod.internet.snmpV2.snmpModules.snmpMIB.snmpMIBObjects.snmpTraps.warmStart => ' + store.translate('iso.org.dod.internet.snmpV2.snmpModules.snmpMIB.snmpMIBObjects.snmpTraps.warmStart', 'module'));
|
38
|
+
console.log('iso.org.dod.internet.snmpV2.snmpModules.snmpMIB.snmpMIBObjects.snmpTraps.warmStart => ' + store.translate('iso.org.dod.internet.snmpV2.snmpModules.snmpMIB.snmpMIBObjects.snmpTraps.warmStart', 'path'));
|
39
|
+
console.log('1.3.6.1.2.1.1.1 => ' + store.translate('1.3.6.1.2.1.1.1', 'oid'));
|
40
|
+
console.log('1.3.6.1.2.1.1.1 => ' + store.translate('1.3.6.1.2.1.1.1', 'module'));
|
41
|
+
console.log('1.3.6.1.2.1.1.1 => ' + store.translate('1.3.6.1.2.1.1.1', 'path'));
|
42
|
+
console.log('RFC1158-MIB::sysDescr => ' + store.translate('RFC1158-MIB::sysDescr', snmp.OidFormat.oid));
|
43
|
+
console.log('SNMPv2-MIB::sysDescr => ' + store.translate('SNMPv2-MIB::sysDescr', snmp.OidFormat.oid));
|
44
|
+
console.log('RFC1158-MIB::sysDescr => ' + store.translate('SNMPv2-MIB::sysDescr', snmp.OidFormat.path));
|
45
|
+
console.log('RFC1158-MIB::sysDescr => ' + store.translate('SNMPv2-MIB::sysDescr', snmp.OidFormat.module));
|
46
|
+
|
47
|
+
// console.log('RFC1158-MIB::ipAdEntReasmMaxSize => ' + store.translate('RFC1158-MIB::ipAdEntReasmMaxSizesz', snmp.OidFormat.oid));
|
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) {
|
@@ -3368,6 +3418,7 @@ ModuleStore.prototype.loadBaseModules = function () {
|
|
3368
3418
|
this.parser.Import (__dirname + "/lib/mibs/" + mibModule + ".mib");
|
3369
3419
|
}
|
3370
3420
|
this.parser.Serialize ();
|
3421
|
+
this.getModuleNames (true).forEach( moduleName => this.addTranslationsForModule (moduleName) );
|
3371
3422
|
};
|
3372
3423
|
|
3373
3424
|
ModuleStore.getConstraintsFromSyntax = function (syntax, syntaxTypes) {
|
@@ -3403,6 +3454,50 @@ ModuleStore.getConstraintsFromSyntax = function (syntax, syntaxTypes) {
|
|
3403
3454
|
};
|
3404
3455
|
};
|
3405
3456
|
|
3457
|
+
ModuleStore.prototype.translate = function (name, destinationFormat) {
|
3458
|
+
var sourceFormat;
|
3459
|
+
if ( name.includes ("::") ) {
|
3460
|
+
sourceFormat = OidFormat.module;
|
3461
|
+
} else if ( name.startsWith ("1.") ) {
|
3462
|
+
sourceFormat = OidFormat.oid;
|
3463
|
+
} else {
|
3464
|
+
sourceFormat = OidFormat.path;
|
3465
|
+
}
|
3466
|
+
var lowercaseDestinationFormat = destinationFormat.toLowerCase();
|
3467
|
+
if ( sourceFormat === lowercaseDestinationFormat ) {
|
3468
|
+
var testMap;
|
3469
|
+
switch ( sourceFormat ) {
|
3470
|
+
case OidFormat.oid: {
|
3471
|
+
testMap = "oidToPath";
|
3472
|
+
break;
|
3473
|
+
}
|
3474
|
+
case OidFormat.path: {
|
3475
|
+
testMap = "pathToOid";
|
3476
|
+
break;
|
3477
|
+
}
|
3478
|
+
case OidFormat.module: {
|
3479
|
+
testMap = "moduleToOid";
|
3480
|
+
break;
|
3481
|
+
}
|
3482
|
+
}
|
3483
|
+
var entryExists = this.translations[testMap][name];
|
3484
|
+
if ( entryExists === undefined ) {
|
3485
|
+
throw new Error ("No translation found for " + name);
|
3486
|
+
} else {
|
3487
|
+
return name;
|
3488
|
+
}
|
3489
|
+
} else {
|
3490
|
+
var capitalizedDestinationFormat = destinationFormat.charAt(0).toUpperCase() + destinationFormat.slice(1).toLowerCase();
|
3491
|
+
var translationMap = sourceFormat + "To" + capitalizedDestinationFormat;
|
3492
|
+
var translation = this.translations[translationMap][name];
|
3493
|
+
if ( ! translation ) {
|
3494
|
+
throw new Error ("No '" + destinationFormat + "' translation found for " + name);
|
3495
|
+
} else {
|
3496
|
+
return translation;
|
3497
|
+
}
|
3498
|
+
}
|
3499
|
+
};
|
3500
|
+
|
3406
3501
|
ModuleStore.create = function () {
|
3407
3502
|
var store = new ModuleStore ();
|
3408
3503
|
store.loadBaseModules ();
|
@@ -6233,6 +6328,7 @@ exports.AccessControlModelType = AccessControlModelType;
|
|
6233
6328
|
exports.AccessLevel = AccessLevel;
|
6234
6329
|
exports.MaxAccess = MaxAccess;
|
6235
6330
|
exports.RowStatus = RowStatus;
|
6331
|
+
exports.OidFormat = OidFormat;
|
6236
6332
|
|
6237
6333
|
exports.ResponseInvalidCode = ResponseInvalidCode;
|
6238
6334
|
exports.ResponseInvalidError = ResponseInvalidError;
|