Java Dynamic Management Kit 3.2 Programming Guide | ||||
---|---|---|---|---|
![]() | ![]() | Chapter 20. Developing SNMP Managers With the Java Dynamic Management Kit | ![]() |
The Java Dynamic Management Kit SNMP manager API enables you to develop applications to manage SNMP agents. The SNMP manager API can be used synchronously for simple applications or asynchronously in more demanding situations. There are four main components of the SNMP manager API:
SNMP Peer
SNMP Parameters
SNMP Session
SNMP Request
The SNMP manager uses instances of the SnmpPeer class to represent remote agents. Each remote agent is represented by a single SnmpPeer object. An SnmpPeer can be instantiated with the IP address, the hostname and port, or the hostname of the remote agent. The SnmpPeer object holds the following information:
IP address of the remote agent
Port number of the remote agent
Maximum request packet size
Maximum number of SNMP object identifiers (OIDs) that can be encoded in a single request packet
Number of retries allowed
Time-out
IP address list for alternate hosts
SnmpParameter object associated with the peer
The SnmpParameter class contains information on the SNMP read and write communities, and the SNMP version. This information is used by an SnmpSession object while exchanging packets with an SnmpPeer. An SnmpPeer can be configured explicitly to use a specific SnmpParameter object. Multiple SnmpPeer objects can share a single parameter object. Changing values for an SnmpParameter object affects all SnmpPeer objects that use that object.
When you change these parameters, the changes are applied to all active messages. Example 20-1 shows the instantiation and configuration of an SnmpPeer object representing a remote agent using port 8085 on host summer.
Example 20-1. Instantiating and Configuring an SnmpPeer Object
String hostname = String ("summer"); int port = 8085; // Create a SnmpPeer object for representing remote agent SnmpPeer agent= new SnmpPeer(hostname, port); // Create parameters to associate to the remote agent. // When creating the parameter object, you can specify the read and write // community to be used when querying the agent. SnmpParameters params= new SnmpParameters("public", "private"); // The newly created parameter object must be associated with the agent. agent.setSnmpParam(params); |
The SNMP manager session is controlled by an instance of the SnmpSession class. An SnmpSession object creates and manages SNMP requests to multiple peers. The SnmpSession object can be instantiated with a default peer so that all requests created without specifying a peer use the default. The default peer can be set while the SnmpSession object is running.
Each SNMP manager session uses a dispatcher to service all of the requests it creates. It uses an SNMP socket which, unless configured otherwise, uses the default socket specified by the SnmpSocket object. The SNMP manager session can also be configured to use a separate socket exclusively.
The SnmpSession class provides methods to create requests. Individual requests perform a specific SNMP operation. When used asynchronously, the session maintains the list of all active requests and responses. Requests are retried if the peer does not respond within a specified time. The maximum retry limit is specified by the SnmpPeer objects. You can cancel any active requests at any time during a session.
Example 20-2 shows the instantiation and configuration of an SnmpSession using the SnmpPeer instantiated in Example 20-1 as the default peer.
Example 20-2. Instantiating and Configuring an SnmpSession
// Build the session. SnmpSession session= new SnmpSession("Manager session"); // Use "agent" as the default peer session.setDefaultPeer(agent); |
SNMP sessions can be configured for specific situations using methods provided in the SnmpOptions object. Setting these options affects all subsequent requests. Existing requests are also affected, depending on the nature of the option. The SNMP session options are:
Allow multiplexing. The variable binding lists of different requests in the same session are merged when sending the request. The responses are de-multiplexed.
Fix errored PDU. If a response contains an error, the errored variable is removed from the variable binding list and the request is re-sent to the agent.
Handle oversized PDUs. If a request is too big to be held in one SNMP PDU, it is split and sent in parts.
The SnmpVarbindList contains a list of SnmpVar objects. Each SnmpVar object holds information for a MIB variable and consists of:
The corresponding OID object for the MIB variable.
A value associated with that OID instance.
The status of the SnmpVar that indicates whether there is an exception as stated in the SNMP v2 specification.
Instances of the SnmpRequest class enable you to send requests, handle retries, time-outs, and process responses from an agent. An SnmpRequest is created using a specific SnmpSession and SnmpPeer. The SnmpPeer object determines the destination of the request and controls the characteristics of the messaging between manager and agent.
The SnmpRequest object creates a request that is used to perform one or more of the following SNMP operations:
Get
GetNext
Set
GetBulk on a specified SnmpVarbindList
A request becomes active when a user submits the request successfully. When any event happens that changes the state of the request to done, the request becomes inactive. At any time, one or more requests active in a session can be cancelled.
![]() | ![]() | ![]() |
Developing SNMP Managers With the Java Dynamic Management Kit | ![]() | Operation of the SNMP Manager |