Java Dynamic Management Kit 3.2 Programming Guide | ||||
---|---|---|---|---|
![]() | ![]() | Chapter 19. Developing SNMP Agents With the Java Dynamic Management Kit | ![]() | ![]() |
In the Java Dynamic Management Kit, a MIB is represented by a subclass of the SnmpMib class in the com.sun.jaw.snmp.agent package. The generated class is named using the module name specified in the MIB definition. For example, mibgen generates a class called RFC1213_MIB.java to represent MIB II. The class initializes all the SNMP metadata required to handle the MIB and creates a new instance of each group.
If you do not need to support a specific group, you can edit the MIB class file and comment out the SNMP group you do not want to support.
If you do not need to support a specific variable in a group, you can do one of the following:
Throw an exception each time methods associated to the variable are called
Edit the metadata file associated with the group
The MIB object provides two init functions, as shown in Table 19-1.
init | Initializes all the SNMP metadata required to handle the MIB and creates a new instance of each group. |
initCmf | The same as init but in addition it registers each group in the framework. |
When an agent instantiates an SNMP adaptor in the Solaris operating environment, it binds by default to port 161. To be able to bind to port 161, the agent must be started by the root user of the system.
If the Solaris SNMP agent (snmpdx) is also running on the same machine, there will be a conflict over port allocations. To resolve this conflict, stop the Solaris SNMP agent (snmpdx) or specify that the agent binds to another port.
To stop the Solaris SNMP agent (snmpdx), as root type:
prompt# /etc/init.d/init.snmpdx stop |
To bind to a different port, set the object name of the SNMP adaptor explicitly, specifying the port number by using the port=portno search key.
Example 19-10 shows how to initialize the MIB within the framework by calling the newObject() method of the framework.
Example 19-10. Initializing a MIB Within the Framework
cmf.newObject("RFC1213_MIB", "SNMP:RFC1213_MIB"); |
Example 19-11 shows how to initialize a MIB in a standalone agent.
Example 19-11. Initializing a MIB in a Standalone Agent
RFC1213_MIB mib2= new RFC1213_MIB(); // Now initialize the mib // mib2.init(); |
A MIB object needs to be bound to an SNMP adaptor to be manageable through the SNMP protocol. A MIB can be bound or unbound at any time.
To retrieve the bind state of a MIB, invoke the getBindingState() method of the SnmpMibAgent class.
To bind a MIB to an SNMP adaptor, do either of the following:
Give the pointer to an SNMP adaptor object directly.
Give the object name of an SNMP adaptor object.
Loading a MIB statically enables you to build a standalone agent that does not require any Java Dynamic Management Kit services. Example 19-12 shows how to load a MIB statically. Loading a MIB statically involves:
Creating an instance of an SNMP AdaptorServerImpl object
Creating and initializing the MIB
Binding the MIB to the adaptor you have instantiated
Example 19-12. Loading a MIB Statically
// Create the SNMP adaptor. (Use default SNMP port 161) // AdaptorServerImpl snmpStack= new AdaptorServerImpl() RFC1213_MIB mib2= new RFC1213_MIB(); // Now initialize the mib // mib2.init(); // Bind the MIB to the adaptor // mib2.setSnmpAdaptor(snmpStack); |
To load a MIB dynamically using the HTML adaptor:
Set the SnmpAdaptorName property of the MIB instance using the object name of the SNMP adaptor to which you want to bind your MIB. The default name is: defaultDomain:com.sun.jaw.impl.adaptor.AdaptorMO.protocol=snmp, port=161
![]() | ![]() | ![]() |
Implementing Access Methods | ![]() | Advanced use of the SNMP Adaptor |