net-snmp 3.10.1 → 3.10.3

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
@@ -3347,6 +3347,14 @@ Example programs are included under the module's `example` directory.
3347
3347
 
3348
3348
  * Fix table column type in provider definition with column type constraints
3349
3349
 
3350
+ ## Version 3.10.2 - 05/02/2024
3351
+
3352
+ * Add MIB parsing support for OID values with intermediate entries in list
3353
+
3354
+ ## Version 3.10.3 - 05/02/2024
3355
+
3356
+ * Add MIB parsing support for final member of OID value list containing identifier/descriptor pair
3357
+
3350
3358
  # License
3351
3359
 
3352
3360
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
package/example/test.js CHANGED
@@ -1,25 +1,67 @@
1
- const snmp = require("../");
1
+ /* eslint-disable no-unused-vars */
2
2
 
3
- const store = snmp.createModuleStore();
3
+ var snmp = require ("../");
4
+ var getopts = require ("getopts");
4
5
 
5
- store.loadFromFile("/var/tmp/mibs/IANAifType-MIB.mib");
6
- store.loadFromFile("/var/tmp/mibs/IF-MIB.mib");
6
+ var options = getopts(process.argv.slice(2));
7
+ var providers;
8
+ var mibDir = '/var/tmp/mibs/';
7
9
 
8
- // const mod = store.getModule("IF-MIB");
10
+ var counter64 = function (num) {
11
+ var buf = Buffer.alloc (4);
12
+ buf.writeUInt32BE (num);
13
+ return buf;
14
+ };
9
15
 
10
- //Object.keys(mod)
11
- // .forEach(key => console.log(key));
16
+ var snmpOptions = {
17
+ disableAuthorization: options.n,
18
+ port: options.p,
19
+ engineID: options.e,
20
+ debug: options.d
21
+ };
12
22
 
13
- //console.log(JSON.stringify(mod, null, 2));
14
- const provs = store.getProvidersForModule('IF-MIB');
15
- console.log(JSON.stringify(provs, null, 2));
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
+ };
16
30
 
31
+ var store = snmp.createModuleStore ();
32
+ var agent = snmp.createAgent (snmpOptions, callback);
33
+ var mib = agent.getMib ();
17
34
 
18
- //const mod = store.getModule("CISCO-CONFIG-MAN-MIB");
19
- //console.log(mod);
20
- //console.log(JSON.stringify(mod.ccmHistoryEventTerminalUser, null, 2));
21
- //console.log(JSON.stringify(mod.ciscoConfigManCTIDNotifyGroup, null, 2));
22
- //console.log(JSON.stringify(mod.ciscoConfigManCTIDObjectGroup, null, 2));
23
- //console.log(JSON.stringify(mod.HistoryEventMedium, null, 2));
24
- //console.log(JSON.stringify(mod.ccmHistoryRunningLastChanged, null, 2));
25
- //console.log(JSON.stringify(mod.ccmHistoryRunningLastSaved, null, 2));
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-RFC.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
+ console.log(store.translate('Job-Monitoring-MIB::jmJobTable', snmp.OidFormat.path));
53
+ console.log(store.translate('1.3.6.1.4.1.2699.1.1.1.3.1', snmp.OidFormat.path));
54
+ console.log(store.translate('1.3.6.1.4.1.2699.1.1.1.3.1', snmp.OidFormat.module));
55
+ console.log(store.translate('iso.org.dod.internet.private.enterprises.pwg.mibs.jobmonMIB.jobmonMIBObjects.jmJob.jmJobTable', snmp.OidFormat.oid));
56
+ console.log(store.translate('iso.org.dod.internet.private.enterprises.pwg.mibs.jobmonMIB.jobmonMIBObjects.jmJob.jmJobTable', snmp.OidFormat.module));
57
+
58
+ // ifNumber
59
+ // Scalar type - setScalarValue() and getScalarValue() are the entire API for these
60
+
61
+ // console.log("All modules: ", JSON.stringify(modules, '', 2));
62
+ // const jobModule = store.getModule('Job-Monitoring-MIB');
63
+ // console.log('jobModule: ', JSON.stringify(jobModule, null, 2));
64
+
65
+ // print IF-MIB
66
+ const ifModule = store.getModule('IF-MIB');
67
+ console.log('ifModule: ', JSON.stringify(ifModule, null, 2));
package/lib/mib.js CHANGED
@@ -733,9 +733,13 @@ 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
+ if ( oid.includes('(') ) {
740
+ let oidSplit = oid.match(/(.*)\((.+)\)$/);
741
+ oid = oidSplit[2];
742
+ }
739
743
  if (parent == 'iso') {
740
744
  let midID = ['1'];
741
745
  let midOD = ['iso'];
@@ -755,8 +759,29 @@ var MIB = function (dir) {
755
759
  callback(midID.join('.'), midOD.join('.'));
756
760
  return;
757
761
  }
758
- ID = ID == '' ? oid : [oid, ID].join('.');
759
- OD = OD == '' ? parent : [parent, OD].join('.');
762
+ if (members.length > 0) {
763
+ // We have middle entries e.g. { enterprises pwg(2699) mibs(1) 1 }
764
+ let midID = [];
765
+ let midOD = [parent];
766
+ for (let entry of members) {
767
+ let match = entry.match(/(.*)\((.+)\)$/);
768
+ midID.push(match[2]);
769
+ midOD.push(match[1]);
770
+ }
771
+ midID.push(oid);
772
+ if ( ID != '' ) {
773
+ midID.push(ID);
774
+ }
775
+ if ( OD != '' ) {
776
+ midOD.push(OD);
777
+ }
778
+ ID = midID.join('.');
779
+ OD = midOD.join('.');
780
+ } else {
781
+ // We have no middle entries e.g. { enterprises 2021 }
782
+ ID = ID == '' ? oid : [oid, ID].join('.');
783
+ OD = OD == '' ? parent : [parent, OD].join('.');
784
+ }
760
785
  for (var ModuleName in this.Modules) {
761
786
  if (this.Modules.hasOwnProperty(ModuleName)) {
762
787
  if (this.Modules[ModuleName][parent]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.10.1",
3
+ "version": "3.10.3",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {