SNMP Subagent Programmer's Guide
Hello World Program
2-14 119728—SNMP Subagent Programmer’s Guide
Programming Tutorials
9. The mgmt_init_env() function initiates communication with the NonStop agent. If
this function fails, the subagent terminates after printing a message. The
mgmt_init_env() function expects five arguments, in the following order:
•
The NonStop agent process name (stored in argv[1]).
•
The object identifier of the subagent, stored in GI_hello. GI_hello is a structure
generated by GDMOC. GDMOC names the structure by adding the prefix GI_
to the MIB name.
•
A textual description of the subagent (passed by value as Hello World
Example).
•
Two arguments that are ignored.
If mgmt_init_env() returns NULL, an error occurred, and the subagent prints a
message and stops. If it succeeds, mgmt_env identifies the subagent-agent
connection for use in subsequent management function calls.
10. The mgmt_new_instance() function initiates SNMP manager access to MIB objects.
This function expects three arguments:
•
The pointer returned from the call to mgmt_init_env() (mgmt_env).
•
A pointer to a class_definition structure identifying the MIB objects. This
structure is generated by GDMOC, which names the structure by adding the
prefix SMI_GROUP_ to the MIB object name assigned in the MIB definition.
In this case, the structure is named SMI_GROUP_hello.
•
A pointer to a data structure used for tabular MIB objects. Since the Hello
World MIB contains no tables, this argument is set to NULL.
If mgmt_new_instance() returns NULL, an error occurred, and the subagent prints a
message and stops. If it succeeds, the MIB objects are available for access by
SNMP managers.
11. A loop for processing incoming requests and conditionally sending a trap is set up.
12. The mgmt_poll() function polls the NonStop agent for requests, then processes them
when they come in. A waited call, this function blocks further processing until the
NonStop agent indicates a request needs processing. Then, the function decodes the
request; performs a Get, GetNext, or Set operation; and returns a response to the
NonStop agent. This function expects three arguments:
•
The pointer returned from the call to mgmt_init_env() (mgmt_env).
•
A pointer to a structure (timeval) that specifies how long the function should
block if no requests are pending. This subagent assigns the value NULL, so this
call blocks until a request is received.
•
A value describing the size of the message received from the NonStop agent.
This argument is useful only when you use mgmt_poll() in conjunction with the
management function mgmt_read_nowait(), so this subagent sets the argument
(dummy) to 0.