Pike v8.1 release 6

Method Protocols.SNMP.agent()->set_get_oid_callback()


Method set_get_oid_callback

void set_get_oid_callback(string oid, function(:void) cb)

Description

set the Get request callback function for an Object Identifier

Parameter oid

the string object identifier, such as 1.3.6.1.4.1.132.2 or an asterisk (*) to serve as the handler for all requests for which a handler is specified.

Parameter cb

the function to call when oid is requested by a manager the function should take 2 arguments: a string containing the requested oid and the body of the request as a mapping. The function should return an array containing 3 or 4 elements: The first is a boolean indicating success or failure. If success, the next 2 elements should be the SNMP data type of the result followed by the result itself. If failure, the next 2 elements should be the error-status such as Protocols.SNMP.ERROR_TOOBIG and the second is the error-index, if any. If a fourth array element is returned, it should contain the OID that the callback actually fetched (typically different from the requested OID for REQUEST_GETNEXT requests). This is needed for e.g. snmpwalk to work properly.

Note

there can be only one callback per object identifier. calling this function more than once with the same oid will result in the new callback replacing the existing one.