net-snmp 3.18.1 → 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 +4 -0
  2. package/index.js +17 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3457,6 +3457,10 @@ Example programs are included under the module's `example` directory.
3457
3457
 
3458
3458
  * Add agent option key for MIB options
3459
3459
 
3460
+ ## Version 3.18.2 - 06/01/2025
3461
+
3462
+ * Add conversion of scalar defVal enumeration name to number on assignment
3463
+
3460
3464
  # License
3461
3465
 
3462
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 ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.18.1",
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": {