SNMP Subagent Programmer's Guide

Programming Tutorials
SNMP Subagent Programmer’s Guide—119728 2-11
Hello World Program
Logic Flow
As Figure 2-1 illustrates, Hello World uses several management functions. All but one
of these library functions are needed by all subagents:
1. The mgmt_init_env() function establishes communication between the NonStop
agent and the subagent.
2. The mgmt_new_instance() function identifies the MIB objects managed by the
subagent that can be manipulated by an SNMP manager. This function registers
objects with both the NonStop agent and the run-time library.
3. The mgmt_poll() function polls the NonStop agent for incoming requests, and
processes requests for objects identified in an earlier mgmt_new_instance() call.
4. The mgmt_del_instance() function de-registers, from the run-time library, MIB
objects identified in an earlier call to mgmt_new_instance, releasing memory used
for their management.
5. The mgmt_term_env() function terminates connection with the NonStop agent and
de-registers, from the agent, all MIB objects registered by using
mgmt_new_instance(). Now the MIB objects are available for other subagent
processes to register for their use.
Other run-time library functions are optional. Hello World, for example, sends a trap.
The mgmt_trap() function performs this operation. Hello World calls mgmt_trap()
whenever a manager changes the value of the variable named helloPrintFreq.
Source Code
The Hello World source code is shown in Example 2-2. Numbers in the example
correspond to comments in the discussions located between here and the example.
Global Declarations
A subagent must always provide certain constructs globally:
1. Every subagent needs to include five header files: tdmporth, machtyph, syspubh,
smitypeh, and mgmtpubh. These files contain definitions the subagent needs to
access run-time library functions and the MIB compiler output.
2. Every MIB object that is not managed by using an access function provided by the
subagent needs to be declared globally. In the case of Hello World, three variables
are required:
helloText The variable for the value of helloOutputText
helloPrintFreq The variable for the value of helloPrintFreq
helloPrintCnt The variable for the value of helloPrintCnt