Java Dynamic Management Kit 3.2 Programming Guide
[ Previous ][ Fast Back ]Chapter 19. Developing SNMP Agents With the Java Dynamic Management Kit[ Fast Forward ][ Next ]

Loading MIBs Into an SNMP Adaptor

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:

The MIB object provides two init functions, as shown in Table 19-1.

Table 19-1. init Functions

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.

Port Allocations

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.

Initializing a MIB Within the Framework

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");

Initializing a MIB in a Standalone Agent

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();

Binding a MIB to an SNMP Adaptor

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:

Statically Loading a MIB

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:

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);

Dynamic Loading

To load a MIB dynamically using the HTML adaptor:

  1. Use the m-bean browser web page to instantiate the MIB you want to load.
  2. If you want your MIB to be accessible through SNMP, bind it to an existing SNMP 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


[ Previous ][ Home ][ Next ]
Implementing Access Methods[ Up ]Advanced use of the SNMP Adaptor