[jboss-cvs] JBossAS SVN: r106424 - in branches/snmp4j-integration-1.11.1/varia/src: main/java/org/jboss/jmx/adaptor/snmp/config/manager and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jul 5 11:01:38 EDT 2010
Author: bshim
Date: 2010-07-05 11:01:37 -0400 (Mon, 05 Jul 2010)
New Revision: 106424
Added:
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java
Modified:
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EventTypes.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/ReadOnlyException.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentService.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpVarBindFactory.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/manager/Manager.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/NotificationProducerService.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/NotificationProducerServiceMBean.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/trapd/TrapdService.java
branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/META-INF/jboss-service.xml
branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/managers.xml
branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/notifications.xml
Log:
migrating snmp work from snmp4j-integration branch
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EventTypes.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EventTypes.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/EventTypes.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -32,4 +32,9 @@
public final String COLDSTART = "jboss.snmp.agent.coldstart";
public final String HEARTBEAT = "jboss.snmp.agent.heartbeat";
+ /** Notification types for testing */
+ public final String V1_TEST_NOTIFICATION = "jboss.snmp.agent.v1test";
+ public final String V2_TEST_NOTIFICATION = "jboss.snmp.agent.v2test";
+ public final String V3_TEST_NOTIFICATION = "jboss.snmp.agent.v3test";
+
}
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/ReadOnlyException.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/ReadOnlyException.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/ReadOnlyException.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -21,7 +21,7 @@
*/
package org.jboss.jmx.adaptor.snmp.agent;
-import org.opennms.protocols.snmp.SnmpObjectId;
+import org.snmp4j.smi.OID;
/**
* This exception is thrown when an entry is read only and
@@ -37,7 +37,7 @@
super("OID " + oid + " is read only");
}
- public ReadOnlyException(SnmpObjectId oid)
+ public ReadOnlyException(OID oid)
{
super("OID " + oid + " is read only");
}
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -24,7 +24,7 @@
import javax.management.MBeanServer;
import org.jboss.logging.Logger;
-import org.opennms.protocols.snmp.SnmpAgentHandler;
+//import org.opennms.protocols.snmp.SnmpAgentHandler;
/**
* Interface that must be implemented by classes
@@ -33,7 +33,7 @@
* @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
* @version $Revision$
*/
-public interface RequestHandler extends SnmpAgentHandler
+public interface RequestHandler extends SnmpAgentRequestHandler
{
/**
* Perform initialization, possibly by parsing
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -29,6 +29,7 @@
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
+import java.util.Vector;
import javax.management.Attribute;
import javax.management.MBeanServer;
@@ -41,7 +42,24 @@
import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
-import org.opennms.protocols.snmp.*;
+//import org.opennms.protocols.snmp.*;
+import org.snmp4j.PDU;
+import org.snmp4j.PDUv1;
+import org.snmp4j.ScopedPDU;
+import org.snmp4j.Snmp;
+import org.snmp4j.event.ResponseEvent;
+import org.snmp4j.mp.SnmpConstants;
+import org.snmp4j.smi.Counter32;
+import org.snmp4j.smi.Counter64;
+import org.snmp4j.smi.Integer32;
+import org.snmp4j.smi.Null;
+import org.snmp4j.smi.OID;
+import org.snmp4j.smi.OctetString;
+import org.snmp4j.smi.TimeTicks;
+import org.snmp4j.smi.Variable;
+import org.snmp4j.smi.VariableBinding;
+import org.snmp4j.util.DefaultPDUFactory;
+import org.snmp4j.util.PDUFactory;
/**
* Implement RequestHandler with mapping of snmp get/set requests
@@ -141,87 +159,136 @@
* @return SnmpPduRequest filled in with the proper response, or null if
* cannot process NOTE: this might be changed to throw an exception.
*/
- public SnmpPduRequest snmpReceivedGet(SnmpPduPacket pdu, boolean getNext)
+ public PDU snmpReceivedGet(PDU pdu, boolean getNext)
{
- try
- {
- SnmpPduRequest response = null;
- int pduLength = pdu.getLength();
- final boolean trace = log.isTraceEnabled();
-
- if (trace)
- log.trace("requestId=" + pdu.getRequestId() + ", pduLength="
- + pduLength + ", getNext=" + getNext);
-
- SnmpVarBind[] vblist = new SnmpVarBind[pduLength];
- int errorStatus = SnmpPduPacket.ErrNoError;
- int errorIndex = 0;
-
- // Process for each varibind in the request
- for (int i = 0; i < pduLength; i++)
- {
- boolean good = true;
- SnmpVarBind vb = pdu.getVarBindAt(i);
- SnmpObjectId oid = vb.getName();
- if (getNext)
- {
- /*
- * We call getNextOid() to find out what is the next valid OID
- * instance in the supported MIB (sub-)tree. Assign that OID to the
- * VB List and then proceed same as that of get request. If the
- * passed oid is already the last, we flag it.
- */
- ComparableSnmpObjectId coid = new ComparableSnmpObjectId(oid);
- oid = getNextOid(coid, true);
- if (oid == null)
- {
- good = false;
- }
- else
- {
- pdu.setVarBindAt(i, new SnmpVarBind(oid));
- }
+ PDU response;
+ //later on should be able to get rid of getNext because pdu.getType() should have it
+ if (pdu instanceof ScopedPDU){
+ response = DefaultPDUFactory.createPDU(SnmpConstants.version3);
+ } else if (pdu instanceof PDUv1){
+ response = DefaultPDUFactory.createPDU(SnmpConstants.version1);
+ } else {
+ response = new PDU();
+ }
+ response.setType(PDU.RESPONSE);
+
+ //Start of MINE
+ //response = (PDU)pdu.clone();
+
+ final boolean trace = log.isTraceEnabled();
+
+ if (trace) {
+ log.trace("requestID=" + pdu.getRequestID() + ", elementCount="
+ + pdu.size() + ", getNext=" + getNext);
+ }
+
+ if (pdu != null){
+
+ if (getNext){
+ //TODO do the GETNEXT case
}
- if (oid!=null)
- vblist[i] = new SnmpVarBind(oid);
- else
- vblist[i] = new SnmpVarBind(vb.getName()); // oid passed in
+ Iterator it = pdu.getVariableBindings().iterator();
+
+ while (it.hasNext()){
+ VariableBinding vb = (VariableBinding)it.next();
+ OID oid = vb.getOid();
+ //setup the new variable binding to put into the response pdu
+ VariableBinding newVB = new VariableBinding(oid);
+
+ //some errorchecking ....
+ //else is good and do:
+ Variable var = getValueFor(oid);
+ newVB.setVariable(var);
+ response.add(newVB);
+ }
+ }
+ //END IF MINE
- if (trace)
- log.trace("oid=" + oid);
-
- SnmpSyntax result = null;
- if (good && bindings != null)
- result = getValueFor(oid);
-
- if (trace)
- log.trace("got result of " + result);
-
- if (result == null || !good)
- {
- errorStatus = SnmpPduPacket.ErrNoSuchName;
- errorIndex = i + 1;
- log.debug("Error Occured " + vb.getName().toString());
- }
- else
- {
- vblist[i].setValue(result);
- log.debug("Varbind[" + i + "] := "
- + vblist[i].getName().toString());
- log.debug(" --> " + vblist[i].getValue().toString());
- }
- } // for ...
- response = new SnmpPduRequest(SnmpPduPacket.RESPONSE, vblist);
- response.setErrorStatus(errorStatus);
- response.setErrorIndex(errorIndex);
- return response;
- } catch (Exception e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
+ return response;
+
+
+// try
+// {
+// SnmpPduRequest response = null;
+// int pduLength = pdu.getLength();
+// final boolean trace = log.isTraceEnabled();
+//
+// if (trace)
+// log.trace("requestId=" + pdu.getRequestId() + ", pduLength="
+// + pduLength + ", getNext=" + getNext);
+//
+// SnmpVarBind[] vblist = new SnmpVarBind[pduLength];
+// int errorStatus = SnmpPduPacket.ErrNoError;
+// int errorIndex = 0;
+//
+// // Process for each varibind in the request
+// for (int i = 0; i < pduLength; i++)
+// {
+// boolean good = true;
+// SnmpVarBind vb = pdu.getVarBindAt(i);
+// SnmpObjectId oid = vb.getName();
+ //START OF GETNEXT
+// if (getNext) //i don't care about GETNEXT, doing GET first
+// {
+// /*
+// * We call getNextOid() to find out what is the next valid OID
+// * instance in the supported MIB (sub-)tree. Assign that OID to the
+// * VB List and then proceed same as that of get request. If the
+// * passed oid is already the last, we flag it.
+// */
+// ComparableSnmpObjectId coid = new ComparableSnmpObjectId(oid);
+// oid = getNextOid(coid, true);
+// if (oid == null)
+// {
+// good = false;
+// }
+// else
+// {
+// pdu.setVarBindAt(i, new SnmpVarBind(oid));
+// }
+// }
+ //End of GETNEXT
+// if (oid!=null)
+// vblist[i] = new SnmpVarBind(oid);
+// else
+// vblist[i] = new SnmpVarBind(vb.getName()); // oid passed in
+//
+//
+// if (trace)
+// log.trace("oid=" + oid);
+//
+// SnmpSyntax result = null;
+// if (good && bindings != null)
+// result = getValueFor(oid);
+//
+// if (trace)
+// log.trace("got result of " + result);
+//
+// if (result == null || !good)
+// {
+// errorStatus = SnmpPduPacket.ErrNoSuchName;
+// errorIndex = i + 1;
+// log.debug("Error Occured " + vb.getName().toString());
+// }
+// else
+// {
+// vblist[i].setValue(result);
+// log.debug("Varbind[" + i + "] := "
+// + vblist[i].getName().toString());
+// log.debug(" --> " + vblist[i].getValue().toString());
+// }
+// } // for ...
+// response = new SnmpPduRequest(SnmpPduPacket.RESPONSE, vblist);
+// response.setErrorStatus(errorStatus);
+// response.setErrorIndex(errorIndex);
+// return response;
+// } catch (Exception e)
+// {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// return null;
+// }
}
/**
@@ -237,52 +304,52 @@
* @return SnmpPduRequest filled in with the proper response, or null if
* cannot process NOTE: this might be changed to throw an exception.
*/
- public SnmpPduRequest snmpReceivedSet(SnmpPduPacket pdu)
- {
- final boolean trace = log.isTraceEnabled();
- SnmpPduRequest response = null;
- int errorStatus = SnmpPduPacket.ErrNoError;
- int errorIndex = 0;
- int k = pdu.getLength();
- SnmpVarBind[] vblist = new SnmpVarBind[k];
-
- for (int i = 0; i < k; i++)
- {
- SnmpVarBind vb = pdu.getVarBindAt(i);
- vblist[i] = new SnmpVarBind(vb);
- SnmpObjectId oid = vb.getName();
- SnmpSyntax newVal = vb.getValue();
- if (trace)
- log.trace("set: received oid " + oid.toString() + " with value " + newVal.toString());
- SnmpSyntax result = null;
- try
- {
- result = setValueFor(oid,newVal);
- }
- catch (ReadOnlyException e)
- {
- errorStatus = SnmpPduPacket.ErrReadOnly;
- errorIndex = i + 1;
- }
-
- if (result != null)
- {
- errorStatus = SnmpPduPacket.ErrReadOnly;
- errorIndex = i + 1;
- log.debug("Error occured " + vb.getName().toString());
- }
-
- if (trace)
- {
- log.trace("Varbind[" + i + "] := " + vb.getName().toString());
- log.trace(" --> " + vb.getValue().toString());
- }
- }
- response = new SnmpPduRequest(SnmpPduPacket.RESPONSE, vblist);
- response.setErrorStatus(errorStatus);
- response.setErrorIndex(errorIndex);
-
- return response;
+ public PDU snmpReceivedSet(PDU pdu)
+ {return null;
+// final boolean trace = log.isTraceEnabled();
+// SnmpPduRequest response = null;
+// int errorStatus = SnmpPduPacket.ErrNoError;
+// int errorIndex = 0;
+// int k = pdu.getLength();
+// SnmpVarBind[] vblist = new SnmpVarBind[k];
+//
+// for (int i = 0; i < k; i++)
+// {
+// SnmpVarBind vb = pdu.getVarBindAt(i);
+// vblist[i] = new SnmpVarBind(vb);
+// SnmpObjectId oid = vb.getName();
+// SnmpSyntax newVal = vb.getValue();
+// if (trace)
+// log.trace("set: received oid " + oid.toString() + " with value " + newVal.toString());
+// SnmpSyntax result = null;
+// try
+// {
+// result = setValueFor(oid,newVal);
+// }
+// catch (ReadOnlyException e)
+// {
+// errorStatus = SnmpPduPacket.ErrReadOnly;
+// errorIndex = i + 1;
+// }
+//
+// if (result != null)
+// {
+// errorStatus = SnmpPduPacket.ErrReadOnly;
+// errorIndex = i + 1;
+// log.debug("Error occured " + vb.getName().toString());
+// }
+//
+// if (trace)
+// {
+// log.trace("Varbind[" + i + "] := " + vb.getName().toString());
+// log.trace(" --> " + vb.getValue().toString());
+// }
+// }
+// response = new SnmpPduRequest(SnmpPduPacket.RESPONSE, vblist);
+// response.setErrorStatus(errorStatus);
+// response.setErrorIndex(errorIndex);
+//
+// return response;
}
/**
@@ -304,12 +371,12 @@
* The SNMP pdu
*
*/
- public void snmpReceivedPdu(SnmpAgentSession session, InetAddress manager,
- int port, SnmpOctetString community, SnmpPduPacket pdu)
+ public void snmpReceivedPdu(Snmp session, InetAddress manager,
+ int port, OctetString community, PDU pdu)
{
- log.error("Message from manager " + manager.toString() + " on port " + port);
- int cmd = pdu.getCommand();
- log.error("Unsupported PDU command......... " + cmd);
+// log.error("Message from manager " + manager.toString() + " on port " + port);
+// int cmd = pdu.getCommand();
+// log.error("Unsupported PDU command......... " + cmd);
}
/**
@@ -336,22 +403,22 @@
* The PDU reference, or potentially null. It may also be an
* exception.
*/
- public void SnmpAgentSessionError(SnmpAgentSession session, int error, Object ref)
+ public void SnmpAgentSessionError(Snmp session, int error, Object ref)
{
- log.error("An error occured in the trap session");
- log.error("Session error code = " + error);
- if (ref != null)
- {
- log.error("Session error reference: " + ref.toString());
- }
-
- if (error == SnmpAgentSession.ERROR_EXCEPTION)
- {
- synchronized (session)
- {
- session.notify(); // close the session
- }
- }
+// log.error("An error occured in the trap session");
+// log.error("Session error code = " + error);
+// if (ref != null)
+// {
+// log.error("Session error reference: " + ref.toString());
+// }
+//
+// if (error == SnmpAgentSession.ERROR_EXCEPTION)
+// {
+// synchronized (session)
+// {
+// session.notify(); // close the session
+// }
+// }
}
// Private -------------------------------------------------------
@@ -419,8 +486,8 @@
BindEntry be = new BindEntry(oid, mmb.getName(), ma.getName());
be.isReadWrite = ma.isReadWrite();
- ComparableSnmpObjectId coid = new ComparableSnmpObjectId(oid);
-
+ //ComparableSnmpObjectId coid = new ComparableSnmpObjectId(oid);
+ OID coid = new OID(oid);
if (log.isTraceEnabled())
log.trace("New bind entry " + be);
if (bindings.containsKey(coid)) {
@@ -443,7 +510,7 @@
}
}
}
-
+
/**
* Return the current value for the given oid
*
@@ -451,132 +518,196 @@
* The oid we want a value for
* @return SnmpNull if no value present
*/
- private SnmpSyntax getValueFor(final SnmpObjectId oid) {
+ private Variable getValueFor(final OID oid) {
BindEntry be = findBindEntryForOid(oid);
- SnmpSyntax ssy = null;
+ Variable ssy = null;
if (be != null)
- {
+ {
if (log.isTraceEnabled())
log.trace("Found entry " + be.toString() + " for oid " + oid);
-
+
try
- {
+ {
Object val = server.getAttribute(be.mbean, be.attr.getName());
if (val instanceof Long)
- {
+ {
Long uin = (Long) val;
- ssy = new SnmpUInt32(uin);
+
+ //consider Counter64 if there's problems
+ ssy = new Counter32(uin);
}
- else if (val instanceof String)
- {
+ else if (val instanceof String)
+ {
String in = (String) val;
- ssy = new SnmpOctetString(in.getBytes());
+ ssy = new OctetString(in.getBytes());
}
- else if (val instanceof Integer)
- {
+ else if (val instanceof Integer)
+ {
Integer in = (Integer) val;
- ssy = new SnmpInt32(in);
+ ssy = new Integer32(in);
}
- else if (val instanceof SnmpObjectId)
- {
- ssy = (SnmpObjectId)val;
- }
- else if (val instanceof SnmpTimeTicks)
- {
- ssy = (SnmpTimeTicks)val;
- }
- else
+
+ //not sure about how to handle this case yet
+// else if (val instanceof SnmpObjectId)
+// {
+// ssy = (SnmpObjectId)val;
+// }
+ else if (val instanceof TimeTicks)
+ {
+ ssy = (TimeTicks)val;
+ }
+ else
log.info("Unknown type for " + be);
}
- catch (Exception e)
- {
+ catch (Exception e)
+ {
log.warn("getValueFor (" + be.mbean.toString() + ", "
+ be.attr.getName() + ": " + e.toString());
- }
- }
- else
- {
- ssy = new SnmpNull();
+ }
+ }
+ else
+ {
+ ssy = new Null();
log.info(NO_ENTRY_FOUND_FOR_OID + oid);
}
return ssy;
}
+
+// /**
+// * Return the current value for the given oid
+// *
+// * @param oid
+// * The oid we want a value for
+// * @return SnmpNull if no value present
+// */
+// private SnmpSyntax getValueFor(final SnmpObjectId oid) {
+//
+// BindEntry be = findBindEntryForOid(oid);
+// SnmpSyntax ssy = null;
+// if (be != null)
+// {
+// if (log.isTraceEnabled())
+// log.trace("Found entry " + be.toString() + " for oid " + oid);
+//
+// try
+// {
+// Object val = server.getAttribute(be.mbean, be.attr.getName());
+//
+// if (val instanceof Long)
+// {
+// Long uin = (Long) val;
+// ssy = new SnmpUInt32(uin);
+// }
+// else if (val instanceof String)
+// {
+// String in = (String) val;
+// ssy = new SnmpOctetString(in.getBytes());
+// }
+// else if (val instanceof Integer)
+// {
+// Integer in = (Integer) val;
+// ssy = new SnmpInt32(in);
+// }
+// else if (val instanceof SnmpObjectId)
+// {
+// ssy = (SnmpObjectId)val;
+// }
+// else if (val instanceof SnmpTimeTicks)
+// {
+// ssy = (SnmpTimeTicks)val;
+// }
+// else
+// log.info("Unknown type for " + be);
+// }
+// catch (Exception e)
+// {
+// log.warn("getValueFor (" + be.mbean.toString() + ", "
+// + be.attr.getName() + ": " + e.toString());
+// }
+// }
+// else
+// {
+// ssy = new SnmpNull();
+// log.info(NO_ENTRY_FOUND_FOR_OID + oid);
+// }
+// return ssy;
+// }
- /**
- * Set a jmx attribute
- * @param oid The oid to set. This is translated into a mbean / attribute pair
- * @param newVal The new value to set
- * @return null on success, non-null on failure
- * @throws ReadOnlyException If the referred entry is read only.
- */
- private SnmpSyntax setValueFor(final SnmpObjectId oid, final SnmpSyntax newVal) throws ReadOnlyException
- {
- final boolean trace = log.isTraceEnabled();
-
- BindEntry be = findBindEntryForOid(oid);
-
- if (trace)
- log.trace("setValueFor: found bind entry for " + oid);
-
- SnmpSyntax ssy = null;
- if (be != null)
- {
- if (trace)
- log.trace("setValueFor: " + be.toString());
-
- if (be.isReadWrite == false)
- {
- if (trace)
- log.trace("setValueFor: this is marked read only");
-
- throw new ReadOnlyException(oid);
- }
- try
- {
- Object val = null;
- if (newVal instanceof SnmpOctetString)
- {
- val = newVal.toString();
- }
- else if (newVal instanceof SnmpInt32)
- {
- val = new Integer(((SnmpInt32)newVal).getValue());
- }
- else if (newVal instanceof SnmpUInt32)
- {
- val = new Long(((SnmpUInt32)newVal).getValue());
- }
- // TODO do more mumbo jumbo for type casting / changing
-
- if (val != null)
- {
- Attribute at = new Attribute(be.attr.getName(), val);
- server.setAttribute(be.mbean, at);
- if (trace)
- log.trace("setValueFor: set attribute in mbean-Server");
- }
- else
- {
- log.debug("Did not find a suitable data type for newVal " + newVal);
- ssy = new SnmpNull();
- }
- // TODO
- }
- catch (Exception e )
- {
- log.debug("setValueFor: exception " + e.getMessage());
- ssy = new SnmpNull();
- }
- }
- else
- {
- ssy = new SnmpNull();
- log.info(NO_ENTRY_FOUND_FOR_OID + oid);
- }
- return ssy;
- }
+// /**
+// * Set a jmx attribute
+// * @param oid The oid to set. This is translated into a mbean / attribute pair
+// * @param newVal The new value to set
+// * @return null on success, non-null on failure
+// * @throws ReadOnlyException If the referred entry is read only.
+// */
+// private SnmpSyntax setValueFor(final OID oid, final SnmpSyntax newVal) throws ReadOnlyException
+// {
+// final boolean trace = log.isTraceEnabled();
+//
+// BindEntry be = findBindEntryForOid(oid);
+//
+// if (trace)
+// log.trace("setValueFor: found bind entry for " + oid);
+//
+// if (be != null)
+// {
+// if (trace)
+// log.trace("setValueFor: " + be.toString());
+//
+// if (be.isReadWrite == false)
+// {
+// if (trace)
+// log.trace("setValueFor: this is marked read only");
+//
+// throw new ReadOnlyException(oid);
+// }
+// try
+// {
+//
+// Object val = null;
+// if (newVal instanceof OctetString)
+// {
+// val = newVal.toString();
+// }
+// else if (newVal instanceof Integer32)
+// {
+// val = new Integer(((Integer32)newVal).getValue());
+// }
+// else if (newVal instanceof Counter32)
+// {
+// val = new Long(((Counter32)newVal).getValue());
+// }
+// // TODO do more mumbo jumbo for type casting / changing
+//
+// if (val != null)
+// {
+// Attribute at = new Attribute(be.attr.getName(), val);
+// server.setAttribute(be.mbean, at);
+// if (trace)
+// log.trace("setValueFor: set attribute in mbean-Server");
+// }
+// else
+// {
+// log.debug("Did not find a suitable data type for newVal " + newVal);
+// ssy = new SnmpNull();
+// }
+// // TODO
+// }
+// catch (Exception e )
+// {
+// log.debug("setValueFor: exception " + e.getMessage());
+// ssy = new SnmpNull();
+// }
+// }
+// else
+// {
+// ssy = new SnmpNull();
+// log.info(NO_ENTRY_FOUND_FOR_OID + oid);
+// }
+// return ssy;
+// }
/**
@@ -585,81 +716,102 @@
* @param oid The oid look up.
* @return a bind entry or null.
*/
- private BindEntry findBindEntryForOid(final SnmpObjectId oid) {
+ private BindEntry findBindEntryForOid(final OID oid) {
- ComparableSnmpObjectId coid= new ComparableSnmpObjectId(oid);
+ //param probably not supposed to be OID type
+// ComparableSnmpObjectId coid= new ComparableSnmpObjectId(oid.toString());
- if (coid.isLeaf())
- {
- coid = coid.removeLastPart();
- }
- BindEntry be = (BindEntry)bindings.get(coid);
+ //add possible oid format checking
+// if (coid.isLeaf())
+// {
+// coid = coid.removeLastPart();
+// }
+ BindEntry be = (BindEntry)bindings.get(oid);
return be;
}
+
+// /**
+// * Lookup a BinEntry on the given oid. If the oid ends in .0,
+// * then the .0 will be stripped of before the search.
+// * @param oid The oid look up.
+// * @return a bind entry or null.
+// */
+// private BindEntry findBindEntryForOid(final SnmpObjectId oid) {
+//
+// ComparableSnmpObjectId coid= new ComparableSnmpObjectId(oid);
+//
+// if (coid.isLeaf())
+// {
+// coid = coid.removeLastPart();
+// }
+// BindEntry be = (BindEntry)bindings.get(coid);
+//
+// return be;
+// }
- /**
- * Return the next oid that is larger than ours.
- * @param oid the starting oid
- * @param stayInSubtree if true, the next oid will not have a different prefix than the one of oid.
- * @return the next oid or null if none found.
- */
- private ComparableSnmpObjectId getNextOid(final ComparableSnmpObjectId oid, boolean stayInSubtree) {
- ComparableSnmpObjectId coid = new ComparableSnmpObjectId(oid);
+// /**
+// * Return the next oid that is larger than ours.
+// * @param oid the starting oid
+// * @param stayInSubtree if true, the next oid will not have a different prefix than the one of oid.
+// * @return the next oid or null if none found.
+// */
+// private ComparableSnmpObjectId getNextOid(final ComparableSnmpObjectId oid, boolean stayInSubtree) {
+// ComparableSnmpObjectId coid = new ComparableSnmpObjectId(oid);
+//
+//
+// if (coid.isLeaf())
+// coid = coid.removeLastPart();
+//
+// SortedSet ret;
+// ret= oidKeys.tailSet(oid); // get oids >= oid
+// Iterator it = ret.iterator();
+// ComparableSnmpObjectId roid=null;
+//
+// /*
+// * If there are elements in the tail set, then
+// * - get first one.
+// * - if first is input (which it is supposed to be according to the contract of
+// * SortedSet.tailSet() , then get next, which is the
+// * one we look for.
+// */
+// if (it.hasNext())
+// {
+// roid = (ComparableSnmpObjectId)it.next(); // oid
+// }
+//
+// if (roid == null)
+// {
+// return null; // roid is null,
+// }
+//
+// if (roid.compareTo(coid)==0) // input elment
+// {
+// // if there is a next element, then it is ours.
+// if (it.hasNext())
+// {
+// roid = (ComparableSnmpObjectId)it.next();
+// }
+// else
+// {
+// roid = null; // end of list
+// }
+// }
+//
+// /*
+// * Check if still in subtree if requested to stay within
+// */
+// if (stayInSubtree && roid != null)
+// {
+// ComparableSnmpObjectId parent = coid.removeLastPart();
+// if (!parent.isRootOf(roid))
+// roid = null;
+// }
+//
+// return roid;
+// }
- if (coid.isLeaf())
- coid = coid.removeLastPart();
-
- SortedSet ret;
- ret= oidKeys.tailSet(oid); // get oids >= oid
- Iterator it = ret.iterator();
- ComparableSnmpObjectId roid=null;
-
- /*
- * If there are elements in the tail set, then
- * - get first one.
- * - if first is input (which it is supposed to be according to the contract of
- * SortedSet.tailSet() , then get next, which is the
- * one we look for.
- */
- if (it.hasNext())
- {
- roid = (ComparableSnmpObjectId)it.next(); // oid
- }
-
- if (roid == null)
- {
- return null; // roid is null,
- }
-
- if (roid.compareTo(coid)==0) // input elment
- {
- // if there is a next element, then it is ours.
- if (it.hasNext())
- {
- roid = (ComparableSnmpObjectId)it.next();
- }
- else
- {
- roid = null; // end of list
- }
- }
-
- /*
- * Check if still in subtree if requested to stay within
- */
- if (stayInSubtree && roid != null)
- {
- ComparableSnmpObjectId parent = coid.removeLastPart();
- if (!parent.isRootOf(roid))
- roid = null;
- }
-
- return roid;
- }
-
-
// Inner Class ---------------------------------------------------
/**
@@ -668,7 +820,7 @@
* @author <a href="mailto:pilhuhn at user.sf.net>">Heiko W. Rupp</a>
*/
private class BindEntry implements Comparable {
- private final ComparableSnmpObjectId oid;
+ private final OID oid;
private ObjectName mbean;
private Attribute attr;
@@ -687,7 +839,7 @@
* The name of the attribute to query
*/
BindEntry(final String oidString, final String mbName, final String attrName) {
- this(new ComparableSnmpObjectId(oidString),
+ this(new OID(oidString),
mbName,
attrName);
}
@@ -698,7 +850,7 @@
* @param mbName The name of an MBean with attribute to query
* @param attrName The name of the attribute to query
*/
- BindEntry(final ComparableSnmpObjectId coid, final String mbName, final String attrName) {
+ BindEntry(final OID coid, final String mbName, final String attrName) {
oid = coid;
this.mName = mbName;
this.aName = attrName;
@@ -739,7 +891,7 @@
return mbean;
}
- public ComparableSnmpObjectId getOid()
+ public OID getOid()
{
return oid;
}
@@ -765,10 +917,10 @@
return 0;
BindEntry obe = (BindEntry) other;
- if (getOid().equals(obe.getOid()))
- return 0;
+// if (getOid().equals(obe.getOid()))
+// return 0;
- int res =oid.compare(obe.getOid());
+ int res =oid.compareTo(obe.getOid());
return res;
}
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -26,13 +26,14 @@
import javax.management.MBeanServer;
import org.jboss.logging.Logger;
-import org.opennms.protocols.snmp.SnmpAgentSession;
-import org.opennms.protocols.snmp.SnmpObjectId;
-import org.opennms.protocols.snmp.SnmpOctetString;
-import org.opennms.protocols.snmp.SnmpPduPacket;
-import org.opennms.protocols.snmp.SnmpPduRequest;
-import org.opennms.protocols.snmp.SnmpSyntax;
-import org.opennms.protocols.snmp.SnmpVarBind;
+//import org.opennms.protocols.snmp.SnmpAgentSession;
+//import org.opennms.protocols.snmp.SnmpObjectId;
+//import org.opennms.protocols.snmp.SnmpPduRequest;
+//import org.opennms.protocols.snmp.SnmpSyntax;
+//import org.opennms.protocols.snmp.SnmpVarBind;
+import org.snmp4j.PDU;
+import org.snmp4j.Snmp;
+import org.snmp4j.smi.OctetString;
/**
* Implement RequestHandler with simple tracing of incoming requests.
@@ -98,54 +99,54 @@
* @return SnmpPduRequest filled in with the proper response, or null if cannot process
* NOTE: this might be changed to throw an exception.
*/
- public SnmpPduRequest snmpReceivedGet(SnmpPduPacket pdu, boolean getNext)
- {
- SnmpPduRequest response = null;
- int pduLength = pdu.getLength();
-
- log.debug("requestId=" + pdu.getRequestId() + ", pduLength=" + pduLength);
-
- SnmpVarBind[] vblist = new SnmpVarBind[pduLength];
- int errorStatus = SnmpPduPacket.ErrNoError;
- int errorIndex = 0;
-
- //Process for each varibind in the request
- for (int i = 0; i < pduLength ; i++ )
- {
- SnmpVarBind vb = pdu.getVarBindAt(i);
- SnmpObjectId oid = vb.getName();
- if (getNext)
- {
- log.debug(
- "Should call getNextOid() to find out what is the next valid OID " +
- "instance in the supported MIB tree. Assign that OID to the VB List " +
- "and then proceed same as that of get request" );
- }
- vblist[i] = new SnmpVarBind(oid);
-
- log.debug("oid=" + oid.toString());
-
- log.debug("Should call the respective interface to retrieve current value for this OID" );
-
- SnmpSyntax result = null;
-
- if (result == null)
- {
- errorStatus = SnmpPduPacket.ErrNoSuchName;
- errorIndex = i + 1;
- //log.debug("Error Occured " + vb.getName().toString());
- }
- else
- {
- vblist[i].setValue(result);
- log.debug("Varbind[" + i + "] := " + vblist[i].getName().toString());
- log.debug(" --> " + vblist[i].getValue().toString());
- }
- }
- response = new SnmpPduRequest(SnmpPduPacket.RESPONSE, vblist);
- response.setErrorStatus(errorStatus);
- response.setErrorIndex(errorIndex);
- return response;
+ public PDU snmpReceivedGet(PDU pdu, boolean getNext)
+ {return null;
+// SnmpPduRequest response = null;
+// int pduLength = pdu.getLength();
+//
+// log.debug("requestId=" + pdu.getRequestId() + ", pduLength=" + pduLength);
+//
+// SnmpVarBind[] vblist = new SnmpVarBind[pduLength];
+// int errorStatus = SnmpPduPacket.ErrNoError;
+// int errorIndex = 0;
+//
+// //Process for each varibind in the request
+// for (int i = 0; i < pduLength ; i++ )
+// {
+// SnmpVarBind vb = pdu.getVarBindAt(i);
+// SnmpObjectId oid = vb.getName();
+// if (getNext)
+// {
+// log.debug(
+// "Should call getNextOid() to find out what is the next valid OID " +
+// "instance in the supported MIB tree. Assign that OID to the VB List " +
+// "and then proceed same as that of get request" );
+// }
+// vblist[i] = new SnmpVarBind(oid);
+//
+// log.debug("oid=" + oid.toString());
+//
+// log.debug("Should call the respective interface to retrieve current value for this OID" );
+//
+// SnmpSyntax result = null;
+//
+// if (result == null)
+// {
+// errorStatus = SnmpPduPacket.ErrNoSuchName;
+// errorIndex = i + 1;
+// //log.debug("Error Occured " + vb.getName().toString());
+// }
+// else
+// {
+// vblist[i].setValue(result);
+// log.debug("Varbind[" + i + "] := " + vblist[i].getName().toString());
+// log.debug(" --> " + vblist[i].getValue().toString());
+// }
+// }
+// response = new SnmpPduRequest(SnmpPduPacket.RESPONSE, vblist);
+// response.setErrorStatus(errorStatus);
+// response.setErrorIndex(errorIndex);
+// return response;
}
/**
@@ -159,39 +160,41 @@
* @return SnmpPduRequest filled in with the proper response, or null if cannot process
* NOTE: this might be changed to throw an exception.
*/
- public SnmpPduRequest snmpReceivedSet(SnmpPduPacket pdu)
- {
- SnmpPduRequest response = null;
- int errorStatus = SnmpPduPacket.ErrNoError;
- int errorIndex = 0;
- int k = pdu.getLength();
- SnmpVarBind[] vblist = new SnmpVarBind[k];
-
- for (int i = 0; i < k ; i++ )
- {
- SnmpVarBind vb = pdu.getVarBindAt(i);
- vblist[i] = new SnmpVarBind(vb);
- SnmpObjectId oid = vb.getName();
-
- SnmpSyntax result = null;
- log.debug("Should call the respective interface to assign a value for this OID" );
-
- if (result != null)
- {
- errorStatus = SnmpPduPacket.ErrReadOnly;
- errorIndex = i + 1;
- log.debug("Error occured " + vb.getName().toString());
- }
-
- log.debug("Varbind[" + i + "] := " + vb.getName().toString());
- log.debug(" --> " + vb.getValue().toString());
- }
-
- response = new SnmpPduRequest(SnmpPduPacket.RESPONSE, vblist);
- response.setErrorStatus(errorStatus);
- response.setErrorIndex(errorIndex);
-
- return response;
+ public PDU snmpReceivedSet(PDU pdu)
+ {
+
+ return null;
+// SnmpPduRequest response = null;
+// int errorStatus = SnmpPduPacket.ErrNoError;
+// int errorIndex = 0;
+// int k = pdu.getLength();
+// SnmpVarBind[] vblist = new SnmpVarBind[k];
+//
+// for (int i = 0; i < k ; i++ )
+// {
+// SnmpVarBind vb = pdu.getVarBindAt(i);
+// vblist[i] = new SnmpVarBind(vb);
+// SnmpObjectId oid = vb.getName();
+//
+// SnmpSyntax result = null;
+// log.debug("Should call the respective interface to assign a value for this OID" );
+//
+// if (result != null)
+// {
+// errorStatus = SnmpPduPacket.ErrReadOnly;
+// errorIndex = i + 1;
+// log.debug("Error occured " + vb.getName().toString());
+// }
+//
+// log.debug("Varbind[" + i + "] := " + vb.getName().toString());
+// log.debug(" --> " + vb.getValue().toString());
+// }
+//
+// response = new SnmpPduRequest(SnmpPduPacket.RESPONSE, vblist);
+// response.setErrorStatus(errorStatus);
+// response.setErrorIndex(errorIndex);
+//
+// return response;
}
/**
@@ -207,12 +210,12 @@
* @param pdu The SNMP pdu
*
*/
- public void snmpReceivedPdu(SnmpAgentSession session, InetAddress manager, int port,
- SnmpOctetString community, SnmpPduPacket pdu)
+ public void snmpReceivedPdu(Snmp session, InetAddress manager, int port,
+ OctetString community, PDU pdu)
{
- log.error("Message from manager " + manager.toString() + " on port " + port);
- int cmd = pdu.getCommand();
- log.error("Unsupported PDU command......... " + cmd);
+// log.error("Message from manager " + manager.toString() + " on port " + port);
+// int cmd = pdu.getCommand();
+// log.error("Unsupported PDU command......... " + cmd);
}
/**
@@ -235,21 +238,21 @@
* @param ref The PDU reference, or potentially null.
* It may also be an exception.
*/
- public void SnmpAgentSessionError(SnmpAgentSession session, int error, Object ref)
+ public void SnmpAgentSessionError(Snmp session, int error, Object ref)
{
- log.error("An error occured in the trap session");
- log.error("Session error code = " + error);
- if(ref != null)
- {
- log.error("Session error reference: " + ref.toString());
- }
-
- if(error == SnmpAgentSession.ERROR_EXCEPTION)
- {
- synchronized(session)
- {
- session.notify(); // close the session
- }
- }
+// log.error("An error occured in the trap session");
+// log.error("Session error code = " + error);
+// if(ref != null)
+// {
+// log.error("Session error reference: " + ref.toString());
+// }
+//
+// if(error == SnmpAgentSession.ERROR_EXCEPTION)
+// {
+// synchronized(session)
+// {
+// session.notify(); // close the session
+// }
+// }
}
}
Added: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java (rev 0)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -0,0 +1,88 @@
+package org.jboss.jmx.adaptor.snmp.agent;
+
+import java.net.InetAddress;
+
+import org.snmp4j.PDU;
+import org.snmp4j.Snmp;
+import org.snmp4j.smi.OctetString;
+
+/**
+* <P>The SnmpAgentRequestHandler interface is implemented by an object that
+* wishs to receive callbacks when an SNMP protocol data unit
+* is received from a manager.</P>
+*
+*/
+public interface SnmpAgentRequestHandler
+{
+/**
+* <P>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</P>
+*
+* @param session The SNMP session
+* @param manager The remote sender
+* @param port The remote senders port
+* @param community The community string
+* @param pdu The SNMP pdu
+*
+*/
+void snmpReceivedPdu(Snmp session,
+ InetAddress manager,
+ int port,
+ OctetString community,
+ PDU pdu);
+
+/**
+* <P>This method is defined to handle SNMP Get 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.</P>
+*
+* @param pdu The SNMP pdu
+* @param getNext The agent is requesting the lexically NEXT item after each
+* item in the pdu.
+*
+* @return PDU filled in with the proper response, or null if cannot process
+* NOTE: this might be changed to throw an exception.
+*/
+PDU snmpReceivedGet(PDU pdu, boolean getNext);
+
+/**
+* <P>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.</P>
+*
+* @param pdu The SNMP pdu
+*
+* @return PDU filled in with the proper response, or null if cannot process
+* NOTE: this might be changed to throw an exception.
+*/
+PDU snmpReceivedSet(PDU pdu);
+//ResponseEvent maybe
+
+///**
+//* <P>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.</P>
+//*
+//* <P>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.</P>
+//*
+//* @param session The SNMP Session
+//* @param error The error condition value.
+//* @param ref The PDU reference, or potentially null.
+//* It may also be an exception.
+//*/
+//void SnmpAgentSessionError(Snmp session,
+// int error,
+// Object ref);
+}
\ No newline at end of file
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentService.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentService.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentService.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -20,6 +20,7 @@
package org.jboss.jmx.adaptor.snmp.agent;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import javax.management.Notification;
@@ -27,10 +28,27 @@
import org.jboss.bootstrap.api.as.config.JBossASServerConfig;
import org.jboss.system.ListenerServiceMBeanSupport;
-import org.opennms.protocols.snmp.SnmpAgentSession;
-import org.opennms.protocols.snmp.SnmpPeer;
-import org.opennms.protocols.snmp.SnmpSMI;
+//import org.opennms.protocols.snmp.SnmpAgentSession;
+//import org.opennms.protocols.snmp.SnmpPeer;
+//import org.opennms.protocols.snmp.SnmpSMI;
+//SNMP4J IMPORTS
+import org.snmp4j.AbstractTarget;
+import org.snmp4j.CommandResponder;
+import org.snmp4j.CommandResponderEvent;
+import org.snmp4j.MessageDispatcher;
+import org.snmp4j.MessageException;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.event.CounterEvent;
+import org.snmp4j.mp.SnmpConstants;
+import org.snmp4j.mp.StateReference;
+import org.snmp4j.mp.StatusInformation;
+import org.snmp4j.smi.*;
+import org.snmp4j.transport.DefaultTcpTransportMapping;
+import org.snmp4j.transport.DefaultUdpTransportMapping;
+import org.snmp4j.PDU;
+
/**
* <tt>SnmpAgentService</tt> is an MBean class implementing an SNMP agent.
*
@@ -52,7 +70,8 @@
{
/** Supported versions */
public static final int SNMPV1 = 1;
- public static final int SNMPV2 = 2;
+ public static final int SNMPV2 = 2;
+ public static final int SNMPV3 = 3;
/** Default communities */
public static final String DEFAULT_READ_COMMUNITY = "public";
@@ -115,7 +134,7 @@
private TrapEmitter trapEmitter = null;
/** the snmp agent session for handling get/set requests */
- private SnmpAgentSession agentSession = null;
+// private SnmpAgentSession agentSession = null;
/** the request handler instance handling get/set requests */
private RequestHandler requestHandler;
@@ -503,6 +522,8 @@
// initialise the snmp agent
log.debug("Starting snmp agent ...");
+
+ //At the moment does nothing
startAgent();
log.info("SNMP agent going active");
@@ -530,8 +551,8 @@
this.trapEmitter = null;
log.debug("Stopping snmp agent ...");
- this.agentSession.close();
- this.agentSession = null;
+// this.agentSession.close();
+// this.agentSession = null;
log.info("SNMP agent stopped");
}
@@ -566,27 +587,65 @@
private void startAgent()
throws Exception
{
+
+ // Instantiate and initialize the RequestHandler implementation
+ requestHandler = (RequestHandler)Class.forName(
+ this.requestHandlerClassName, true, this.getClass().getClassLoader()).newInstance();
+ requestHandler.initialize(this.requestHandlerResName, this.getServer(), this.log, this.clock);
+
+ //Snmp snmp = new Snmp(new DefaultTcpTransportMapping(new TcpAddress(this.bindAddress, this.port)));
+ Snmp snmp = new Snmp(new DefaultUdpTransportMapping(new UdpAddress(this.bindAddress, this.port)));
+ SnmpRequest request = new SnmpRequest(requestHandler, log);
+ snmp.addCommandResponder(request);
+ snmp.listen();
+ /********************************************************************
+ *
+ * ORIG!!!!
+ *
+ ********************************************************************/
+
// cater for possible global -b option, if no override has been specified
- InetAddress address = this.bindAddress != null ? this.bindAddress :
- toInetAddress(System.getProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_BIND_ADDRESS));
+// InetAddress address = this.bindAddress != null ? this.bindAddress :
+// toInetAddress(System.getProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_BIND_ADDRESS));
// the listening address
- SnmpPeer peer = new SnmpPeer(address, this.port);
+ //SnmpPeer peer = new SnmpPeer(address, this.port);
- // set community strings and protocol version
- peer.getParameters().setReadCommunity(this.readCommunity);
- peer.getParameters().setWriteCommunity(this.writeCommunity);
- peer.getParameters().setVersion(this.snmpVersion == SNMPV2 ? SnmpSMI.SNMPV2 : SnmpSMI.SNMPV1);
+ /********************************************************************
+ *
+ * START OF MINE!!!!
+ *
+ ********************************************************************/
- // Instantiate and initialize the RequestHandler implementation
- requestHandler = (RequestHandler)Class.forName(
- this.requestHandlerClassName, true, this.getClass().getClassLoader()).newInstance();
- requestHandler.initialize(this.requestHandlerResName, this.getServer(), this.log, this.clock);
+// TcpAddress tcpAddr = new TcpAddress(address, this.port);
+// DefaultTcpTransportMapping tcpMapping = new DefaultTcpTransportMapping(tcpAddr);
+// Snmp snmpPeer = new Snmp(tcpMapping);
+//
+ /********************************************************************
+ *
+ * END OF MINE!!!!
+ *
+ ********************************************************************/
+
+ /********************************************************************
+ *
+ * ORIG!!!!
+ *
+ ********************************************************************/
- // Instantiate the AgentSession with an optional thread pool
- this.agentSession = this.numberOfThreads > 1
- ? new SnmpAgentSession(requestHandler, peer, this.numberOfThreads)
- : new SnmpAgentSession(requestHandler, peer);
+// // set community strings and protocol version
+// peer.getParameters().setReadCommunity(this.readCommunity);
+// peer.getParameters().setWriteCommunity(this.writeCommunity);
+// peer.getParameters().setVersion(this.snmpVersion == SNMPV2 ? SnmpSMI.SNMPV2 : SnmpSMI.SNMPV1);
+//
+
+
+
+
+// // Instantiate the AgentSession with an optional thread pool
+// this.agentSession = this.numberOfThreads > 1
+// ? new SnmpAgentSession(requestHandler, peer, this.numberOfThreads)
+// : new SnmpAgentSession(requestHandler, peer);
}
/**
@@ -601,4 +660,102 @@
return InetAddress.getByName(host);
}
+// @Override
+// public void processPdu(CommandResponderEvent event) {
+// PDU pdu = event.getPDU();
+//
+// if (pdu == null)
+// return;
+//
+// int type = pdu.getType();
+// //switch based on pdu.getType() == ___
+// PDU response = null;
+// try{
+// switch (type) {
+// case PDU.GET:
+// response = requestHandler.snmpReceivedGet(pdu, false);
+//// Address address = event.getPeerAddress();
+//// Snmp snmp = new Snmp(new DefaultTcpTransportMapping((TcpAddress)address));
+// break;
+// case PDU.GETBULK:
+// //TODO maybe make a method called snmpReceivedGetBulk in requesthandler
+// // requestHandler.snmpReceivedGet(pdu);
+// break;
+// case PDU.GETNEXT:
+// response = requestHandler.snmpReceivedGet(pdu, true);
+// break;
+// case PDU.SET:
+// response = requestHandler.snmpReceivedSet(pdu);
+// break;
+// default:
+// log.warn("Invalid PDU type: " + PDU.getTypeString(type));
+// return;
+// }
+// if (response != null) {
+// sendResponse(event, response);
+// }
+// } catch (Exception e){
+// log.debug("Snmp request failed: "+ PDU.getTypeString(pdu.getType()));
+// }
+//
+// }
+
+// private void sendResponse(CommandResponderEvent requestEvent, PDU response) {
+// //MessageDispatcher disp = requestEvent.getMessageDispatcher();
+// try {
+// if (response.getBERLength() > requestEvent.getMaxSizeResponsePDU()) {
+// // response is tooBig
+// if (response.getType() != PDU.REPORT) {
+// if (requestEvent.getPDU().getType() == PDU.GETBULK) {
+// while ((response.size() > 0) &&
+// (response.getBERLength() >
+// requestEvent.getMaxSizeResponsePDU()))
+// {
+// response.trim();
+// }
+// }
+// else {
+// response.clear();
+// response.setRequestID(requestEvent.getPDU().getRequestID());
+// response.setErrorStatus(PDU.tooBig);
+// }
+// }
+// if (response.getBERLength() > requestEvent.getMaxSizeResponsePDU()) {
+// //still too big and can't send a response
+// return;
+// }
+// }
+////---start of my addition -- Mar 29
+//
+//
+////--end of my addition
+//
+// StatusInformation status = new StatusInformation();
+// StateReference stateRef = requestEvent.getStateReference();
+// if (stateRef == null) {
+// log.warn("No state reference available for requestEvent="+
+// requestEvent+". Cannot return response="+response);
+// }
+// else {
+// stateRef.setTransportMapping(requestEvent.getTransportMapping());
+// int resp = requestEvent.getMessageDispatcher().returnResponsePdu(requestEvent.getMessageProcessingModel(),
+// requestEvent.getSecurityModel(),
+// requestEvent.getSecurityName(),
+// requestEvent.getSecurityLevel(),
+// response,
+// requestEvent.getMaxSizeResponsePDU(),
+// //requestEvent.getStateReference(),
+// stateRef,
+// status);
+// log.info("Response was OK? : "+resp +" Constant: "+SnmpConstants.SNMP_MP_OK);
+// log.info("Returned response for requestID: " +
+// requestEvent.getPDU().getRequestID().toString() +
+// "to peer: "+requestEvent.getPeerAddress().toString());
+// }
+// }
+// catch (MessageException ex) {
+// log.error("Failed to send response to request "+requestEvent, ex);
+// }
+// }
+
}
Added: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java (rev 0)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -0,0 +1,123 @@
+package org.jboss.jmx.adaptor.snmp.agent;
+
+import org.jboss.logging.Logger;
+import org.snmp4j.CommandResponder;
+import org.snmp4j.CommandResponderEvent;
+import org.snmp4j.MessageException;
+import org.snmp4j.PDU;
+import org.snmp4j.mp.SnmpConstants;
+import org.snmp4j.mp.StateReference;
+import org.snmp4j.mp.StatusInformation;
+
+public class SnmpRequest implements CommandResponder {
+
+ /** Logger object */
+ protected Logger log;
+
+ /** the request handler instance handling get/set requests */
+ private RequestHandler requestHandler;
+
+ public SnmpRequest(RequestHandler requestHandler, Logger log){
+ this.requestHandler = requestHandler;
+ this.log = log;
+ }
+
+ public void setRequestHandler(RequestHandler requestHandler){
+ this.requestHandler = requestHandler;
+ }
+
+ public RequestHandler getRequestHandler(){
+ return this.requestHandler;
+ }
+
+ @Override
+ public void processPdu(CommandResponderEvent event) {
+ PDU pdu = event.getPDU();
+
+ if (pdu == null) {
+ log.warn("Null request PDU received ... skipping");
+ return;
+ }
+
+ log.info("Received Snmp request of type: "+PDU.getTypeString(pdu.getType()));
+ int type = pdu.getType();
+
+ PDU response = null;
+ //switch based on pdu.getType() == ___
+ switch (type) {
+ case PDU.GET:
+ response = requestHandler.snmpReceivedGet(pdu, false);
+ break;
+ case PDU.GETBULK:
+ //TODO maybe make a method called snmpReceivedGetBulk in requesthandler
+ // requestHandler.snmpReceivedGet(pdu);
+ break;
+ case PDU.GETNEXT:
+ response = requestHandler.snmpReceivedGet(pdu, true);
+ break;
+ case PDU.SET:
+ response = requestHandler.snmpReceivedSet(pdu);
+ break;
+ default:
+ log.warn("Cannot process request PDU of type: " +
+ PDU.getTypeString(type) + "unsupported");
+ return;
+ }
+ if (response != null) {
+
+ //VERY IMPORTANT LINE
+ response.setRequestID(event.getPDU().getRequestID());
+ try {
+ sendResponse(event, response);
+ } catch (MessageException e) {
+ log.warn("Response may not have been sent correctly. " +
+ "An error occured snmp4j message processing: " +
+ e.getMessage());
+ }
+ }
+ }
+
+ private void sendResponse(CommandResponderEvent requestEvent, PDU response) throws MessageException{
+
+ if (response.getBERLength() > requestEvent.getMaxSizeResponsePDU()) {
+ // response is tooBig
+ if (response.getType() != PDU.REPORT) {
+ if (requestEvent.getPDU().getType() == PDU.GETBULK) {
+ while ((response.size() > 0) &&
+ (response.getBERLength() >
+ requestEvent.getMaxSizeResponsePDU()))
+ {
+ response.trim();
+ }
+ }
+ else {
+ response.clear();
+ response.setRequestID(requestEvent.getPDU().getRequestID());
+ response.setErrorStatus(PDU.tooBig);
+ }
+ }
+ if (response.getBERLength() > requestEvent.getMaxSizeResponsePDU()) {
+ //still too big and can't send a response
+ return;
+ }
+ }
+
+ StatusInformation status = new StatusInformation();
+ StateReference stateRef = requestEvent.getStateReference();
+ if (stateRef == null) {
+ log.warn("No state reference available for requestEvent="+
+ requestEvent+". Cannot return response="+response);
+ }
+ else {
+ stateRef.setTransportMapping(requestEvent.getTransportMapping());
+ int resp = requestEvent.getMessageDispatcher().returnResponsePdu(requestEvent.getMessageProcessingModel(),
+ requestEvent.getSecurityModel(),
+ requestEvent.getSecurityName(),
+ requestEvent.getSecurityLevel(),
+ response,
+ requestEvent.getMaxSizeResponsePDU(),
+ stateRef,
+ status);
+ }
+ }
+}
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpVarBindFactory.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpVarBindFactory.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpVarBindFactory.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -29,6 +29,12 @@
import org.opennms.protocols.snmp.SnmpObjectId;
import org.opennms.protocols.snmp.SnmpOctetString;
import org.opennms.protocols.snmp.SnmpVarBind;
+import org.snmp4j.smi.Counter32;
+import org.snmp4j.smi.Counter64;
+import org.snmp4j.smi.Integer32;
+import org.snmp4j.smi.OID;
+import org.snmp4j.smi.OctetString;
+import org.snmp4j.smi.VariableBinding;
/**
* <tt>SnmpVarBindFactory</tt> implements the infrastructure required to
* generate SNMP variable bindings from generic Object instances.
@@ -61,7 +67,7 @@
{
makers.put("java.lang.String", new SnmpOctetStringMaker());
makers.put("java.lang.Integer", new SnmpInt32Maker());
- makers.put("java.lang.Long", new SnmpCounter64Maker());
+ makers.put("java.lang.Long", new SnmpCounter32Maker());
makers.put("java.math.BigInteger", new SnmpCounter64Maker());
makers.put("java.util.Date", new SnmpDateMaker());
}
@@ -71,7 +77,7 @@
* provided value, as this is returned by "getClass().getName()". If a
* match is found the call is delegated to the returned maker.
**/
- public SnmpVarBind make(String oid, Object value)
+ public VariableBinding make(String oid, Object value)
throws MappingFailedException
{
// Get value type and locate the maker
@@ -94,7 +100,7 @@
**/
interface Maker
{
- public SnmpVarBind make(String oid, Object value)
+ public VariableBinding make(String oid, Object value)
throws MappingFailedException;
}
@@ -104,15 +110,31 @@
class SnmpInt32Maker
implements Maker
{
- public SnmpVarBind make(String oid, Object value)
+ public VariableBinding make(String oid, Object value)
throws MappingFailedException
{
Integer i = (Integer)value;
- return new SnmpVarBind(new SnmpObjectId(oid),
- new SnmpInt32(i));
+ return new VariableBinding(new OID(oid),
+ new Integer32(i));
}
} // class SnmpInt32Maker
+
+ /**
+ * Generates unsigned long integer SNMP variable bindings
+ **/
+ class SnmpCounter32Maker
+ implements Maker
+ {
+ public VariableBinding make(String oid, Object value)
+ throws MappingFailedException
+ {
+ Long l = (Long)value;
+
+ return new VariableBinding(new OID(oid),
+ new Counter32(l.longValue()));
+ }
+ } // class SnmpCounter64Maker
/**
* Generates unsigned long integer SNMP variable bindings
@@ -120,13 +142,13 @@
class SnmpCounter64Maker
implements Maker
{
- public SnmpVarBind make(String oid, Object value)
+ public VariableBinding make(String oid, Object value)
throws MappingFailedException
{
Long l = (Long)value;
- return new SnmpVarBind(new SnmpObjectId(oid),
- new SnmpCounter64(l.longValue()));
+ return new VariableBinding(new OID(oid),
+ new Counter64(l.longValue()));
}
} // class SnmpCounter64Maker
@@ -136,13 +158,13 @@
class SnmpOctetStringMaker
implements Maker
{
- public SnmpVarBind make(String oid, Object value)
+ public VariableBinding make(String oid, Object value)
throws MappingFailedException
{
String s = (String)value;
- return new SnmpVarBind(new SnmpObjectId(oid),
- new SnmpOctetString(s.getBytes()));
+ return new VariableBinding(new OID(oid),
+ new OctetString(s.getBytes()));
}
} // class OctetStringMaker
@@ -152,7 +174,7 @@
class SnmpDateMaker
implements Maker
{
- public SnmpVarBind make(String oid, Object value)
+ public VariableBinding make(String oid, Object value)
throws MappingFailedException
{
Date d = (Date)value;
@@ -168,7 +190,7 @@
class SnmpObjectMaker
implements Maker
{
- public SnmpVarBind make(String oid, Object value)
+ public VariableBinding make(String oid, Object value)
throws MappingFailedException
{
SnmpOctetStringMaker sMaker = new SnmpOctetStringMaker();
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -19,6 +19,7 @@
**/
package org.jboss.jmx.adaptor.snmp.agent;
+import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -36,10 +37,30 @@
import org.jboss.xb.binding.MappingObjectModelFactory;
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
-import org.opennms.protocols.snmp.SnmpIPAddress;
-import org.opennms.protocols.snmp.SnmpPduPacket;
-import org.opennms.protocols.snmp.SnmpPduTrap;
+//import org.opennms.protocols.snmp.SnmpIPAddress;
+//import org.opennms.protocols.snmp.SnmpPduPacket;
+//import org.opennms.protocols.snmp.SnmpPduTrap;
+import org.snmp4j.CommunityTarget;
+import org.snmp4j.PDUv1;
+import org.snmp4j.ScopedPDU;
+import org.snmp4j.Target;
+import org.snmp4j.Snmp;
+import org.snmp4j.UserTarget;
+import org.snmp4j.mp.MPv3;
+import org.snmp4j.mp.SnmpConstants;
+import org.snmp4j.security.SecurityModels;
+import org.snmp4j.security.SecurityProtocols;
+import org.snmp4j.security.USM;
+import org.snmp4j.smi.Address;
+import org.snmp4j.smi.IpAddress;
+import org.snmp4j.smi.OctetString;
+import org.snmp4j.smi.TcpAddress;
+import org.snmp4j.smi.UdpAddress;
+import org.snmp4j.transport.AbstractTransportMapping;
+import org.snmp4j.transport.DefaultTcpTransportMapping;
+import org.snmp4j.transport.DefaultUdpTransportMapping;
+
/**
* <tt>TrapEmitter</tt> is a class that manages SNMP trap emission.
*
@@ -124,14 +145,6 @@
throws Exception
{
synchronized(this.managers) {
-
- // Recycle open sessions to managers
- Iterator i = this.managers.iterator();
-
- while (i.hasNext()) {
- ManagerRecord s = (ManagerRecord)i.next();
- s.closeSession();
- }
// Drop all held manager records
this.managers.clear();
@@ -158,45 +171,79 @@
}
// Cache the translated notification
- SnmpPduTrap v1TrapPdu = null;
- SnmpPduPacket v2TrapPdu = null;
-
+ PDUv1 v1TrapPdu = null;
+ ScopedPDU v2cTrapPdu = null;
+ ScopedPDU v3TrapPdu = null;
+
+ //The snmp session
+ Snmp snmp = null;
+
+ //The target to send to
+ Target t = null;
+
// Send trap. Synchronise on the subscription collection while
// iterating
- synchronized(this.managers) {
-
+ synchronized(this.managers) {
+
// Iterate over sessions and emit the trap on each one
Iterator i = this.managers.iterator();
while (i.hasNext()) {
- ManagerRecord s = (ManagerRecord)i.next();
-
+ //ManagerRecord t = (ManagerRecord)i.next();
+ t = (Target)i.next();
+
try {
- switch (s.getVersion()) {
- case SnmpAgentService.SNMPV1:
+ snmp = createSnmpSession(t.getAddress());
+ switch (t.getVersion()) {
+ case SnmpConstants.version1:
+ //case SnmpAgentService.SNMPV1:
if (v1TrapPdu == null)
v1TrapPdu = this.trapFactory.generateV1Trap(n);
// fix the agent ip in the trap depending on which local address is bound
- v1TrapPdu.setAgentAddress(new SnmpIPAddress(s.getLocalAddress()));
-
+ //Should work, but need to upgrade to snmp4j v.1.10.2
+ //v1TrapPdu.setAgentAddress((IpAddress)t.getAddress());
+
// Advance the trap counter
this.trapCount.advance();
// Send
- s.getSession().send(v1TrapPdu);
+ //s.getSession().send(v1TrapPdu);
+ log.debug("Sending trap: "+v1TrapPdu.toString() + "\n to target: "+ t.toString());
+ snmp.send(v1TrapPdu, t);
break;
- case SnmpAgentService.SNMPV2:
- if (v2TrapPdu == null)
- v2TrapPdu = this.trapFactory.generateV2Trap(n);
+ case SnmpConstants.version2c:
+ //case SnmpAgentService.SNMPV2:
+ if (v2cTrapPdu == null)
+ v2cTrapPdu = this.trapFactory.generateV2cTrap(n);
// Advance the trap counter
this.trapCount.advance();
// Send
- s.getSession().send(v2TrapPdu);
+ //t.getSession().send(v2TrapPdu);
+ snmp.send(v2cTrapPdu, t);
break;
+ case SnmpConstants.version3:
+
+ if (v3TrapPdu == null)
+ v3TrapPdu = this.trapFactory.generateV3Trap(n);
+
+// if (contextEngineID != null) {
+// trapPdu.setContextEngineID(contextEngineID);
+// }
+// if (contextName != null) {
+// trapPdu.setContextName(contextName);
+// }
+
+ // Advance the trap counter
+ this.trapCount.advance();
+
+ // Send
+ snmp.send(v3TrapPdu, t);
+ break;
+
default:
log.error("Skipping session: Unknown SNMP version found");
}
@@ -206,11 +253,17 @@
}
catch(Exception e) {
log.error("SNMP send error for " +
- s.getAddress().toString() + ":" +
- s.getPort() + ": <" + e +
+ t.getAddress().toString() + ":" +
+ ": <" + e +
">");
}
- }
+ }
+ if (snmp != null){
+ snmp.close();
+ }
+ else {
+ log.warn("No SNMP managers to send traps to");
+ }
}
}
@@ -261,36 +314,62 @@
{
// Read the monitoring manager's particulars
Manager m = (Manager)i.next();
-
- try
- {
- // Create a record of the manager's interest
- ManagerRecord mr = new ManagerRecord(
- InetAddress.getByName(m.getAddress()),
- m.getPort(),
- toInetAddressWithDefaultBinding(m.getLocalAddress()),
- m.getLocalPort(),
- m.getVersion()
- );
+ fixManagerVersion(m);
+// try
+// {
+ // Create a record of the manager's interest
+
+ Target target = createTarget(m);
+ if (target == null){
+ log.warn("createTarget: manager m: "+m.toString() + " is null!");
+ continue;
+ }
+
+// ManagerRecord mr = new ManagerRecord(
+// InetAddress.getByName(m.getAddress()),
+// m.getPort(),
+// toInetAddressWithDefaultBinding(m.getLocalAddress()),
+// m.getLocalPort(),
+// m.getVersion()
+// );
// Add the record to the list of monitoring managers. If
// successfull open the session to the manager as well.
- if (this.managers.add(mr) == false)
+ if (this.managers.add(target) == false)
{
log.warn("Ignoring duplicate manager: " + m);
}
- else
- {
+ //else
+ //{
// Open the session to the manager
- mr.openSession();
- }
- }
- catch (Exception e)
- {
- log.warn("Error enabling monitoring manager: " + m, e);
- }
+ //mr.openSession();
+ //}
+// }
+// catch (Exception e)
+// {
+// log.warn("Error enabling monitoring manager: " + m, e);
+// }
}
}
+
+ /**
+ * Function used to change the SNMP versions received from managers
+ * config file (1,2,3) to the actual versions used to distinguish in
+ * snmp4j (0,1,3)
+ * @param m the Manager who's version we want to fix
+ */
+ private void fixManagerVersion(Manager m){
+ if (m != null){
+ switch (m.getVersion()){
+ case 1:
+ m.setVersion(SnmpConstants.version1);
+ break;
+ case 2:
+ m.setVersion(SnmpConstants.version2c);
+ }
+
+ }
+ }
/**
* cater for possible global -b option, if no override has been specified
@@ -310,4 +389,81 @@
return InetAddress.getByName(host);
}
+ private Target createTarget(Manager m){
+ Target target = null;
+// String newAddr;
+// if (m.getAddress() != null){
+// System.out.println("*************************************");
+// System.out.println("Address" + m.getAddress());
+// System.out.println("Port" + m.getPort());
+// System.out.println("*************************************");
+// newAddr = m.getAddress()+"/"+m.getPort();
+// }
+// else {return null;}
+
+ int version = m.getVersion();
+ try{
+ if (version == SnmpConstants.version1 || version == SnmpConstants.version2c){
+
+ //change 'public' to a constant somewhere
+ //target = new CommunityTarget(new TcpAddress(newAddr), new OctetString("public"));
+
+ if (m.getAddress() != null){
+ target = new CommunityTarget(new UdpAddress(InetAddress.getByName(m.getAddress()), m.getPort()), new OctetString(m.getCommunityString()));
+ //try defining retries/timeout period in notifications.xml
+ //Timeout and Retries needs to be a field later on
+ //target.setRetries(3);
+ target.setTimeout(8000);
+ }
+ }
+ else if (version == SnmpConstants.version3) {
+ //won't be used at the moment
+ target = new UserTarget();
+ target.setAddress(new UdpAddress(InetAddress.getByName(m.getAddress()), m.getPort()));
+ }
+ else {
+ //unrecognized version
+ return null;
+ }
+
+ } catch (UnknownHostException e) {} //something goes here
+ if (target != null){
+ target.setVersion(version);
+ }
+ return target;
+ }
+
+ private Snmp createSnmpSession(Address address) throws IOException {
+ AbstractTransportMapping transport;
+ if (address instanceof TcpAddress) {
+ transport = new DefaultTcpTransportMapping();
+ }
+ else {
+ transport = new DefaultUdpTransportMapping();
+ }
+ // Could save some CPU cycles:
+ // transport.setAsyncMsgProcessingSupported(false);
+
+ Snmp snmp = new Snmp(transport);
+ OctetString localEngineID =
+ new OctetString(snmp.getLocalEngineID());
+ USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
+ SecurityModels.getInstance().addSecurityModel(usm);
+
+
+// SNMPv3 stuff ~ add and fix later
+//
+// ((MPv3)snmp.getMessageProcessingModel(MPv3.ID)).
+// setLocalEngineID(localEngineID.getValue());
+//
+// if (version == SnmpConstants.version3) {
+// USM usm = new USM(SecurityProtocols.getInstance(),
+// localEngineID,
+// engineBootCount);
+// SecurityModels.getInstance().addSecurityModel(usm);
+// addUsmUser(snmp);
+// }
+ return snmp;
+ }
+
} // class TrapEmitter
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -21,8 +21,8 @@
import javax.management.Notification;
-import org.opennms.protocols.snmp.SnmpPduPacket;
-import org.opennms.protocols.snmp.SnmpPduTrap;
+import org.snmp4j.PDUv1;
+import org.snmp4j.ScopedPDU;
/**
* <tt>TrapFactory </tt> takes care of translation of Notifications into
@@ -77,20 +77,31 @@
public void start()
throws Exception;
+
/**
- * Translates a Notification to an SNMP V2 trap.
+ * Traslates a Notification to an SNMP V1 trap.
*
* @param the notification to be translated
**/
- public SnmpPduPacket generateV2Trap(Notification n)
- throws MappingFailedException;
+ public PDUv1 generateV1Trap(Notification n)
+ throws MappingFailedException;
+
+ /**
+ * Translates a Notification to an SNMP V2c trap.
+ *
+ * @param the notification to be translated
+ **/
+// public SnmpPduPacket generateV2Trap(Notification n)
+// throws MappingFailedException;
+ public ScopedPDU generateV2cTrap(Notification n)
+ throws MappingFailedException;
/**
- * Traslates a Notification to an SNMP V1 trap.
+ * Traslates a Notification to an SNMP V3 trap.
*
* @param the notification to be translated
**/
- public SnmpPduTrap generateV1Trap(Notification n)
- throws MappingFailedException;
+ public ScopedPDU generateV3Trap(Notification n)
+ throws MappingFailedException;
} // TrapFactory
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -40,9 +40,13 @@
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
import org.jboss.xb.binding.UnmarshallingContext;
-import org.opennms.protocols.snmp.SnmpPduPacket;
-import org.opennms.protocols.snmp.SnmpPduRequest;
-import org.opennms.protocols.snmp.SnmpPduTrap;
+//import org.opennms.protocols.snmp.SnmpPduPacket;
+//import org.opennms.protocols.snmp.SnmpPduRequest;
+//import org.opennms.protocols.snmp.SnmpPduTrap;
+import org.snmp4j.PDU;
+import org.snmp4j.PDUv1;
+import org.snmp4j.ScopedPDU;
+import org.snmp4j.smi.OID;
import org.xml.sax.Attributes;
/**
@@ -265,7 +269,7 @@
/**
* Traslates a Notification to an SNMP V1 trap.
**/
- public SnmpPduTrap generateV1Trap(Notification n)
+ public PDUv1 generateV1Trap(Notification n)
throws MappingFailedException
{
if (log.isTraceEnabled())
@@ -287,14 +291,15 @@
Mapping m = (Mapping)this.notificationMapList.get(index);
// Create trap
- SnmpPduTrap trapPdu = new SnmpPduTrap();
+ PDUv1 trapPdu = new PDUv1();
- trapPdu.setTimeStamp(this.clock.uptime());
+ trapPdu.setTimestamp(this.clock.uptime());
+ trapPdu.setType(PDU.V1TRAP);
// Organise the 'variable' payload
- trapPdu.setGeneric(m.getGeneric());
- trapPdu.setSpecific(m.getSpecific());
- trapPdu.setEnterprise(m.getEnterprise());
+ trapPdu.setGenericTrap(m.getGeneric());
+ trapPdu.setSpecificTrap(m.getSpecific());
+ trapPdu.setEnterprise(new OID(m.getEnterprise()));
// Append the specified varbinds. Get varbinds from mapping and for
// each one of the former use the wrapper to get the corresponding
@@ -322,8 +327,8 @@
// wrapper in order for it to locate the required value. That
// value and the aforementioned OID are used to generate the
// variable binding
- trapPdu.addVarBind(
- this.snmpVBFactory.make(vb.getOid(), wrapper.get(vb.getTag())));
+ trapPdu.add(
+ this.snmpVBFactory.make(vb.getOid(), wrapper.get(vb.getTag())));
}
}
else
@@ -336,15 +341,15 @@
}
/**
- * Traslates a Notification to an SNMP V2 trap.
+ * Traslates a Notification to an SNMP V2c trap.
*
* TODO: how do you get timestamp, generic, and specific stuff in the trap
**/
- public SnmpPduPacket generateV2Trap(Notification n)
+ public ScopedPDU generateV2cTrap(Notification n)
throws MappingFailedException
{
if (log.isTraceEnabled())
- log.trace("generateV2Trap");
+ log.trace("generateV2cTrap");
// Locate mapping for incomming event
int index = -1;
@@ -362,7 +367,8 @@
Mapping m = (Mapping)this.notificationMapList.get(index);
// Create trap
- SnmpPduRequest trapPdu = new SnmpPduRequest(SnmpPduPacket.V2TRAP);
+ ScopedPDU trapPdu = new ScopedPDU();
+ trapPdu.setType(PDU.TRAP);
// Append the specified varbinds. Get varbinds from mapping and for
// each one of the former use the wrapper to get data from the
@@ -388,8 +394,8 @@
// wrapper in order for it to locate the required value. That
// value and the aforementioned OID are used to generate the
// variable binding
- trapPdu.addVarBind(
- this.snmpVBFactory.make(vb.getOid(), wrapper.get(vb.getTag())));
+ trapPdu.add(
+ this.snmpVBFactory.make(vb.getOid(), wrapper.get(vb.getTag())));
}
}
else
@@ -401,6 +407,72 @@
}
/**
+ * Traslates a Notification to an SNMP V3 trap.
+ *
+ * TODO: how do you get timestamp, generic, and specific stuff in the trap
+ **/
+ public ScopedPDU generateV3Trap(Notification n)
+ throws MappingFailedException
+ {
+ if (log.isTraceEnabled())
+ log.trace("generateV3Trap");
+
+ // Locate mapping for incomming event
+ int index = -1;
+
+ try
+ {
+ index = findMappingIndex(n);
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ throw new MappingFailedException(
+ "No mapping found for notification type: '" + n.getType() + "'");
+ }
+
+ Mapping m = (Mapping)this.notificationMapList.get(index);
+
+ // Create trap
+ ScopedPDU trapPdu = new ScopedPDU();
+ trapPdu.setType(PDU.TRAP);
+
+ // Append the specified varbinds. Get varbinds from mapping and for
+ // each one of the former use the wrapper to get data from the
+ // notification
+
+ // Get the coresponding wrapper
+ NotificationWrapper wrapper =
+ (NotificationWrapper)this.notificationWrapperCache.get(index);
+
+ if (wrapper != null)
+ {
+ // Prime the wrapper with the notification contents
+ wrapper.prime(n);
+
+ List vbList = m.getVarBindList().getVarBindList();
+
+ for (int i = 0; i < vbList.size(); i++)
+ {
+ VarBind vb = (VarBind)vbList.get(i);
+
+ // Append the var bind. Interrogate read vb for OID and
+ // variable tag. The later is used as the key passed to the
+ // wrapper in order for it to locate the required value. That
+ // value and the aforementioned OID are used to generate the
+ // variable binding
+ trapPdu.add(
+ this.snmpVBFactory.make(vb.getOid(), wrapper.get(vb.getTag())));
+ }
+ }
+ else
+ {
+ log.warn("Varbind mapping failure: null wrapper defined for " +
+ " notification type '" + m.getNotificationType() + "'" );
+ }
+ return trapPdu;
+ }
+
+ /**
* Utility class used by JBossXB to help parse notifications.xml
*/
private static class NotificationBinding implements GenericObjectModelFactory
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/manager/Manager.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/manager/Manager.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/manager/Manager.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -37,6 +37,7 @@
private String localAddress;
private int localPort;
private int version;
+ private String communityString;
// Constructors -------------------------------------------------
@@ -102,6 +103,17 @@
}
/**
+ * Method getCommunityString returns the value of field 'communityString'.
+ *
+ * @return the value of field 'communityString'.
+ *
+ */
+ public String getCommunityString()
+ {
+ return communityString;
+ }
+
+ /**
* Method setAddress sets the value of field 'address'.
*
* @param address the value of field 'address'.
@@ -152,6 +164,17 @@
this.version = version;
}
+ /**
+ * Method getCommunityString sets the value of field 'communityString'.
+ *
+ * @return the value of field 'communityString'.
+ *
+ */
+ public void setCommunityString(String communityString)
+ {
+ this.communityString = communityString;
+ }
+
// Object overrides ----------------------------------------------
public String toString()
@@ -163,7 +186,8 @@
.append(", port=").append(port)
.append(", localAddress=").append(localAddress)
.append(", localPort=").append(localPort)
- .append(", version=").append(version)
+ .append(", version=").append(version)
+ .append(", communityString=").append(communityString)
.append(']');
return sbuf.toString();
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/NotificationProducerService.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/NotificationProducerService.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/NotificationProducerService.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -19,9 +19,25 @@
**/
package org.jboss.jmx.adaptor.snmp.test;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
import javax.management.Notification;
-
+import org.jboss.jmx.adaptor.snmp.agent.EventTypes;
import org.jboss.system.ServiceMBeanSupport;
+import org.snmp4j.CommunityTarget;
+import org.snmp4j.PDU;
+import org.snmp4j.Snmp;
+import org.snmp4j.Target;
+import org.snmp4j.event.ResponseEvent;
+import org.snmp4j.smi.Address;
+import org.snmp4j.smi.OID;
+import org.snmp4j.smi.TcpAddress;
+import org.snmp4j.smi.UdpAddress;
+import org.snmp4j.smi.VariableBinding;
+import org.snmp4j.transport.DefaultTcpTransportMapping;
+import org.snmp4j.transport.DefaultUdpTransportMapping;
/**
* <tt>NotificationProducerService</tt> is a test class with an MBean interface
@@ -40,6 +56,7 @@
extends ServiceMBeanSupport
implements NotificationProducerServiceMBean
{
+
/**
* Sends a test Notification of type "V1"
*
@@ -48,8 +65,10 @@
public void sendV1()
throws Exception
{
- sendNotification(
- new Notification("V1", this, getNextNotificationSequenceNumber(),
+ log.debug("Sending SnmpV1 test notification");
+
+ sendNotification(
+ new Notification(EventTypes.V1_TEST_NOTIFICATION, this, getNextNotificationSequenceNumber(),
"V1 test notifications"));
}
@@ -61,10 +80,73 @@
public void sendV2()
throws Exception
{
- sendNotification(
- new Notification("V2", this, getNextNotificationSequenceNumber(),
+ log.debug("Sending SnmpV2 test notification");
+ sendNotification(
+ new Notification(EventTypes.V2_TEST_NOTIFICATION, this, getNextNotificationSequenceNumber(),
"V2 test notifications"));
}
+ /**
+ * Sends a test Notification of type "V3"
+ *
+ * @jmx:managed-operation
+ **/
+ public void sendV3()
+ throws Exception
+ {
+ log.debug("Sending SnmpV3 test notification");
+ sendNotification(
+ new Notification(EventTypes.V3_TEST_NOTIFICATION, this, getNextNotificationSequenceNumber(),
+ "V3 test notifications"));
+ }
+
+
+ /**
+ * Sends a test GET request
+ *
+ * @jmx:managed-operation
+ */
+ public void get(){
+ PDU pdu = new PDU();
+ pdu.setType(PDU.GET);
+ pdu.add(new VariableBinding(new OID("1.2.3.4.1.3")));
+
+ Target target = new CommunityTarget();
+ try {
+ target.setAddress(new UdpAddress(InetAddress.getByName("127.0.0.1"), 1161));//could be 1162
+ DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping();
+ Snmp snmp = new Snmp(transport);
+ ResponseEvent responseEvent = snmp.send(pdu, target);
+ System.out.println("response " + responseEvent.toString());
+ // extract the response PDU (could be null if timed out)
+
+ PDU responsePDU = responseEvent.getResponse();
+ if (responsePDU == null){
+ System.out.println("Request Timed out ...");
+ }
+ else {
+ System.out.println("RESPONSE RECEIVED!");
+ System.out.println("responsePdu = " + responsePDU);
+
+ }
+ } catch (UnknownHostException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ }
+
+ /**
+ * Sends a test SET request
+ *
+ * @jmx:managed-operation
+ */
+ public void set(){
+
+ }
+
} // class NotificationProducerService
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/NotificationProducerServiceMBean.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/NotificationProducerServiceMBean.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/NotificationProducerServiceMBean.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -35,5 +35,20 @@
* Sends a test Notification of type "V2"
*/
void sendV2() throws java.lang.Exception;
+
+ /**
+ * Sends a test Notification of type "V3"
+ */
+ void sendV3() throws java.lang.Exception;
+
+ /**
+ * Sends a test SNMP GET
+ */
+ void get();
+
+ /**
+ * Sends a test SNMP SET
+ */
+ void set();
}
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/trapd/TrapdService.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/trapd/TrapdService.java 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/trapd/TrapdService.java 2010-07-05 15:01:37 UTC (rev 106424)
@@ -21,11 +21,39 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.Iterator;
+import java.util.Vector;
import org.jboss.bootstrap.api.as.config.JBossASServerConfig;
import org.jboss.system.ServiceMBeanSupport;
-import org.opennms.protocols.snmp.SnmpTrapSession;
+//import org.opennms.protocols.snmp.SnmpPduRequest;
+//import org.opennms.protocols.snmp.SnmpTrapSession;
+//import org.opennms.protocols.snmp.SnmpVarBind;
+
+import org.snmp4j.CommandResponder;
+import org.snmp4j.CommandResponderEvent;
+import org.snmp4j.MessageDispatcher;
+import org.snmp4j.MessageDispatcherImpl;
+import org.snmp4j.PDU;
+import org.snmp4j.PDUv1;
+import org.snmp4j.ScopedPDU;
+import org.snmp4j.Snmp;
+import org.snmp4j.TransportMapping;
+import org.snmp4j.mp.MPv1;
+import org.snmp4j.mp.MPv2c;
+import org.snmp4j.mp.MPv3;
+import org.snmp4j.mp.SnmpConstants;
+import org.snmp4j.security.SecurityModels;
+import org.snmp4j.security.SecurityProtocols;
+import org.snmp4j.security.USM;
+import org.snmp4j.smi.OctetString;
+import org.snmp4j.smi.TcpAddress;
+import org.snmp4j.smi.UdpAddress;
+import org.snmp4j.smi.VariableBinding;
+import org.snmp4j.transport.DefaultTcpTransportMapping;
+import org.snmp4j.transport.DefaultUdpTransportMapping;
+
/**
* MBean wrapper class that acts as an SNMP trap receiver/logger.
* It logs traps as INFO messages - change log4j configuration to
@@ -42,7 +70,7 @@
**/
public class TrapdService
extends ServiceMBeanSupport
- implements TrapdServiceMBean
+ implements TrapdServiceMBean, CommandResponder
{
/** The listening port */
private int port;
@@ -51,7 +79,7 @@
private InetAddress bindAddress;
/** The snmp session used to receive the traps*/
- protected SnmpTrapSession trapSession;
+ protected Snmp snmp;
/**
* Empty CTOR
@@ -123,19 +151,34 @@
{
// Create the SNMP trap receiving session with the logging handler,
// using Logger inherited from ServiceMBeanSupport
- try {
+
// cater for possible global -b option, if no override has been specified
InetAddress address = this.bindAddress != null ? this.bindAddress :
toInetAddress(System.getProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_BIND_ADDRESS));
- this.trapSession =
- new SnmpTrapSession(new TrapReceiver(this.log), this.port, address);
- }
- catch (Exception e) {
- log.error("Cannot instantiate trap session");
-
- throw e; // ServiceMBeanSupport will log this
- }
+ MessageDispatcher mtDispatcher = new MessageDispatcherImpl();
+//
+// // add message processing models
+ mtDispatcher.addMessageProcessingModel(new MPv1());
+ mtDispatcher.addMessageProcessingModel(new MPv2c());
+ mtDispatcher.addMessageProcessingModel(new MPv3());
+ TransportMapping transport =
+ new DefaultUdpTransportMapping(new UdpAddress(address,port));
+
+ this.snmp = new Snmp(mtDispatcher,transport);
+
+ //start test
+// OctetString localEngineID =
+// new OctetString(snmp.getLocalEngineID());
+// USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
+// SecurityModels.getInstance().addSecurityModel(usm);
+ //end test
+
+// this.snmp = new Snmp(mtDispatcher, transport);
+
+ snmp.addCommandResponder(this);
+ snmp.listen();
+ log.debug("listening on: "+address);
}
/**
@@ -144,8 +187,10 @@
protected void stopService()
throws Exception
{
- this.trapSession.close();
- this.trapSession = null; // gc
+ snmp.close();
+
+// this.trapSession.close();
+// this.trapSession = null; // gc
}
/**
@@ -159,5 +204,82 @@
else
return InetAddress.getByName(host);
}
+
+ @Override
+ public void processPdu(CommandResponderEvent e) {
+// PDUv1 pdu = (PDUv1)e.getPDU();
+ PDU pdu = e.getPDU();
+ if (pdu != null){
+
+ if (pdu instanceof PDUv1){
+ processPDUv1((PDUv1)pdu);
+ } else if (pdu instanceof ScopedPDU) {
+ processScopedPDU((ScopedPDU)pdu);
+ } else {
+ log.warn("Unknown PDU type: " + PDU.getTypeString(pdu.getType()));
+ }
+
+ }
+ }
+
+ private void processScopedPDU(ScopedPDU pdu) {
+ //****
+ StringBuffer sbuf = new StringBuffer();
+ //sbuf.append("\n***************NEW SNMP4J ADAPTOR******************");
+ sbuf.append("\nV2/V3 Trap from agent ").append(this.bindAddress.toString());
+ sbuf.append(" on port ").append(this.port);
+
+ //sbuf.append("\nCommunity string... ").append(community.toString());
+ sbuf.append("\n");
+
+ Vector bindings = pdu.getVariableBindings();
+ Iterator it = bindings.iterator();
+ int counter = 0;
+ while (it.hasNext())
+ {
+ VariableBinding vb = (VariableBinding)it.next();
+ if (vb != null) {
+ sbuf.append("Varbind[").append(counter++).append("] := ");
+// sbuf.append(vb.toString());
+ sbuf.append(vb.getOid().toString()).append(" --> ");
+ sbuf.append(vb.getVariable().toString()).append("\n");
+ }
+ }
+ sbuf.append("\nLength............. ").append(counter);
+ log.debug(sbuf.toString());
+
+ }
+
+ private void processPDUv1(PDUv1 pdu) {
+ //*****
+ StringBuffer sbuf = new StringBuffer();
+ //sbuf.append("\n***************NEW SNMP4J ADAPTOR******************");
+ sbuf.append("\nV1 Trap from agent ").append(this.bindAddress.toString());
+ sbuf.append(" on port ").append(this.port);
+ sbuf.append("\nIP Address......... ").append(pdu.getAgentAddress().toString());
+ sbuf.append("\nEnterprise Id...... ").append(pdu.getEnterprise());
+ sbuf.append("\nGeneric ........... ").append(pdu.getGenericTrap());
+ sbuf.append("\nSpecific .......... ").append(pdu.getSpecificTrap());
+ sbuf.append("\nTimeStamp ......... ").append(pdu.getTimestamp());
+
+ //sbuf.append("\nCommunity string... ").append(community.toString());
+ sbuf.append("\n");
+
+ Vector bindings = pdu.getVariableBindings();
+ Iterator it = bindings.iterator();
+ int counter = 0;
+ while (it.hasNext())
+ {
+ VariableBinding vb = (VariableBinding)it.next();
+ if (vb != null) {
+ sbuf.append("Varbind[").append(counter++).append("] := ");
+// sbuf.append(vb.toString());
+ sbuf.append(vb.getOid().toString()).append(" --> ");
+ sbuf.append(vb.getVariable().toString()).append("\n");
+ }
+ }
+ sbuf.append("\nLength............. ").append(counter);
+ log.debug(sbuf.toString());
+ }
} // class TrapdService
Modified: branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/META-INF/jboss-service.xml
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/META-INF/jboss-service.xml 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/META-INF/jboss-service.xml 2010-07-05 15:01:37 UTC (rev 106424)
@@ -84,7 +84,12 @@
parameter="jboss.jmx:name=SnmpAgent,service=trapd,type=logger"/>
</attribute>
</mbean>
+
+ <!-- Used for internal testing - ignore -->
+ <mbean code="org.jboss.jmx.adaptor.snmp.test.NotificationProducerService"
+ name="jboss.jmx:name=SnmpAgent,service=notification,type=producer"/>
+
<!-- The SNMP adaptor MBean -->
<mbean code="org.jboss.jmx.adaptor.snmp.agent.SnmpAgentService"
name="jboss.jmx:name=SnmpAgent,service=snmp,type=adaptor">
@@ -94,7 +99,7 @@
<attribute name="TrapFactoryClassName">org.jboss.jmx.adaptor.snmp.agent.TrapFactorySupport</attribute>
<attribute name="NotificationMapResName">/notifications.xml</attribute>
<attribute name="ManagersResName">/managers.xml</attribute>
- <attribute name="HeartBeatPeriod">0</attribute>
+ <attribute name="HeartBeatPeriod">2</attribute>
<attribute name="BindAddress">
<!-- Get the interface from the ServiceBindingManager -->
<value-factory bean="ServiceBindingManager" method="getStringBinding"
@@ -118,6 +123,13 @@
<mbean name="jboss.jmx:name=SnmpAgent,service=timer,type=heartbeat">
<notification type="jboss.snmp.agent.heartbeat"/>
</mbean>
+
+ <!-- Monitor NotificationProducer test events (internal testing) -ignore -->
+ <mbean name="jboss.jmx:name=SnmpAgent,service=notification,type=producer">
+ <notification type="jboss.snmp.agent.v1test"/>
+ <notification type="jboss.snmp.agent.v2test"/>
+ <notification type="jboss.snmp.agent.v3test"/>
+ </mbean>
<!-- Valid JMX ObjectName patterns may be used as well, for example
<mbean name="*:service=invoker,*"/>
@@ -149,9 +161,5 @@
jboss.jmx:name=SnmpAgent,service=snmp,type=adaptor
</depends>
</mbean>
-
- <!-- Used for internal testing - ignore
- <mbean code="org.jboss.jmx.adaptor.snmp.test.NotificationProducerService"
- name="jboss.jmx:name=SnmpAgent,service=notification,type=producer"/>
- -->
-</service>
\ No newline at end of file
+
+</service>
Modified: branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/managers.xml
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/managers.xml 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/managers.xml 2010-07-05 15:01:37 UTC (rev 106424)
@@ -32,5 +32,6 @@
<local-address></local-address>
<local-port></local-port>
<version>1</version>
+ <community-string>public</community-string>
</manager>
</manager-list>
Modified: branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/notifications.xml
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/notifications.xml 2010-07-05 11:15:01 UTC (rev 106423)
+++ branches/snmp4j-integration-1.11.1/varia/src/resources/services/snmp/deploy/notifications.xml 2010-07-05 15:01:37 UTC (rev 106424)
@@ -64,4 +64,57 @@
</var-bind-list>
</mapping>
+<!-- Used for internal testing -ignore -->
+ <mapping>
+ <notification-type>jboss.snmp.agent.v1test</notification-type>
+ <generic>10</generic>
+ <specific>0</specific>
+ <enterprise>1.2.3.4.5.6.7</enterprise>
+ <var-bind-list wrapper-class="org.jboss.jmx.adaptor.snmp.agent.NotificationWrapperSupport">
+ <var-bind>
+ <tag>a:startTime</tag>
+ <oid>1.2.3.4.5.6.7.9</oid>
+ </var-bind>
+ <var-bind>
+ <tag>a:trapCount</tag>
+ <oid>1.2.3.4.5.6.7.6</oid>
+ </var-bind>
+ </var-bind-list>
+ </mapping>
+
+ <mapping>
+ <notification-type>jboss.snmp.agent.v2test</notification-type>
+ <generic>11</generic>
+ <specific>0</specific>
+ <enterprise>1.2.3.4.5.6.7</enterprise>
+ <var-bind-list wrapper-class="org.jboss.jmx.adaptor.snmp.agent.NotificationWrapperSupport">
+ <var-bind>
+ <tag>a:startTime</tag>
+ <oid>1.2.3.4.5.6.7.9</oid>
+ </var-bind>
+ <var-bind>
+ <tag>a:trapCount</tag>
+ <oid>1.2.3.4.5.6.7.6</oid>
+ </var-bind>
+ </var-bind-list>
+ </mapping>
+
+ <mapping>
+ <notification-type>jboss.snmp.agent.v3test</notification-type>
+ <generic>12</generic>
+ <specific>0</specific>
+ <enterprise>1.2.3.4.5.6.7</enterprise>
+ <var-bind-list wrapper-class="org.jboss.jmx.adaptor.snmp.agent.NotificationWrapperSupport">
+ <var-bind>
+ <tag>a:startTime</tag>
+ <oid>1.2.3.4.5.6.7.9</oid>
+ </var-bind>
+ <var-bind>
+ <tag>a:trapCount</tag>
+ <oid>1.2.3.4.5.6.7.6</oid>
+ </var-bind>
+ </var-bind-list>
+ </mapping>
+
+
</notification-map-list>
More information about the jboss-cvs-commits
mailing list