net-snmp 3.9.8 → 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 +34 -0
- package/example/test.js +47 -54
- package/index.js +96 -0
- package/lib/mib.js +24 -14
- 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.
|
@@ -3309,6 +3335,14 @@ Example programs are included under the module's `example` directory.
|
|
3309
3335
|
|
3310
3336
|
* Fix subtree callback termination
|
3311
3337
|
|
3338
|
+
## Version 3.9.9 - 17/01/2024
|
3339
|
+
|
3340
|
+
* Add SMIv1 integer enumeration support
|
3341
|
+
|
3342
|
+
## Version 3.10.0 - 17/01/2024
|
3343
|
+
|
3344
|
+
* Add numeric/named OID translate function
|
3345
|
+
|
3312
3346
|
# License
|
3313
3347
|
|
3314
3348
|
Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
|
package/example/test.js
CHANGED
@@ -1,54 +1,47 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
var
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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));
|
1
|
+
const snmp = require("../");
|
2
|
+
|
3
|
+
const store = snmp.createModuleStore();
|
4
|
+
|
5
|
+
//store.loadFromFile("/var/tmp/mibs/CISCO-SMI.mib");
|
6
|
+
//store.loadFromFile("/var/tmp/mibs/CISCO-TC.mib");
|
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");
|
10
|
+
|
11
|
+
const mod1 = store.getModule("SMIv1-TEST-MIB");
|
12
|
+
// const mod2 = store.getModule("SMIv2-TEST-MIB");
|
13
|
+
|
14
|
+
// Object.keys(mod1)
|
15
|
+
// .forEach(key => console.log(key));
|
16
|
+
|
17
|
+
console.log(JSON.stringify(mod1, null, 2));
|
18
|
+
// console.log(JSON.stringify(mod2, null, 2));
|
19
|
+
|
20
|
+
//const mod = store.getModule("CISCO-CONFIG-MAN-MIB");
|
21
|
+
//console.log(mod);
|
22
|
+
//console.log(JSON.stringify(mod.ccmHistoryEventTerminalUser, null, 2));
|
23
|
+
//console.log(JSON.stringify(mod.ciscoConfigManCTIDNotifyGroup, null, 2));
|
24
|
+
//console.log(JSON.stringify(mod.ciscoConfigManCTIDObjectGroup, null, 2));
|
25
|
+
//console.log(JSON.stringify(mod.HistoryEventMedium, null, 2));
|
26
|
+
//console.log(JSON.stringify(mod.ccmHistoryRunningLastChanged, null, 2));
|
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;
|
package/lib/mib.js
CHANGED
@@ -679,22 +679,10 @@ var MIB = function (dir) {
|
|
679
679
|
var SYNTAX = Symbols[c1];
|
680
680
|
var val = Symbols[c1 + 1];
|
681
681
|
|
682
|
+
// Normal MACROs
|
682
683
|
if (this.MACROS.indexOf(macro) > -1 && m < 10) {
|
683
684
|
if (val[0] === "{") {
|
684
|
-
c1
|
685
|
-
while (Symbols[c1].indexOf("}") == -1) {
|
686
|
-
c1++;
|
687
|
-
val += Symbols[c1].trim();
|
688
|
-
}
|
689
|
-
val = val.replace("{", "").replace("}", "").split(",");
|
690
|
-
|
691
|
-
Object[ObjectName]['SYNTAX'] = {};
|
692
|
-
Object[ObjectName]['SYNTAX'][SYNTAX] = {};
|
693
|
-
|
694
|
-
for (var TC = 0; TC < val.length; TC++) {
|
695
|
-
let openParenSplit = val[TC].split(/\s*\(\s*/);
|
696
|
-
Object[ObjectName]['SYNTAX'][SYNTAX][openParenSplit[1].replace(/\s*\)\s*$/, '')] = openParenSplit[0].trimStart();
|
697
|
-
}
|
685
|
+
this.BuildObjectEnumeration(Object, ObjectName, c1, SYNTAX, val, Symbols);
|
698
686
|
} else if (val[0] === '(') {
|
699
687
|
const key = val.startsWith('(SIZE')? 'sizes' : 'ranges';
|
700
688
|
Object[ObjectName]['SYNTAX'] = {};
|
@@ -702,6 +690,28 @@ var MIB = function (dir) {
|
|
702
690
|
} else {
|
703
691
|
Object[ObjectName]['SYNTAX'] = SYNTAX;
|
704
692
|
}
|
693
|
+
// SMIv1 INTEGER enumerations
|
694
|
+
} else if ( Symbols[i + 1] == 'INTEGER' ) {
|
695
|
+
c1 = i + 1;
|
696
|
+
SYNTAX = 'INTEGER';
|
697
|
+
val = Symbols[c1 + 1];
|
698
|
+
if ( val[0] === '{' ) {
|
699
|
+
this.BuildObjectEnumeration(Object, ObjectName, c1, SYNTAX, val, Symbols);
|
700
|
+
}
|
701
|
+
}
|
702
|
+
},
|
703
|
+
BuildObjectEnumeration: function (Object, ObjectName, c1, SYNTAX, val, Symbols) {
|
704
|
+
c1++;
|
705
|
+
while (Symbols[c1].indexOf("}") == -1) {
|
706
|
+
c1++;
|
707
|
+
val += Symbols[c1].trim();
|
708
|
+
}
|
709
|
+
val = val.replace("{", "").replace("}", "").split(",");
|
710
|
+
Object[ObjectName]['SYNTAX'] = {};
|
711
|
+
Object[ObjectName]['SYNTAX'][SYNTAX] = {};
|
712
|
+
for (var TC = 0; TC < val.length; TC++) {
|
713
|
+
let openParenSplit = val[TC].split(/\s*\(\s*/);
|
714
|
+
Object[ObjectName]['SYNTAX'][SYNTAX][openParenSplit[1].replace(/\s*\)\s*$/, '')] = openParenSplit[0].trimStart();
|
705
715
|
}
|
706
716
|
},
|
707
717
|
GetSummary: function (callback) {
|