net-snmp 3.10.1 → 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 +4 -0
- package/example/test.js +55 -18
- package/lib/mib.js +24 -3
- package/package.json +1 -1
package/README.md
CHANGED
@@ -3347,6 +3347,10 @@ 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
|
+
|
3350
3354
|
# License
|
3351
3355
|
|
3352
3356
|
Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
|
package/example/test.js
CHANGED
@@ -1,25 +1,62 @@
|
|
1
|
-
|
1
|
+
/* eslint-disable no-unused-vars */
|
2
2
|
|
3
|
-
|
3
|
+
var snmp = require ("../");
|
4
|
+
var getopts = require ("getopts");
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
var options = getopts(process.argv.slice(2));
|
7
|
+
var providers;
|
8
|
+
var mibDir = '/var/tmp/mibs/';
|
7
9
|
|
8
|
-
|
10
|
+
var counter64 = function (num) {
|
11
|
+
var buf = Buffer.alloc (4);
|
12
|
+
buf.writeUInt32BE (num);
|
13
|
+
return buf;
|
14
|
+
};
|
9
15
|
|
10
|
-
|
11
|
-
|
16
|
+
var snmpOptions = {
|
17
|
+
disableAuthorization: options.n,
|
18
|
+
port: options.p,
|
19
|
+
engineID: options.e,
|
20
|
+
debug: options.d
|
21
|
+
};
|
12
22
|
|
13
|
-
|
14
|
-
|
15
|
-
console.
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
//
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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/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
|
-
|
759
|
-
|
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]) {
|