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 +9 -1
- package/example/snmp-agent.js +7 -2
- package/example/test.js +62 -47
- package/index.js +7 -2
- package/lib/mib.js +24 -3
- package/package.json +1 -1
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.
|
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>
|
package/example/snmp-agent.js
CHANGED
@@ -190,8 +190,13 @@ var tableProvider = {
|
|
190
190
|
number: 2,
|
191
191
|
name: "ifDescr",
|
192
192
|
type: snmp.ObjectType.OctetString,
|
193
|
-
|
194
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
//
|
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:
|
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
|
-
|
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]) {
|