[jboss-cvs] JBossAS SVN: r110304 - in branches/snmp4j-integration-1.11.1: varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jan 7 09:30:44 EST 2011
Author: thauser at redhat.com
Date: 2011-01-07 09:30:43 -0500 (Fri, 07 Jan 2011)
New Revision: 110304
Added:
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedTable.java
Modified:
branches/snmp4j-integration-1.11.1/pom.xml
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeMappingsBinding.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/SnmpRequest.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedAttribute.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java
Log:
started the modifications needed to have tabular data structures.
Modified: branches/snmp4j-integration-1.11.1/pom.xml
===================================================================
--- branches/snmp4j-integration-1.11.1/pom.xml 2011-01-07 13:48:54 UTC (rev 110303)
+++ branches/snmp4j-integration-1.11.1/pom.xml 2011-01-07 14:30:43 UTC (rev 110304)
@@ -549,7 +549,7 @@
<module>tomcat</module>
<module>varia</module>
<module>webservices</module>
- <module>weld-int</module>
+ <!--<module>weld-int</module>-->
<!-- distro modules -->
<module>client</module>
<module>build</module>
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeMappingsBinding.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeMappingsBinding.java 2011-01-07 13:48:54 UTC (rev 110303)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/AttributeMappingsBinding.java 2011-01-07 14:30:43 UTC (rev 110304)
@@ -26,6 +26,7 @@
import org.jboss.jmx.adaptor.snmp.config.attribute.AttributeMappings;
import org.jboss.jmx.adaptor.snmp.config.attribute.ManagedBean;
import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
+import org.jboss.jmx.adaptor.snmp.config.attribute.MappedTable;
import org.jboss.logging.Logger;
import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.UnmarshallingContext;
@@ -87,9 +88,10 @@
public Object newChild(ManagedBean mbean, UnmarshallingContext navigator,
String namespaceUri, String localName, Attributes attrs)
{
+ Object placeholder = null;
- MappedAttribute attribute = null;
if ("attribute".equals(localName)) {
+ MappedAttribute attribute = null;
String oid = attrs.getValue("oid");
String name = attrs.getValue("name");
String mode = attrs.getValue("mode");
@@ -98,8 +100,22 @@
attribute.setReadWrite(true);
attribute.setName(name);
attribute.setOid(oid);
+ return attribute;
}
- return attribute;
+ else if ("table".equals(localName)){
+ MappedTable attribute = null;
+ String oidPrefix = attrs.getValue("oid-prefix");
+ String name = attrs.getValue("name");
+ int size = Integer.parseInt(attrs.getValue("size"));
+ attribute = new MappedTable();
+ attribute.setName(name);
+ attribute.setPrefix(oidPrefix);
+ attribute.setSize(size);
+ return attribute;
+ }
+
+ return placeholder;
+
}
public void addChild(ManagedBean mbean, MappedAttribute attribute,
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 2011-01-07 13:48:54 UTC (rev 110303)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2011-01-07 14:30:43 UTC (rev 110304)
@@ -28,7 +28,6 @@
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.TreeSet;
import java.util.Vector;
@@ -40,6 +39,7 @@
import org.jboss.jmx.adaptor.snmp.config.attribute.AttributeMappings;
import org.jboss.jmx.adaptor.snmp.config.attribute.ManagedBean;
import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
+import org.jboss.jmx.adaptor.snmp.config.attribute.MappedTable;
import org.jboss.logging.Logger;
import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.Unmarshaller;
@@ -693,40 +693,64 @@
Iterator aIt = attrs.iterator();
while (aIt.hasNext())
{
- MappedAttribute ma = (MappedAttribute)aIt.next();
- String oid;
- if (oidPrefix != null)
- oid = oidPrefix + ma.getOid();
- else
- oid = ma.getOid();
-
- BindEntry be = new BindEntry(oid, mmb.getName(), ma.getName());
- be.isReadWrite = ma.isReadWrite();
-
- OID coid = new OID(oid);
- if (log.isTraceEnabled())
- log.trace("New bind entry " + be);
- if (bindings.containsKey(coid)) {
- log.info("Duplicate oid " + oid + SKIP_ENTRY);
- continue;
- }
- if (mmb.getName() == null || mmb.getName().equals(""))
- {
- log.info("Invalid mbean name for oid " + oid + SKIP_ENTRY);
- continue;
- }
- if (ma.getName() == null || ma.getName().equals(""))
- {
- log.info("Invalid attribute name " + ma.getName() + " for oid " + oid + SKIP_ENTRY);
- continue;
- }
- bindings.put(coid, be);
- oidKeys.add(coid);
-
- }
+ Object check = aIt.next();
+ if (check instanceof MappedTable){
+ MappedTable ma = (MappedTable)check;
+ int size = ma.getSize();
+ String tablePrefix = ma.getPrefix();
+ // the next size attributes in the list are part of this table.
+ for (int i = 0; i < size; i++){
+ MappedAttribute mat = (MappedAttribute)aIt.next();
+ String oid;
+ if (oidPrefix != null && tablePrefix != null){
+ oid = oidPrefix + tablePrefix + mat.getOid();
+ }
+ else{
+ oid = mat.getOid();
+ }
+ addBindEntry(oid,mmb.getName(),mat.getName(),mat.isReadWrite());
+ }
+ }
+
+ else {
+ MappedAttribute ma = (MappedAttribute)check;
+
+ String oid;
+ if (oidPrefix != null)
+ oid = oidPrefix + ma.getOid();
+ else
+ oid = ma.getOid();
+
+ addBindEntry(oid, mmb.getName(), ma.getName(),ma.isReadWrite());
+
+ }
+
+ }
}
}
+ private void addBindEntry(String oid, String mmb, String ma, boolean rw){
+ BindEntry be = new BindEntry(oid, mmb, ma);
+ be.isReadWrite = rw;
+
+ OID coid = new OID(oid);
+ if (log.isTraceEnabled())
+ log.trace("New bind entry " + be);
+ if (bindings.containsKey(coid)) {
+ log.info("Duplicate oid " + oid + SKIP_ENTRY);
+ }
+ if (mmb == null || mmb.equals(""))
+ {
+ log.info("Invalid mbean name for oid " + oid + SKIP_ENTRY);
+ }
+ if (ma == null || ma.equals(""))
+ {
+ log.info("Invalid attribute name " + ma + " for oid " + oid + SKIP_ENTRY);
+ }
+ bindings.put(coid, be);
+ oidKeys.add(coid);
+
+ }
/**
* Return the current value for the given oid
*
@@ -931,7 +955,7 @@
/** This method is used by snmpReceivedSet to reverse any changes in a
* SET PDU if an error is encountered before finishing.
*
- * @param modified HashMap containing OID,Val mappings
+ * @param modified HashSet containing OID,Val mappings
*/
private void undoSets(HashSet modified){
Iterator<VariableBinding> iter = modified.iterator();
@@ -959,6 +983,7 @@
/**
* Lookup a BindEntry 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.
*/
@@ -968,10 +993,12 @@
OID coid= new OID(oid);
//add possible oid format checking
- if (coid.last() == 0)
+ //we should not be stripping off the last number if it's 0! that's the instance identifier,
+ //and indicates that the given variable is a scalar value! (not part of a table.)
+ /*if (coid.last() == 0)
{
coid.removeLast();
- }
+ }*/
BindEntry be = (BindEntry)bindings.get(coid);
return be;
@@ -1119,9 +1146,9 @@
private final OID oid;
private ObjectName mbean;
- private Attribute attr;
+ private Attribute attr;
private String mName;
- private String aName;
+ private String aName;
private boolean isReadWrite = false;
/**
Modified: 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 2011-01-07 13:48:54 UTC (rev 110303)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java 2011-01-07 14:30:43 UTC (rev 110304)
@@ -49,14 +49,25 @@
case PDU.GET:
// TODO: this needs to catch NoSuchOidException, VariableTypeException, and EndOfMibViewException
case PDU.GETNEXT:
+ try{
response = requestHandler.snmpReceivedGet(pdu);
+ }
+ catch(Exception e){
+ log.debug("processPDU caugh Exception " + e + " in GETNEXT code.");
+ return;
+ }
break;
case PDU.GETBULK:
response = requestHandler.snmpReceivedGetBulk(pdu);
break;
case PDU.SET:
// TODO: this needs to catch NoSuchOidException, and VariableTypeException
+ try{
response = requestHandler.snmpReceivedSet(pdu);
+ }
+ catch(Exception e){
+ log.debug("processPDU caught Exception " + e + " in SET code.");
+ }
break;
default:
log.warn("Cannot process request PDU of type: " +
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedAttribute.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedAttribute.java 2011-01-07 13:48:54 UTC (rev 110303)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedAttribute.java 2011-01-07 14:30:43 UTC (rev 110304)
@@ -23,15 +23,22 @@
/**
* An attribute mapping, by default readonly.
+ * **New addition**
+ * Can now be of type Scalar or Tabular.
+ * If the type is scalar, the OID is created with 0 as the instance identifier.
+ * It may be queried normally, with a .0 suffix on the OID.
*
+ *
+ *
+ *
* @author <a href="mailto:hwr at pilhuhn.de">Heiko W. Rupp</a>
* @version $Revision$
*/
public class MappedAttribute
{
- String name;
- String oid;
- boolean isReadWrite = false;
+ private String name;
+ private String oid;
+ private boolean isReadWrite = false;
/** Attribute name */
public String getName()
Added: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedTable.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedTable.java (rev 0)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MappedTable.java 2011-01-07 14:30:43 UTC (rev 110304)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jmx.adaptor.snmp.config.attribute;
+
+/**
+ * This class denotes a Table of data.
+ * Essentially it is just a conceptual grouping of attributes into a table.
+ * This functionality can simplify retrieving certain attributes and organization of the MIB.
+ * The name can be arbitrary. It is simply a label used for organization.
+ *
+ * Tables are never writable.
+ *
+ * @author <a href="mailto:hwr at pilhuhn.de">Heiko W. Rupp</a>
+ * @version $Revision: 81038 $
+ */
+public class MappedTable
+{
+ private String name;
+ private String oidPrefix;
+ private int size;
+
+ public String getName()
+ {
+ return this.name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ // Table OID
+ public String getPrefix()
+ {
+ return this.oidPrefix;
+ }
+
+ public void setPrefix(String oid)
+ {
+ this.oidPrefix = oid;
+ }
+
+ public int getSize(){
+ return this.size;
+ }
+ public void setSize(int n){
+ this.size = n;
+ }
+
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append("[table name=").append(name);
+ buf.append(", oid=").append(oidPrefix);
+ buf.append("]");
+ return buf.toString();
+ }
+}
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java 2011-01-07 13:48:54 UTC (rev 110303)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/test/Test.java 2011-01-07 14:30:43 UTC (rev 110304)
@@ -51,9 +51,8 @@
}
public static void snmpwalk(String [] args){
PDU pdu = new PDU();
- OID treeOID = new OID (args[1]);
- OID currentOID = new OID(args[1]);
- OID endOID = new OID(args[2]);
+ Vector<PDU> pduResp = new Vector<PDU>();
+
CommunityTarget target = new CommunityTarget();
OctetString community = new OctetString("public");
@@ -64,64 +63,58 @@
target.setRetries(0);
target.setTimeout(2000);
- if (currentOID.compareTo(endOID) > 0){
- // invalid start / end OIDs.
- System.out.println("invalid oid range.");
- return;
- }
-
- pdu.setType(PDU.GETNEXT);
+ pdu.setType(PDU.GETNEXT);
- while (currentOID.compareTo(endOID)<0){
- pdu.add(new VariableBinding(currentOID));
- try {
- DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping();
- transport.listen();
- Snmp snmp = new Snmp(transport);
-
- System.out.println("Sending PDU: "+pdu);
- ResponseEvent responseEvent = snmp.send(pdu, target);
- System.out.println("response " + responseEvent.toString());
- PDU responsePDU = responseEvent.getResponse();
- if (responsePDU == null){
- System.out.println("Request timed out");
- }
- else{
- if (responsePDU.getErrorStatus()!= 0){
- System.out.println("Received error response: " + responsePDU);
- pdu.clear();
- return;
+ // initiate parallell walk.
+ for (int i = 1; i < args.length; i++){ //walk each OID.
+ OID treeOID = new OID (args[i]);
+ OID currentOID = new OID(treeOID);
+
+ // construct the PDU with all values required
+ while (currentOID.leftMostCompare(treeOID.getValue().length, treeOID)==0){
+ pdu.add(new VariableBinding(currentOID));
+ try {
+ DefaultUdpTransportMapping transport = new DefaultUdpTransportMapping();
+ transport.listen();
+ Snmp snmp = new Snmp(transport);
+
+ System.out.println("Sending PDU: "+pdu);
+ ResponseEvent responseEvent = snmp.send(pdu, target);
+ PDU responsePDU = responseEvent.getResponse();
+ if (responsePDU == null){
+ System.out.println("Request timed out");
}
-
- System.out.println("Received response "+responsePDU);
+ else{
+ if (responsePDU.getErrorStatus()!= 0){
+ System.out.println("Received error response: " + responsePDU);
+ pdu.clear();
+ return;
+ }
+ pduResp.add(new PDU(responsePDU));
+ // System.out.println("Received response "+responsePDU);
+ }
+ Vector<VariableBinding> vbs = responsePDU.getVariableBindings();
+ currentOID = vbs.get(0).getOid();
+ responsePDU = null;
+ pdu.clear();
+ } catch (UnknownHostException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (Exception e) {
+
+ System.out.println("Some Other exception!!");
+ System.out.println(e);
}
- System.out.println("Peer Address: "+responseEvent.getPeerAddress());
- Vector<VariableBinding> vbs = responsePDU.getVariableBindings();
-
- Variable retvar = vbs.get(0).getVariable();
- if (retvar == Null.endOfMibView){
- System.out.print("end of mib.");
- pdu.clear();
- return;
- }
- currentOID = vbs.get(0).getOid();
- if (currentOID == )
- responsePDU = null;
- pdu.clear();
- } catch (UnknownHostException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (Exception e) {
- System.out.println("Some Other exception!!");
- System.out.println(e);
+
}
-
-
}
+ for (PDU response : pduResp){
+ System.out.println("Results of snmpwalk: " + response);
+ }
More information about the jboss-cvs-commits
mailing list