Skip to content

MibNode.setValue() is no longer defined for readonly OIDs #297

@thom-nic

Description

@thom-nic

We have dynamic handlers for many read-only OIDs. For example:

const SYS_OID = '1.3.6.1.2.1.1';

class SystemProvider extends MibProvider {
  constructor(mib) {
    super(mib);
    this._handlers = [
      {
        name: 'sysUpTime',
        oid: `${SYS_OID}.3`,
        type: MibProviderType.Scalar,
        scalarType: ObjectType.TimeTicks,
        maxAccess: MaxAccess['read-only'],
        value: 0,
        handler: (mibRequest) => {
          mibRequest.instanceNode.setValue(ObjectType.TimeTicks, Math.min(Math.round(os.uptime() * 100), 2**32 - 1));
          mibRequest.done();
        },
      },
      ....

I see in v3.25, MibNode.setValue() was removed: 3.24.0...3.25.0#diff-e727e4bdf3657fd1d798edcd6b099d6e092f8573cba266154583a746bba0f346L3986

Is the correct migration path to do something like this instead?

        handler: (mibRequest) => {
          const { instanceNode } = mibRequest;
          const constraints = instanceNode.getConstraintsFromProvider();
          const value = Math.min(Math.round(os.uptime() * 100), 2**32 - 1);
          const castValue = ObjectTypeUtil.castSetValue(ObjectType.TimeTicks, value, constraints);
          if ( ! instanceNode.validateValue(ObjectType.TimeTicks, castValue) {
            // throw error?
          }
          instanceNode.value = castValue;
          mibRequest.done();
        },

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions