net-snmp 3.18.0 → 3.18.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 +12 -1
  2. package/index.js +19 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1598,7 +1598,8 @@ var options = {
1598
1598
  accessControlModelType: snmp.AccessControlModelType.None,
1599
1599
  engineID: "8000B98380XXXXXXXXXXXXXXXXXXXXXXXX", // where the X's are random hex digits
1600
1600
  address: null,
1601
- transport: "udp4"
1601
+ transport: "udp4",
1602
+ mibOptions: {}
1602
1603
  };
1603
1604
 
1604
1605
  var callback = function (error, data) {
@@ -1634,6 +1635,8 @@ an object, possibly empty, and can contain the following fields:
1634
1635
  * `sockets` - an array of objects containing triples of `transport`, `address` and `port` that
1635
1636
  can be used to specify multiple socket listeners. This option overrides any individual
1636
1637
  `transport`, `address` and `port` options.
1638
+ * `mibOptions` - an MIB options object that is passed to the `Mib` instance - see the MIB section
1639
+ for further details on this - defaults to the empty object.
1637
1640
 
1638
1641
  The `mib` parameter is optional, and sets the agent's singleton `Mib` instance.
1639
1642
  If not supplied, the agent creates itself a new empty `Mib` singleton. If supplied,
@@ -3450,6 +3453,14 @@ Example programs are included under the module's `example` directory.
3450
3453
 
3451
3454
  * Add MIB option to add scalar MIB object on scalar provider registration
3452
3455
 
3456
+ ## Version 3.18.1 - 06/01/2025
3457
+
3458
+ * Add agent option key for MIB options
3459
+
3460
+ ## Version 3.18.2 - 06/01/2025
3461
+
3462
+ * Add conversion of scalar defVal enumeration name to number on assignment
3463
+
3453
3464
  # License
3454
3465
 
3455
3466
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
package/index.js CHANGED
@@ -783,6 +783,15 @@ ObjectTypeUtil.doesStringMeetConstraints = function (value, constraints) {
783
783
  return true;
784
784
  };
785
785
 
786
+ ObjectTypeUtil.getEnumerationNumberFromName = function (enumeration, name) {
787
+ for ( const [enumNumber, enumName] of Object.entries (enumeration) ) {
788
+ if ( enumName === name ) {
789
+ return Number (enumNumber);
790
+ }
791
+ }
792
+ return null;
793
+ };
794
+
786
795
  /*****************************************************************************
787
796
  ** PDU class definitions
788
797
  **/
@@ -4199,10 +4208,15 @@ Mib.prototype.populateIndexEntryFromColumn = function (localProvider, indexEntry
4199
4208
  Mib.prototype.registerProvider = function (provider) {
4200
4209
  this.providers[provider.name] = provider;
4201
4210
  if ( provider.type == MibProviderType.Scalar ) {
4202
- if ( this.options?.addScalarDefaultsOnRegistration ) {
4203
- if ( provider.defVal ) {
4204
- this.setScalarValue (provider.name, provider.defVal);
4211
+ if ( this.options?.addScalarDefaultsOnRegistration && provider.defVal ) {
4212
+ let scalarValue;
4213
+ // If the scalar has an enumeration, set the value to the enumeration number derived from the defVal name
4214
+ if ( provider.constraints?.enumeration ) {
4215
+ scalarValue = ObjectTypeUtil.getEnumerationNumberFromName (provider.constraints.enumeration, provider.defVal);
4216
+ } else {
4217
+ scalarValue = provider.defVal;
4205
4218
  }
4219
+ this.setScalarValue (provider.name, scalarValue);
4206
4220
  }
4207
4221
  } else if ( provider.type == MibProviderType.Table ) {
4208
4222
  if ( provider.tableAugments ) {
@@ -4798,7 +4812,8 @@ var Agent = function (options, callback, mib) {
4798
4812
  this.engine = new Engine (options.engineID);
4799
4813
  this.authorizer = new Authorizer (options);
4800
4814
  this.callback = callback || function () {};
4801
- this.mib = mib || new Mib ();
4815
+ const mibOptions = mib?.options || options?.mibOptions || {};
4816
+ this.mib = mib || new Mib (mibOptions);
4802
4817
  this.context = "";
4803
4818
  this.forwarder = new Forwarder (this.listener, this.callback);
4804
4819
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.18.0",
3
+ "version": "3.18.2",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {