SNMP Subagent Programmer's Guide

Programming Tutorials
SNMP Subagent Programmer’s Guide119728 2-13
Hello World Program
The variables are assigned data types that correspond to the SYNTAX attribute of
the MIB definition for the object. For example, since helloOutputText has a MIB
definition with a SYNTAX specification of DisplayString, the helloText variable is
assigned the type DisplayString. The header file named smitypeh contains typedef
declarations that map these data types to C data types.
Hello World initializes each variable as follows:
3. The compiler pragma nowarn (93) suppresses warnings from the C compiler
indicating that some of the variables declared in the GDMOC output file, helloh, are
never referenced. For example, GDMOC generates Set functions that can handle
tables. The index and context variables required for tables are not used for scalar
objects, so the compiler generates a warning. Warning suppression is turned off
after helloh has been included.
4. This directive includes helloh, the file containing the MIB definition compiled with
GDMOC. Code in helloh references the variables for the MIB objects to be
managed, so the variables had to be declared earlier.
5. An integer variable named time_to_die is initialized to 0. Later, this variable is used
to set up the main loop, which polls the agent for pending requests and conditionally
sends a trap.
Main Control Block
The main control block manages the MIB object variables and calls run-time library
functions to control interactions with the NonStop agent:
6. The main function expects two arguments: the executable subagent name (argv[0])
and the name of the agent process with which it should interact (argv[1]). These
arguments are assigned values at invocation:
RUN HELLO $ZSNMP
argv[0] argv[1]
The main function returns a 0 when the subagent terminates normally. A value of 1
(warning) or 2 (fatal error) is otherwise returned on termination.
7. Several variables needed for subsequent management function calls are declared:
8. If the main function does not receive two arguments (the subagent and agent names),
the subagent terminates after printing a message.
helloText Hello World
helloPrintFreq 15
helloPrintCnt 0
dummy Is used in the call to mgmt_poll().
mgmt_env Is used in the call to mgmt_init_env().
mgmt_hello_handle Is used in calls to mgmt_new_instance() and
mgmt_del_instance().