net-snmp 3.10.4 → 3.11.1
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 +8 -0
- package/example/test.js +5 -2
- package/index.js +35 -34
- package/lib/mib.js +68 -72
- package/package.json +1 -1
package/README.md
CHANGED
@@ -3359,6 +3359,14 @@ Example programs are included under the module's `example` directory.
|
|
3359
3359
|
|
3360
3360
|
* Add MIB parsing support for middle member of OID value list containing identifier only
|
3361
3361
|
|
3362
|
+
## Version 3.11.0 - 23/03/2024
|
3363
|
+
|
3364
|
+
* Fix parent object retrieval to respect MIB module imports
|
3365
|
+
|
3366
|
+
## Version 3.11.1 - 30/03/2024
|
3367
|
+
|
3368
|
+
* Add error status and index handling to AgentX subagent
|
3369
|
+
|
3362
3370
|
# License
|
3363
3371
|
|
3364
3372
|
Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
|
package/example/test.js
CHANGED
@@ -43,6 +43,7 @@ store.loadFromFile (mibDir + "IANA-PRINTER-MIB.mib");
|
|
43
43
|
store.loadFromFile (mibDir + "IANA-CHARSET-MIB.mib");
|
44
44
|
store.loadFromFile (mibDir + "PRINTER-MIBv1.mib");
|
45
45
|
store.loadFromFile (mibDir + "JOB-MONITORING-MIB-RFC.mib");
|
46
|
+
store.loadFromFile (mibDir + "NETSURE-MIB-001-B.mib");
|
46
47
|
|
47
48
|
// const mibModuleOid = store.translate('1.3.6.1.4.1', snmp.OidFormat.module);
|
48
49
|
// console.log('mibModuleOid: ', mibModuleOid);
|
@@ -63,5 +64,7 @@ console.log(store.translate('iso.org.dod.internet.private.enterprises.pwg.mibs.j
|
|
63
64
|
// console.log('jobModule: ', JSON.stringify(jobModule, null, 2));
|
64
65
|
|
65
66
|
// print IF-MIB
|
66
|
-
const ifModule = store.getModule('IF-MIB');
|
67
|
-
console.log('ifModule: ', JSON.stringify(ifModule, null, 2));
|
67
|
+
// const ifModule = store.getModule('IF-MIB');
|
68
|
+
// console.log('ifModule: ', JSON.stringify(ifModule, null, 2));
|
69
|
+
const nsModule = store.getModule('NETSURE-MIB-001-B');
|
70
|
+
console.log('nsModule: ', JSON.stringify(nsModule, null, 2));
|
package/index.js
CHANGED
@@ -5506,6 +5506,19 @@ AgentXPdu.prototype.readHeader = function (buffer) {
|
|
5506
5506
|
this.payloadLength = buffer.readUInt32BE ();
|
5507
5507
|
};
|
5508
5508
|
|
5509
|
+
AgentXPdu.prototype.getResponsePduForRequest = function () {
|
5510
|
+
const responsePdu = AgentXPdu.createFromVariables({
|
5511
|
+
pduType: AgentXPduType.Response,
|
5512
|
+
sessionID: this.sessionID,
|
5513
|
+
transactionID: this.transactionID,
|
5514
|
+
packetID: this.packetID,
|
5515
|
+
sysUpTime: 0,
|
5516
|
+
error: 0,
|
5517
|
+
index: 0
|
5518
|
+
});
|
5519
|
+
return responsePdu;
|
5520
|
+
};
|
5521
|
+
|
5509
5522
|
AgentXPdu.createFromVariables = function (vars) {
|
5510
5523
|
var pdu = new AgentXPdu ();
|
5511
5524
|
pdu.flags = vars.flags ? vars.flags | 0x10 : 0x10; // set NETWORK_BYTE_ORDER to big endian
|
@@ -6040,13 +6053,14 @@ Subagent.prototype.response = function (pdu) {
|
|
6040
6053
|
};
|
6041
6054
|
|
6042
6055
|
Subagent.prototype.request = function (pdu, requestVarbinds) {
|
6043
|
-
|
6044
|
-
|
6045
|
-
|
6046
|
-
|
6047
|
-
|
6048
|
-
|
6049
|
-
|
6056
|
+
const me = this;
|
6057
|
+
const varbindsLength = requestVarbinds.length;
|
6058
|
+
const responseVarbinds = [];
|
6059
|
+
const responsePdu = pdu.getResponsePduForRequest ();
|
6060
|
+
let varbindsCompleted = 0;
|
6061
|
+
|
6062
|
+
for ( let i = 0; i < varbindsLength; i++ ) {
|
6063
|
+
const requestVarbind = requestVarbinds[i];
|
6050
6064
|
var instanceNode = this.mib.lookup (requestVarbind.oid);
|
6051
6065
|
var providerNode;
|
6052
6066
|
var mibRequest;
|
@@ -6097,14 +6111,21 @@ Subagent.prototype.request = function (pdu, requestVarbinds) {
|
|
6097
6111
|
}
|
6098
6112
|
|
6099
6113
|
(function (savedIndex) {
|
6100
|
-
var responseVarbind;
|
6101
6114
|
mibRequest.done = function (error) {
|
6115
|
+
let responseVarbind;
|
6102
6116
|
if ( error ) {
|
6103
6117
|
responseVarbind = {
|
6104
6118
|
oid: mibRequest.oid,
|
6105
6119
|
type: error.type || ObjectType.Null,
|
6106
6120
|
value: error.value || null
|
6107
6121
|
};
|
6122
|
+
if ( (typeof responsePdu.errorStatus == "undefined" || responsePdu.errorStatus == ErrorStatus.NoError) && error.errorStatus != ErrorStatus.NoError ) {
|
6123
|
+
responsePdu.error = error.errorStatus;
|
6124
|
+
responsePdu.index = savedIndex + 1;
|
6125
|
+
}
|
6126
|
+
if ( error.errorStatus != ErrorStatus.NoError ) {
|
6127
|
+
responseVarbind.errorStatus = error.errorStatus;
|
6128
|
+
}
|
6108
6129
|
} else {
|
6109
6130
|
if ( pdu.pduType == AgentXPduType.TestSet ) {
|
6110
6131
|
// more tests?
|
@@ -6130,9 +6151,9 @@ Subagent.prototype.request = function (pdu, requestVarbinds) {
|
|
6130
6151
|
if ( ++varbindsCompleted == varbindsLength) {
|
6131
6152
|
if ( pdu.pduType == AgentXPduType.TestSet || pdu.pduType == AgentXPduType.CommitSet
|
6132
6153
|
|| pdu.pduType == AgentXPduType.UndoSet) {
|
6133
|
-
me.
|
6154
|
+
me.sendResponse.call (me, responsePdu);
|
6134
6155
|
} else {
|
6135
|
-
me.
|
6156
|
+
me.sendResponse.call (me, responsePdu, responseVarbinds);
|
6136
6157
|
}
|
6137
6158
|
}
|
6138
6159
|
};
|
@@ -6234,30 +6255,10 @@ Subagent.prototype.getBulkRequest = function (pdu) {
|
|
6234
6255
|
this.request (pdu, getBulkVarbinds);
|
6235
6256
|
};
|
6236
6257
|
|
6237
|
-
Subagent.prototype.
|
6238
|
-
|
6239
|
-
|
6240
|
-
|
6241
|
-
transactionID: requestPdu.transactionID,
|
6242
|
-
packetID: requestPdu.packetID,
|
6243
|
-
sysUpTime: 0,
|
6244
|
-
error: 0,
|
6245
|
-
index: 0,
|
6246
|
-
varbinds: varbinds
|
6247
|
-
});
|
6248
|
-
this.sendPdu (pdu, null);
|
6249
|
-
};
|
6250
|
-
|
6251
|
-
Subagent.prototype.sendSetResponse = function (setPdu) {
|
6252
|
-
var responsePdu = AgentXPdu.createFromVariables ({
|
6253
|
-
pduType: AgentXPduType.Response,
|
6254
|
-
sessionID: setPdu.sessionID,
|
6255
|
-
transactionID: setPdu.transactionID,
|
6256
|
-
packetID: setPdu.packetID,
|
6257
|
-
sysUpTime: 0,
|
6258
|
-
error: 0,
|
6259
|
-
index: 0,
|
6260
|
-
});
|
6258
|
+
Subagent.prototype.sendResponse = function (responsePdu, varbinds) {
|
6259
|
+
if ( varbinds ) {
|
6260
|
+
responsePdu.varbinds = varbinds;
|
6261
|
+
}
|
6261
6262
|
this.sendPdu (responsePdu, null);
|
6262
6263
|
};
|
6263
6264
|
|
package/lib/mib.js
CHANGED
@@ -372,13 +372,11 @@ var MIB = function (dir) {
|
|
372
372
|
Object[Symbols[i - 2]]['OID'] = '0.0';
|
373
373
|
Object[Symbols[i - 2]]['NameSpace'] = 'null';
|
374
374
|
} else {
|
375
|
-
this.
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
// Object[Symbols[i - 2]]['ObjectName'] = Symbols[i - 2];
|
381
|
-
});
|
375
|
+
const { oidString, nameString } = this.getOidAndNamePaths(Object[Symbols[i - 2]]['OBJECT IDENTIFIER'], Symbols[i - 2], ModuleName);
|
376
|
+
Object[Symbols[i - 2]]['OID'] = oidString;
|
377
|
+
Object[Symbols[i - 2]]['NameSpace'] = nameString;
|
378
|
+
// Object[Symbols[i - 2]]['ModuleName'] = ModuleName;
|
379
|
+
// Object[Symbols[i - 2]]['ObjectName'] = Symbols[i - 2];
|
382
380
|
}
|
383
381
|
|
384
382
|
} else {
|
@@ -533,13 +531,11 @@ var MIB = function (dir) {
|
|
533
531
|
Object[Symbols[r - 1]]['OID'] = '0.0';
|
534
532
|
Object[Symbols[r - 1]]['NameSpace'] = 'null';
|
535
533
|
} else {
|
536
|
-
this.
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
//Object[Symbols[r - 1]]['ObjectName'] = Symbols[r - 1];
|
542
|
-
});
|
534
|
+
const { oidString, nameString } = this.getOidAndNamePaths(Object[Symbols[r - 1]]['OBJECT IDENTIFIER'], Symbols[r - 1], ModuleName);
|
535
|
+
Object[Symbols[r - 1]]['OID'] = oidString;
|
536
|
+
Object[Symbols[r - 1]]['NameSpace'] = nameString;
|
537
|
+
// Object[Symbols[r - 1]]['ModuleName'] = ModuleName;
|
538
|
+
// Object[Symbols[r - 1]]['ObjectName'] = Symbols[r - 1];
|
543
539
|
}
|
544
540
|
if ( Object[Symbols[r - 1]]['REVISIONS-DESCRIPTIONS'] &&
|
545
541
|
Object[Symbols[r - 1]]['REVISIONS-DESCRIPTIONS'].length == 1 &&
|
@@ -732,71 +728,71 @@ var MIB = function (dir) {
|
|
732
728
|
}
|
733
729
|
callback(summary);
|
734
730
|
},
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
}
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
}
|
751
|
-
midID.push(oid);
|
752
|
-
if ( ID != '' ) {
|
753
|
-
midID.push(ID);
|
754
|
-
}
|
755
|
-
if ( OD != '' ) {
|
756
|
-
midOD.push(OD);
|
757
|
-
}
|
758
|
-
midOD.push(ObjectName);
|
759
|
-
callback(midID.join('.'), midOD.join('.'));
|
760
|
-
return;
|
761
|
-
}
|
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
|
-
// cater for unannotated middle entries
|
731
|
+
getOidAndNamePaths: function (OBJECT_IDENTIFIER, ObjectName, ModuleName) {
|
732
|
+
const entries = OBJECT_IDENTIFIER.split(/\s+/);
|
733
|
+
const parent = entries.shift();
|
734
|
+
const finalEntries = entries.pop();
|
735
|
+
const nameEntries = [];
|
736
|
+
const oidEntries = [];
|
737
|
+
// process middle entries if any
|
738
|
+
// e.g. { enterprises pwg(2699) mibs(1) jobmonMIB(1) }
|
739
|
+
for (const entry of entries) {
|
740
|
+
const match = entry.match(/(.*)\((.+)\)$/);
|
741
|
+
if ( match ) {
|
742
|
+
oidEntries.push(match[2]);
|
743
|
+
nameEntries.push(match[1]);
|
744
|
+
} else {
|
745
|
+
// cater for unannotated middle entries (use number entries for name entries)
|
769
746
|
// e.g. { enterprises 2699 1 1 }
|
770
|
-
|
771
|
-
|
772
|
-
midOD.push(entry);
|
773
|
-
} else {
|
774
|
-
midID.push(match[2]);
|
775
|
-
midOD.push(match[1]);
|
776
|
-
}
|
747
|
+
oidEntries.push(entry);
|
748
|
+
nameEntries.push(entry);
|
777
749
|
}
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
ID = midID.join('.');
|
786
|
-
OD = midOD.join('.');
|
750
|
+
}
|
751
|
+
// ignore name entry if it exists on final OID entry - use object name instead
|
752
|
+
// e.g. for { mibs jobmonMIB(1) } we would ignore the "jobmonMIB" name
|
753
|
+
let finalOid;
|
754
|
+
if ( finalEntries.includes('(') ) {
|
755
|
+
const oidSplit = finalEntries.match(/(.*)\((.+)\)$/);
|
756
|
+
finalOid = oidSplit[2];
|
787
757
|
} else {
|
788
|
-
|
789
|
-
ID = ID == '' ? oid : [oid, ID].join('.');
|
790
|
-
OD = OD == '' ? parent : [parent, OD].join('.');
|
758
|
+
finalOid = finalEntries;
|
791
759
|
}
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
760
|
+
oidEntries.push(finalOid);
|
761
|
+
nameEntries.push(ObjectName);
|
762
|
+
let parentOidPrefix;
|
763
|
+
let parentNamePrefix;
|
764
|
+
if ( parent == 'iso' ) {
|
765
|
+
parentOidPrefix = '1';
|
766
|
+
parentNamePrefix = 'iso';
|
767
|
+
} else {
|
768
|
+
// find parent object
|
769
|
+
// first look in the current module
|
770
|
+
let parentObject = this.Modules[ModuleName][parent];
|
771
|
+
// if not found, find the import entry for the object
|
772
|
+
if ( ! parentObject ) {
|
773
|
+
const importModules = Object.keys(this.Modules[ModuleName]['IMPORTS']);
|
774
|
+
for (let importModule of importModules) {
|
775
|
+
if (this.Modules[importModule][parent]) {
|
776
|
+
parentObject = this.Modules[importModule][parent];
|
777
|
+
break;
|
778
|
+
}
|
797
779
|
}
|
798
780
|
}
|
781
|
+
if ( ! parentObject ) {
|
782
|
+
// occurs for out-of-order dependencies in a module
|
783
|
+
// console.warn('Parent object not found for ' + parent);
|
784
|
+
return {
|
785
|
+
oidString: '',
|
786
|
+
nameString: ''
|
787
|
+
};
|
788
|
+
}
|
789
|
+
parentOidPrefix = parentObject['OID'];
|
790
|
+
parentNamePrefix = parentObject['NameSpace'];
|
799
791
|
}
|
792
|
+
return {
|
793
|
+
oidString: parentOidPrefix + '.' + oidEntries.join('.'),
|
794
|
+
nameString: parentNamePrefix + '.' + nameEntries.join('.')
|
795
|
+
};
|
800
796
|
}
|
801
797
|
});
|
802
798
|
|