org.jboss.jmx.adaptor.snmp.agent
Class RequestHandlerImpl

java.lang.Object
  extended by org.jboss.jmx.adaptor.snmp.agent.RequestHandlerSupport
      extended by org.jboss.jmx.adaptor.snmp.agent.RequestHandlerImpl
All Implemented Interfaces:
Reconfigurable, RequestHandler, SnmpAgentRequestHandler

public class RequestHandlerImpl
extends RequestHandlerSupport
implements Reconfigurable

Implement RequestHandler with mapping of snmp get/set requests to JMX mbean attribute gets/sets. Currently only v1 / v2 PDUs are supported by the agent service.

Version:
$Revision: 110789 $
Author:
Heiko W. Rupp, Dimitris Andreadis, or Thomas Hauser

Field Summary
protected  java.util.SortedMap<org.snmp4j.smi.OID,BindEntry> bindings
          Bindings from oid to mbean
static java.lang.String NO_ENTRY_FOUND_FOR_OID
           
static java.lang.String SKIP_ENTRY
           
 
Fields inherited from class org.jboss.jmx.adaptor.snmp.agent.RequestHandlerSupport
clock, log, resourceName, server
 
Constructor Summary
RequestHandlerImpl()
          Default CTOR
 
Method Summary
 void addAttributeMappings(java.util.List<ManagedBean> mappings)
           
 org.snmp4j.smi.Variable getValueFor(org.snmp4j.smi.OID oid)
          Return the current value for the given oid
 void initialize(java.lang.String resourceName, javax.management.MBeanServer server, org.jboss.logging.Logger log, Clock uptime)
          Initialize
static org.snmp4j.smi.Variable prepForPdu(java.lang.Object val, org.snmp4j.smi.OID tableIndexOID)
          This method takes an Object that is typically going to be put into a VariableBinding for use in a PDU, and thus must be converted into an SNMP type based on it's type.
 void reconfigure(java.lang.String resName)
          Reconfigures the RequestHandler
 void removeAttributeMappings(java.util.List<ManagedBean> mappings)
           
 void SnmpAgentSessionError(org.snmp4j.Snmp session, int error, java.lang.Object ref)
           This method is invoked if an error occurs in the session.
 org.snmp4j.PDU snmpReceivedGet(org.snmp4j.PDU pdu)
           This method is defined to handle SNMP GET and GETNEXT requests that are received by the session.
 org.snmp4j.PDU snmpReceivedGetBulk(org.snmp4j.PDU pdu)
           This method handles SNMP GetBulk requests received in this session.
 void snmpReceivedPdu(org.snmp4j.Snmp session, java.net.InetAddress manager, int port, org.snmp4j.smi.OctetString community, org.snmp4j.PDU pdu)
           This method is defined to handle SNMP requests that are received by the session.
 org.snmp4j.PDU snmpReceivedSet(org.snmp4j.PDU pdu)
           This method is defined to handle SNMP Set requests that are received by the session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_ENTRY_FOUND_FOR_OID

public static final java.lang.String NO_ENTRY_FOUND_FOR_OID
See Also:
Constant Field Values

SKIP_ENTRY

public static final java.lang.String SKIP_ENTRY
See Also:
Constant Field Values

bindings

protected java.util.SortedMap<org.snmp4j.smi.OID,BindEntry> bindings
Bindings from oid to mbean

Constructor Detail

RequestHandlerImpl

public RequestHandlerImpl()
Default CTOR

Method Detail

initialize

public void initialize(java.lang.String resourceName,
                       javax.management.MBeanServer server,
                       org.jboss.logging.Logger log,
                       Clock uptime)
                throws java.lang.Exception
Initialize

Specified by:
initialize in interface RequestHandler
Overrides:
initialize in class RequestHandlerSupport
Parameters:
resourceName - A file containing get/set mappings
server - Our MBean-Server
log - The logger we use
uptime - The uptime of the snmp-agent subsystem.
Throws:
java.lang.Exception - in case of initialization problem

reconfigure

public void reconfigure(java.lang.String resName)
                 throws java.lang.Exception
Reconfigures the RequestHandler

Specified by:
reconfigure in interface Reconfigurable
Parameters:
resName - the file to configure from, usually the same used at initialization time.
Throws:
java.lang.Exception - in case of failure

snmpReceivedGetBulk

public org.snmp4j.PDU snmpReceivedGetBulk(org.snmp4j.PDU pdu)

This method handles SNMP GetBulk requests received in this session. Request is already validated. Builds a response and passes it back. A GetBulk request has two additional fields: nonRepeaters: the amount of scalar objects in the PDU maxRepetitions: the number of getNext requests to be done on the scalar objects. The parameter PDU is interpreted as follows: The first nonRepeaters elements in the VariableBinding list are retrieved with a simple GET snmp call. The remaining (size - nonRepeaters) elements in the VariableBinding list have maxRepetitions GETNEXT calls upon them. All of these VariableBindings are added into the response. The resultant response will have N + (M*R) VariableBindings This method functions according to the protocol definition in RFC-3416

Specified by:
snmpReceivedGetBulk in interface SnmpAgentRequestHandler
Overrides:
snmpReceivedGetBulk in class RequestHandlerSupport
Parameters:
pdu - contains the following: a list of OIDs an Integer > 0 indicating the number of non-repeaters (set with PDU.setNonRepeaters()) an Integer >= 0 indicating the number of repetitions (set with PDU.setMaxRepetitions())
Returns:
a PDU filled with the appropriate values, and if values were not found, null for those values. GetBulk will rarely error out completely if non-zero list of VariableBindings is provided in the parameter PDU. It may be filled with no useful data, but will always return a PDU with some content.

snmpReceivedGet

public org.snmp4j.PDU snmpReceivedGet(org.snmp4j.PDU pdu)

This method is defined to handle SNMP GET and GETNEXT requests that are received by the session. The request has already been validated by the system. This routine will build a response and pass it back to the caller. The behaviour is defined in RFC-3416 for v2 protocols.

Specified by:
snmpReceivedGet in interface SnmpAgentRequestHandler
Overrides:
snmpReceivedGet in class RequestHandlerSupport
Parameters:
pdu - The SNMP pdu.
Returns:
a PDU filled in with the proper response, or a PDU filled with appropriate error indications. Both the error type (ErrorStatus) and error index (the binding in the PDU being processed that caused the error are returned.)

snmpReceivedSet

public org.snmp4j.PDU snmpReceivedSet(org.snmp4j.PDU pdu)

This method is defined to handle SNMP Set requests that are received by the session. The request has already been validated by the system. This routine will build a response and pass it back to the caller. Upon any error, this method will rollback all sets that were made before the failure occured. The behaviour is defined in RFC-3416

Specified by:
snmpReceivedSet in interface SnmpAgentRequestHandler
Overrides:
snmpReceivedSet in class RequestHandlerSupport
Parameters:
pdu - The SNMP pdu
Returns:
PDU filled with the new value of the given OID and an error of 0 on success, or a PDU with the same VB list as given and an error status indicating why the operation failed, and which VariableBinding caused the problem. Any changes that have completed before this problem occured will be undone, as per RFC-3416

snmpReceivedPdu

public void snmpReceivedPdu(org.snmp4j.Snmp session,
                            java.net.InetAddress manager,
                            int port,
                            org.snmp4j.smi.OctetString community,
                            org.snmp4j.PDU pdu)

This method is defined to handle SNMP requests that are received by the session. The parameters allow the handler to determine the host, port, and community string of the received PDU

Specified by:
snmpReceivedPdu in interface SnmpAgentRequestHandler
Overrides:
snmpReceivedPdu in class RequestHandlerSupport
Parameters:
session - The SNMP session
manager - The remote sender
port - The remote senders port
community - The community string
pdu - The SNMP pdu

SnmpAgentSessionError

public void SnmpAgentSessionError(org.snmp4j.Snmp session,
                                  int error,
                                  java.lang.Object ref)

This method is invoked if an error occurs in the session. The error code that represents the failure will be passed in the second parameter, 'error'. The error codes can be found in the class SnmpAgentSession class.

If a particular PDU is part of the error condition it will be passed in the third parameter, 'pdu'. The pdu will be of the type SnmpPduRequest or SnmpPduTrap object. The handler should use the "instanceof" operator to determine which type the object is. Also, the object may be null if the error condition is not associated with a particular PDU.

Overrides:
SnmpAgentSessionError in class RequestHandlerSupport
Parameters:
session - The SNMP Session
error - The error condition value.
ref - The PDU reference, or potentially null. It may also be an exception.

addAttributeMappings

public void addAttributeMappings(java.util.List<ManagedBean> mappings)
Specified by:
addAttributeMappings in interface RequestHandler
Parameters:
mappings -

removeAttributeMappings

public void removeAttributeMappings(java.util.List<ManagedBean> mappings)
Specified by:
removeAttributeMappings in interface RequestHandler
Parameters:
mappings -

getValueFor

public org.snmp4j.smi.Variable getValueFor(org.snmp4j.smi.OID oid)
                                    throws NoSuchInstanceException,
                                           VariableTypeException
Return the current value for the given oid

Specified by:
getValueFor in interface RequestHandler
Parameters:
oid - The oid we want a value for
Returns:
Null if no value present
Throws:
NoSuchInstanceException
VariableTypeException

prepForPdu

public static org.snmp4j.smi.Variable prepForPdu(java.lang.Object val,
                                                 org.snmp4j.smi.OID tableIndexOID)
                                          throws VariableTypeException
This method takes an Object that is typically going to be put into a VariableBinding for use in a PDU, and thus must be converted into an SNMP type based on it's type. This Object is usually read from the MBean server.

Parameters:
val - The value needing conversion.
Returns:
the converted value. null on failure.
Throws:
VariableTypeException - if the method was unable to convert val's type into an equivalent SMI type.


Copyright © 2011. All Rights Reserved.