In the SNMP alarm method for long-running data collection, the module registers an SNMP alarm to call a function at a specified interval. The interval is specified in seconds. The function can be called one time, or called repeatedly until the alarm is unregistered. The module sets a flag that causes the agent to delegate the SNMP request. By delegating a request, the agent avoids blocking other requests while responding to a request. The agent caches the SNMP request information to be retrieved later when the request is handled. The demo_module_9 example demonstrates the SNMP-alarm-based approach.
The demo_module_9 code is located by default in /usr/demo/sma_snmp/demo_module_9. The README_demo_module_9 file within that directory contains instructions that describe how to perform the following tasks:
Compile source files to generate a shared library object that implements a module
Set up the agent to dynamically load the module
Test the module with snmp commands to show that the module is functioning as expected
The demo_module_9 example implements the objects defined in the SDK-DEMO9-MIB.txt. The module demonstrates how to implement objects that normally would block the agent as the agent waits for external events. The agent can continue responding to other requests while this implementation waits.
This example uses the following features:
Sets the delegated member of the requests structure to 1 to indicate to the agent that this request should be delayed. The agent queues this request to be handled later and then is available to handle other requests. The agent is not blocked by this request.
Registers an SNMP alarm to update the results at a later time.
An important aspect of the demo_module_9 example is the relationship between the SNMP timeout and the delay time interval of the module. The delay time interval is the interval in seconds after which the agent sends an alarm to the module. The delay_time variable in the module stores this value. By default, the delay time is set to 1 in the module. You can change this value by issuing an snmpset command on the delayedInstanceOid object and supplying an integer value. The set_demo_module_9 script does issue the snmpset command to change the delay time interval. The new time interval value is used by the module to register for an alarm with the agent.
The agent calls the module when a snmpget or snmpset is issued on the delayedInstanceOid object. Instead of returning the requesting data right away, the module sets a flag to tell the agent that the request processing might take a while. The agent is free to handle other requests. The module then registers an alarm with the agent. The module needs some way to get the agent to return to the module and return the requested data when the data collection has completed. In demo_module_9, a one-time alarm is set to go off in 1 second. If you want a longer data collection, you can set the delay_time value to a longer interval. You can also set the alarm to go off repeatedly at a specified interval.
The module registers the alarm with a callback function. At the specific alarm interval, the agent calls the callback function in the module. In demo_module_9, the callback function is return_delayed_response(), which actually handles the SNMP GET or SNMP SET request.
The client that requested the data with SNMP GET must wait for the response from the agent. The snmpget command and other Net-SNMP tools have a default timeout value of 5 seconds. The client is likely to time out before getting the requested response. For this reason, you should increase the timeout value for the snmpget and snmpset commands.
You should increase the timeout of the command the amount of time required to complete the data collection. If you are doing an snmpset, make the timeout value 3 or 4 times longer than the delay time interval. A longer timeout is needed because a SET operation is more time-consuming than a GET. The agent makes several calls to the module to process a single SET, and each call is delayed by the delay value.
The -t option is used to set the timeout value. See thesnmpcmd(1M) man page for more information about common command-line options for Net-SNMP tools.