Implement a provider handler
masterA handler is a callback function called before a MIB request is processed. It receives a MibRequest object.
Request Types and Handling:
GetRequest, GetNextRequest, GetBulkRequest: To serve dynamic values (like
sysUpTime), you must assign the value tomibRequest.instanceNode.valuebefore callingdone(). Alternatively, callmib.setScalarValue(providerName, value).SetRequest: The agent validates and casts the value into
mibRequest.setValuebefore the handler runs. The agent commits the value tomibRequest.instanceNode.valueautomatically during the commit pass. You typically only need to calldone()ordone({errorStatus: ...})to reject the set.
MibRequest Properties:
done(error?): Completes the request. Pass an error object like{errorStatus: snmp.ErrorStatus.GeneralError}to signal failure.oid: The instance OID being operated on.operation: The request type (snmp.PduType).setValue/setType: (SetRequest only) The value and type received in the varbind.instanceNode.value: The location to assign read values for Get requests.
// Example handler for a dynamic scalar
const handler = (mibRequest) => {
// For a GetRequest, assign the dynamic value
mibRequest.instanceNode.value = computeDynamicValue();
mibRequest.done();
};
// Example handler for a SetRequest with validation
const handler = (mibRequest) => {
if (someValidationFailed) {
mibRequest.done({ errorStatus: snmp.ErrorStatus.GenErr });
} else {
mibRequest.done();
}
};