net-snmp 3.10.0 → 3.10.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/README.md CHANGED
@@ -2486,7 +2486,7 @@ call.
2486
2486
  Takes an OID in one of the three supported formats (the library automatically detects the given OID's format):
2487
2487
  - **OidFormat.oid** - canonical (numerical) OID format e.g. 1.3.6.1.2.1.1.1
2488
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
2489
+ - **OidFormat.module** - module-qualified format e.g. SNMPv2-MIB::sysDescr
2490
2490
 
2491
2491
  Returns the given OID translated to the provided destination format - also one of the above three formats.
2492
2492
 
@@ -3343,6 +3343,14 @@ Example programs are included under the module's `example` directory.
3343
3343
 
3344
3344
  * Add numeric/named OID translate function
3345
3345
 
3346
+ ## Version 3.10.1 - 30/01/2024
3347
+
3348
+ * Fix table column type in provider definition with column type constraints
3349
+
3350
+ ## Version 3.10.2 - 05/02/2024
3351
+
3352
+ * Add MIB parsing support for OID values with intermediate entries in list
3353
+
3346
3354
  # License
3347
3355
 
3348
3356
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
@@ -190,8 +190,13 @@ var tableProvider = {
190
190
  number: 2,
191
191
  name: "ifDescr",
192
192
  type: snmp.ObjectType.OctetString,
193
- maxAccess: snmp.MaxAccess['read-write'],
194
- defVal: "Hello world!"
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
@@ -1,47 +1,62 @@
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));
1
+ /* eslint-disable no-unused-vars */
2
+
3
+ var snmp = require ("../");
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 + "IANAifType-MIB.mib");
40
+ store.loadFromFile (mibDir + "IF-MIB.mib");
41
+ store.loadFromFile (mibDir + "HOST-RESOURCES-MIB.MIB");
42
+ store.loadFromFile (mibDir + "IANA-PRINTER-MIB.mib");
43
+ store.loadFromFile (mibDir + "IANA-CHARSET-MIB.mib");
44
+ store.loadFromFile (mibDir + "PRINTER-MIBv1.mib");
45
+ store.loadFromFile (mibDir + "JOB-MONITORING-MIB.mib");
46
+
47
+ // const mibModuleOid = store.translate('1.3.6.1.4.1', snmp.OidFormat.module);
48
+ // console.log('mibModuleOid: ', mibModuleOid);
49
+ // const mibOid = store.translate('Job-Monitoring-MIB::jmJobTable', snmp.OidFormat.oid);
50
+ // console.log('mibOid: ', mibOid);
51
+ console.log(store.translate('Job-Monitoring-MIB::jmJobTable', snmp.OidFormat.oid));
52
+
53
+ // ifNumber
54
+ // Scalar type - setScalarValue() and getScalarValue() are the entire API for these
55
+
56
+ // console.log("All modules: ", JSON.stringify(modules, '', 2));
57
+ const jobModule = store.getModule('Job-Monitoring-MIB');
58
+ console.log('jobModule: ', JSON.stringify(jobModule, null, 2));
59
+
60
+ // print IF-MIB
61
+ // const ifModule = store.getModule('IF-MIB');
62
+ // console.log('ifModule: ', JSON.stringify(ifModule, null, 2));
package/index.js CHANGED
@@ -3350,10 +3350,14 @@ ModuleStore.prototype.getProvidersForModule = function (moduleName) {
3350
3350
  }
3351
3351
  } else if ( parentOid == currentTableProvider.name ) {
3352
3352
  // table column
3353
+ let columnType = syntaxTypes[syntax];
3354
+ if (typeof columnType === 'object') {
3355
+ columnType = syntaxTypes[Object.keys(columnType)[0]];
3356
+ }
3353
3357
  var columnDefinition = {
3354
3358
  number: parseInt (mibEntry["OBJECT IDENTIFIER"].split (" ")[1]),
3355
3359
  name: mibEntry.ObjectName,
3356
- type: syntaxTypes[syntax],
3360
+ type: columnType,
3357
3361
  maxAccess: MaxAccess[maxAccess]
3358
3362
  };
3359
3363
  if ( constraints ) {
@@ -3388,8 +3392,9 @@ ModuleStore.prototype.getProvidersForModule = function (moduleName) {
3388
3392
  } else if ( mibEntry.MACRO == "OBJECT-TYPE" ) {
3389
3393
  // OBJECT-TYPE entries not in a table are scalars
3390
3394
  let scalarType = syntaxTypes[syntax];
3391
- if (typeof scalarType === 'object')
3395
+ if (typeof scalarType === 'object') {
3392
3396
  scalarType = syntaxTypes[Object.keys(scalarType)[0]];
3397
+ }
3393
3398
  var scalarDefinition = {
3394
3399
  name: mibEntry.ObjectName,
3395
3400
  type: MibProviderType.Scalar,
package/lib/mib.js CHANGED
@@ -733,7 +733,7 @@ var MIB = function (dir) {
733
733
  callback(summary);
734
734
  },
735
735
  OID: function (OBJECT_IDENTIFIER, ID, ObjectName, OD, callback) {
736
- let members = OBJECT_IDENTIFIER.split(" ");
736
+ let members = OBJECT_IDENTIFIER.split(/\s+/);
737
737
  let parent = members.shift();
738
738
  let oid = members.pop();
739
739
  if (parent == 'iso') {
@@ -755,8 +755,29 @@ var MIB = function (dir) {
755
755
  callback(midID.join('.'), midOD.join('.'));
756
756
  return;
757
757
  }
758
- ID = ID == '' ? oid : [oid, ID].join('.');
759
- OD = OD == '' ? parent : [parent, OD].join('.');
758
+ if (members.length > 0) {
759
+ // We have middle entries e.g. { enterprises pwg(2699) mibs(1) 1 }
760
+ let midID = [];
761
+ let midOD = [parent];
762
+ for (let entry of members) {
763
+ let match = entry.match(/(.*)\((.+)\)$/);
764
+ midID.push(match[2]);
765
+ midOD.push(match[1]);
766
+ }
767
+ midID.push(oid);
768
+ if ( ID != '' ) {
769
+ midID.push(ID);
770
+ }
771
+ if ( OD != '' ) {
772
+ midOD.push(OD);
773
+ }
774
+ ID = midID.join('.');
775
+ OD = midOD.join('.');
776
+ } else {
777
+ // We have no middle entries e.g. { enterprises 2021 }
778
+ ID = ID == '' ? oid : [oid, ID].join('.');
779
+ OD = OD == '' ? parent : [parent, OD].join('.');
780
+ }
760
781
  for (var ModuleName in this.Modules) {
761
782
  if (this.Modules.hasOwnProperty(ModuleName)) {
762
783
  if (this.Modules[ModuleName][parent]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.10.0",
3
+ "version": "3.10.2",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {