[jboss-cvs] JBossAS SVN: r111782 - branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 19 16:55:16 EDT 2011
Author: thauser at redhat.com
Date: 2011-07-19 16:55:16 -0400 (Tue, 19 Jul 2011)
New Revision: 111782
Modified:
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NotificationWrapper.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NotificationWrapperSupport.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java
Log:
tags with the value a:* will be retrieved using the OID of the variable, if possible, not the NotificationWrapperSupport class.
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NotificationWrapper.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NotificationWrapper.java 2011-07-19 20:53:48 UTC (rev 111781)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NotificationWrapper.java 2011-07-19 20:55:16 UTC (rev 111782)
@@ -63,6 +63,9 @@
public static final String STARTTIME_TAG = "a:startTime";
public static final String UPTIME_TAG = "a:uptime";
public static final String TRAPCOUNT_TAG = "a:trapCount";
+
+ // user properties
+ public static final String USERDATA_TAG = "u:userData";
/**
* Sets the uptime clock and trap counter
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NotificationWrapperSupport.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NotificationWrapperSupport.java 2011-07-19 20:53:48 UTC (rev 111781)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/NotificationWrapperSupport.java 2011-07-19 20:55:16 UTC (rev 111782)
@@ -109,6 +109,8 @@
if (userData instanceof Map) {
// Copy all of the user data in the payload
this.payload.putAll((Map)userData);
+ } else {
+ this.payload.put(USERDATA_TAG, userData);
}
} // prime
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java 2011-07-19 20:53:48 UTC (rev 111781)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java 2011-07-19 20:55:16 UTC (rev 111782)
@@ -27,6 +27,8 @@
import org.jboss.jmx.adaptor.snmp.config.attribute.ManagedBean;
import org.jboss.logging.Logger;
+import org.snmp4j.smi.OID;
+import org.snmp4j.smi.Variable;
/**
* Interface that must be implemented by classes
@@ -52,5 +54,5 @@
void addAttributeMappings(List<ManagedBean> mappings);
void removeAttributeMappings(List<ManagedBean> mappings);
-
+ Variable getValueFor(OID oid) throws NoSuchInstanceException, VariableTypeException;
} // RequestHandler
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2011-07-19 20:53:48 UTC (rev 111781)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2011-07-19 20:55:16 UTC (rev 111782)
@@ -32,6 +32,9 @@
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
import javax.management.Attribute;
import javax.management.MBeanServer;
@@ -787,7 +790,7 @@
* The oid we want a value for
* @return Null if no value present
*/
- private Variable getValueFor(final OID oid) throws NoSuchInstanceException, VariableTypeException {
+ public Variable getValueFor(final OID oid) throws NoSuchInstanceException, VariableTypeException {
BindEntry be = findBindEntryForOid(oid);
Variable ssy = null;
@@ -913,15 +916,24 @@
// manage regular java types
if (value instanceof Long) {
result = new OctetString(((Long)value).toString());
- } else if (value instanceof Boolean) {
+ } else if (value instanceof AtomicLong) {
+ result = new OctetString(((AtomicLong)value).toString());
+ } else if (value instanceof Boolean) {
if(((Boolean)value).booleanValue())
result = new Integer32(1);
else
result = new Integer32(0);
+ } else if (value instanceof AtomicBoolean) {
+ if(((AtomicBoolean)value).get())
+ result = new Integer32(1);
+ else
+ result = new Integer32(0);
} else if (value instanceof String) {
result = new OctetString((String) value);
} else if (value instanceof Integer) {
result = new Integer32((Integer)value);
+ } else if (value instanceof AtomicInteger) {
+ result = new Integer32(((AtomicInteger)value).get());
} else if (value instanceof OID) {
result = new OID((OID)value);
} else if (value instanceof TimeTicks) {
@@ -952,6 +964,8 @@
{
if(attribute instanceof Long) {
result = Long.parseLong(val.toString());
+ } else if(attribute instanceof AtomicLong) {
+ result = new AtomicLong(Long.parseLong(val.toString()));
} else {
result = val.toString();
}
@@ -964,6 +978,14 @@
} else {
result = Boolean.TRUE;
}
+ } else if(attribute instanceof AtomicBoolean) {
+ if(((Integer32)val).getValue() == 0) {
+ result = new AtomicBoolean(Boolean.FALSE);
+ } else {
+ result = new AtomicBoolean(Boolean.TRUE);
+ }
+ } else if(attribute instanceof AtomicInteger) {
+ result = new AtomicInteger(Integer.valueOf(((Integer32)val).getValue()));
} else {
result = Integer.valueOf(((Integer32)val).getValue());
}
@@ -1205,8 +1227,7 @@
if(nextOid != null) {
return nextOid;
}
- SortedSet<OID> ret;
- ret=oidKeys.tailSet(oid); // get oids >= oid
+ SortedSet<OID> ret = new TreeSet(oidKeys.tailSet(oid)); // get oids >= oid
Iterator<OID> it = ret.iterator();
OID roid=null;
@@ -1243,6 +1264,16 @@
}
}
+ if(roid.last() != 0) {
+ nextOid = tableMapper.getNextTable(roid);
+ if(nextOid != null) {
+ return nextOid;
+ }
+ nextOid = attributeTableMapper.getNextTable(roid);
+ if(nextOid != null) {
+ return nextOid;
+ }
+ }
return roid;
}
@@ -1250,7 +1281,7 @@
* was repeated so many times it was prudent to give it it's own method.
* @param response This PDU is the one being modified into an error PDU.
* @param oid The OID to contain the error Null instance.
- * @param errIndex the VariableBinding in the PDU that caused the error.
+ * @param errorIndex the VariableBinding in the PDU that caused the error.
* @param err The error number defined in the PDU class that indicates a given failure
*/
private void makeErrorPdu(PDU response, PDU pdu, int errorIndex, int err){
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java 2011-07-19 20:53:48 UTC (rev 111781)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java 2011-07-19 20:55:16 UTC (rev 111782)
@@ -129,7 +129,8 @@
// Initialise
this.trapFactory.set(this.snmpAgentService.getClock(),
- this.snmpAgentService.getTrapCounter());
+ this.snmpAgentService.getTrapCounter(),
+ this.snmpAgentService.getRequestHandler());
// Start the trap factory
this.trapFactory.start();
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java 2011-07-19 20:53:48 UTC (rev 111781)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java 2011-07-19 20:55:16 UTC (rev 111782)
@@ -72,6 +72,8 @@
**/
public void set(Clock uptime, Counter count);
+ public void set(Clock uptime, Counter count, RequestHandler rh);
+
/**
* Performs all the required initialisation in order for the mapper to
* commence operation (e.g. reading of the resource file)
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java 2011-07-19 20:53:48 UTC (rev 111781)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java 2011-07-19 20:55:16 UTC (rev 111782)
@@ -35,6 +35,7 @@
import org.snmp4j.ScopedPDU;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.OID;
+import org.snmp4j.smi.Variable;
import org.snmp4j.smi.TimeTicks;
import org.snmp4j.smi.VariableBinding;
import org.xml.sax.Attributes;
@@ -91,12 +92,9 @@
/** Trap counter */
private Counter trapCount = null;
- /** attributes gathered from attributes.xml, used for bindings **/
- // private SortedMap bindings = null;
+ /** Request handler ref */
+ private RequestHandler requestHandler = null;
- /** MBeanServer instance to query about BindEntry objects contained in the bindings map**/
- // private MBeanServer server = null;
-
/**
* Create TrapFactorySupport
**/
@@ -113,9 +111,13 @@
{
this.clock = clock;
this.trapCount = count;
-// this.server = server;
}
+ public void set(Clock clock, Counter count, RequestHandler rh){
+ this.clock = clock;
+ this.trapCount = count;
+ this.requestHandler = rh;
+ }
/**
* Populates the regular expression and wrapper instance collections. Note
* that a failure (e.g. to compile a regular expression or to instantiate a
@@ -155,9 +157,6 @@
// Append the specified varbinds. Get varbinds from mapping and for
// each one of the former use the wrapper to get the corresponding
// values
-
- // we don't want to use the wrapper for getting the values. we want to use the MBeanServer to
- // directly query the included OID. This is how traps should have been done.
if(wrapper != null)
{
@@ -172,16 +171,33 @@
{
VarBind vb = (VarBind)vbList.get(i);
- // we should first attempt to find the OID's value in the list of bindings, whether it be a table cell
- // or otherwise. We do this by calling into the list of bind entries.
-
- // 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())));
+ if (vb.getTag().matches("^a:.*")){
+ OID oid = new OID(vb.getOid()+".0");
+ Variable var;
+ try{
+ var = requestHandler.getValueFor(oid);
+ }
+ catch (Exception e){
+ var = null;
+ }
+
+ if (var != null){
+ trapPdu.add(new VariableBinding(oid, var));
+ }
+ else { // we failed to find the variable with given oid here. we fall back onto the wrapper.
+ trapPdu.add(
+ this.snmpVBFactory.make(vb.getOid(), wrapper.get(vb.getTag())));
+ }
+ }
+ else{
+ // 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
@@ -229,15 +245,35 @@
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())));
+ VarBind vb = (VarBind)vbList.get(i);
+
+ if (vb.getTag().matches("^a:.*")){
+ OID oid = new OID(vb.getOid()+".0");
+ Variable var;
+ try{
+ var = requestHandler.getValueFor(oid);
+ }
+ catch (Exception e){
+ var = null;
+ }
+
+ if (var != null){
+ trapPdu.add(new VariableBinding(oid, var));
+ }
+ else { // we failed to find the variable with given oid here. we fall back onto the wrapper.
+ trapPdu.add(
+ this.snmpVBFactory.make(vb.getOid(), wrapper.get(vb.getTag())));
+ }
+ }
+ else{
+ // 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
@@ -282,23 +318,35 @@
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
-
- /**
- * This is incorrect. we should not be using this "tag" system at all, but
- * we should be using the OID itself as a key to find a BindEntry that matches
- * the OID. Trap variable bindings must consist of MIB-defined Objects, not arbitrarily
- * defined variables.
- */
-
- trapPdu.add(
- this.snmpVBFactory.make(vb.getOid(), wrapper.get(vb.getTag())));
+ VarBind vb = (VarBind)vbList.get(i);
+
+ if (vb.getTag().matches("^a:.*")){
+ OID oid = new OID(vb.getOid()+".0");
+ Variable var;
+ try{
+ var = requestHandler.getValueFor(oid);
+ }
+ catch (Exception e){
+ var = null;
+ }
+
+ if (var != null){
+ trapPdu.add(new VariableBinding(oid, var));
+ }
+ else { // we failed to find the variable with given oid here. we fall back onto the wrapper.
+ trapPdu.add(
+ this.snmpVBFactory.make(vb.getOid(), wrapper.get(vb.getTag())));
+ }
+ }
+ else{
+ // 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 " +
More information about the jboss-cvs-commits
mailing list