net-snmp 3.11.0 → 3.11.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.
Files changed (3) hide show
  1. package/README.md +8 -0
  2. package/index.js +36 -34
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3363,6 +3363,14 @@ Example programs are included under the module's `example` directory.
3363
3363
 
3364
3364
  * Fix parent object retrieval to respect MIB module imports
3365
3365
 
3366
+ ## Version 3.11.1 - 30/03/2024
3367
+
3368
+ * Add error status and index handling to AgentX subagent
3369
+
3370
+ ## Version 3.11.2 - 03/04/2024
3371
+
3372
+ * Add provider to MIB request
3373
+
3366
3374
  # License
3367
3375
 
3368
3376
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
package/index.js CHANGED
@@ -4537,6 +4537,7 @@ var MibRequest = function (requestDefinition) {
4537
4537
  this.address = Mib.convertOidToAddress (requestDefinition.oid);
4538
4538
  this.oid = this.address.join ('.');
4539
4539
  this.providerNode = requestDefinition.providerNode;
4540
+ this.provider = this.providerNode ? this.providerNode.provider : null;
4540
4541
  this.instanceNode = requestDefinition.instanceNode;
4541
4542
  };
4542
4543
 
@@ -5506,6 +5507,19 @@ AgentXPdu.prototype.readHeader = function (buffer) {
5506
5507
  this.payloadLength = buffer.readUInt32BE ();
5507
5508
  };
5508
5509
 
5510
+ AgentXPdu.prototype.getResponsePduForRequest = function () {
5511
+ const responsePdu = AgentXPdu.createFromVariables({
5512
+ pduType: AgentXPduType.Response,
5513
+ sessionID: this.sessionID,
5514
+ transactionID: this.transactionID,
5515
+ packetID: this.packetID,
5516
+ sysUpTime: 0,
5517
+ error: 0,
5518
+ index: 0
5519
+ });
5520
+ return responsePdu;
5521
+ };
5522
+
5509
5523
  AgentXPdu.createFromVariables = function (vars) {
5510
5524
  var pdu = new AgentXPdu ();
5511
5525
  pdu.flags = vars.flags ? vars.flags | 0x10 : 0x10; // set NETWORK_BYTE_ORDER to big endian
@@ -6040,13 +6054,14 @@ Subagent.prototype.response = function (pdu) {
6040
6054
  };
6041
6055
 
6042
6056
  Subagent.prototype.request = function (pdu, requestVarbinds) {
6043
- var me = this;
6044
- var varbindsCompleted = 0;
6045
- var varbindsLength = requestVarbinds.length;
6046
- var responseVarbinds = [];
6047
-
6048
- for ( var i = 0; i < requestVarbinds.length; i++ ) {
6049
- var requestVarbind = requestVarbinds[i];
6057
+ const me = this;
6058
+ const varbindsLength = requestVarbinds.length;
6059
+ const responseVarbinds = [];
6060
+ const responsePdu = pdu.getResponsePduForRequest ();
6061
+ let varbindsCompleted = 0;
6062
+
6063
+ for ( let i = 0; i < varbindsLength; i++ ) {
6064
+ const requestVarbind = requestVarbinds[i];
6050
6065
  var instanceNode = this.mib.lookup (requestVarbind.oid);
6051
6066
  var providerNode;
6052
6067
  var mibRequest;
@@ -6097,14 +6112,21 @@ Subagent.prototype.request = function (pdu, requestVarbinds) {
6097
6112
  }
6098
6113
 
6099
6114
  (function (savedIndex) {
6100
- var responseVarbind;
6101
6115
  mibRequest.done = function (error) {
6116
+ let responseVarbind;
6102
6117
  if ( error ) {
6103
6118
  responseVarbind = {
6104
6119
  oid: mibRequest.oid,
6105
6120
  type: error.type || ObjectType.Null,
6106
6121
  value: error.value || null
6107
6122
  };
6123
+ if ( (typeof responsePdu.errorStatus == "undefined" || responsePdu.errorStatus == ErrorStatus.NoError) && error.errorStatus != ErrorStatus.NoError ) {
6124
+ responsePdu.error = error.errorStatus;
6125
+ responsePdu.index = savedIndex + 1;
6126
+ }
6127
+ if ( error.errorStatus != ErrorStatus.NoError ) {
6128
+ responseVarbind.errorStatus = error.errorStatus;
6129
+ }
6108
6130
  } else {
6109
6131
  if ( pdu.pduType == AgentXPduType.TestSet ) {
6110
6132
  // more tests?
@@ -6130,9 +6152,9 @@ Subagent.prototype.request = function (pdu, requestVarbinds) {
6130
6152
  if ( ++varbindsCompleted == varbindsLength) {
6131
6153
  if ( pdu.pduType == AgentXPduType.TestSet || pdu.pduType == AgentXPduType.CommitSet
6132
6154
  || pdu.pduType == AgentXPduType.UndoSet) {
6133
- me.sendSetResponse.call (me, pdu);
6155
+ me.sendResponse.call (me, responsePdu);
6134
6156
  } else {
6135
- me.sendGetResponse.call (me, pdu, responseVarbinds);
6157
+ me.sendResponse.call (me, responsePdu, responseVarbinds);
6136
6158
  }
6137
6159
  }
6138
6160
  };
@@ -6234,30 +6256,10 @@ Subagent.prototype.getBulkRequest = function (pdu) {
6234
6256
  this.request (pdu, getBulkVarbinds);
6235
6257
  };
6236
6258
 
6237
- Subagent.prototype.sendGetResponse = function (requestPdu, varbinds) {
6238
- var pdu = AgentXPdu.createFromVariables ({
6239
- pduType: AgentXPduType.Response,
6240
- sessionID: requestPdu.sessionID,
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
- });
6259
+ Subagent.prototype.sendResponse = function (responsePdu, varbinds) {
6260
+ if ( varbinds ) {
6261
+ responsePdu.varbinds = varbinds;
6262
+ }
6261
6263
  this.sendPdu (responsePdu, null);
6262
6264
  };
6263
6265
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.11.0",
3
+ "version": "3.11.2",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {