[jboss-cvs] JBossAS SVN: r111780 - branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 19 16:45:56 EDT 2011


Author: thauser at redhat.com
Date: 2011-07-19 16:45:56 -0400 (Tue, 19 Jul 2011)
New Revision: 111780

Modified:
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java
Log:
fix dealing with Notification generation

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java	2011-07-19 11:56:24 UTC (rev 111779)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java	2011-07-19 20:45:56 UTC (rev 111780)
@@ -27,22 +27,17 @@
 import java.util.Iterator;
 import java.util.Set;
 import java.util.HashMap;
-import java.util.List;
 
 import org.jboss.jmx.adaptor.snmp.generator.metrics.MappedAttribute;
 import org.jboss.jmx.adaptor.snmp.generator.metrics.AttributeMappings;
 import org.jboss.jmx.adaptor.snmp.generator.metrics.ManagedBean;
 import org.jboss.jmx.adaptor.snmp.generator.metrics.Mapping;
 import org.jboss.jmx.adaptor.snmp.generator.metrics.VarBind;
-import org.jboss.jmx.adaptor.snmp.generator.metrics.VarBindList;
+import org.jboss.jmx.adaptor.snmp.generator.exceptions.NotEnoughInformationException;
 
 import javax.management.ObjectName;
 
-import org.snmp4j.smi.TimeTicks;
-import org.snmp4j.smi.Counter32;
-import org.snmp4j.smi.OID;
 
-
 /** 
 * This class will be able to generate MIBs or XMLs, depending on the invocation by the user. 
 * It will utilize mibble libraries to parse MIBs to generate xmls from them, and will use 
@@ -63,12 +58,9 @@
 	private ArrayList<Mapping> nmList; // list of notification mappings we care about
 	private ArrayList<VarBind> vbList;
 	private AttributeMappings mbList;
-
-	//private MBeanServer server; // used when this class is created in the snmp-adaptor itself
 	
 	private HashMap<String, OIDDef> oidDefMap;	
 
-	
 	/** 
 	 * Default constructor. Nulls all around.
 	 */
@@ -80,8 +72,6 @@
 		this.maList = null;
 	}
 	
-	
-	
 	/**
 	 * Constructor for use when also parsing Notifications.xml
 	 * @param outputResName the output filename
@@ -160,7 +150,7 @@
 	}
 	
 	/**
-	 * Simple class that writes the header to the MIB file.  
+	 * Simple method that writes the header to the MIB file.  
 	 * TODO: make the name JBOSS-AS-MIB configurable.
 	 * @param out the PrintWriter to output to.
 	 */
@@ -174,7 +164,7 @@
 	}
 	
 	/**
-	 * Another simple class that outputs the Imports of the generated MIB.
+	 * Another simple method that outputs the Imports of the generated MIB.
 	 * The current imports will be recognized by any standard snmp tool (notably net-snmp)
 	 * TODO: Make these imports configurable. 
 	 * @param out
@@ -212,7 +202,7 @@
 	}
 	
 	/**
-	 * Outputs all of the objects in miboList to the outputFile.
+	 * Outputs all of the objects to the output file
 	 * @param out
 	 */
 	
@@ -287,7 +277,7 @@
 			for(Mapping nm : nmList){
 				try{
 					MIBNotification mibN = new MIBNotification(nm);
-					mibnList.add(new MIBNotification(nm));
+					mibnList.add(mibN);
 				}
 				catch (NotEnoughInformationException e){
 					System.err.println(e.getMessage());
@@ -329,7 +319,6 @@
 				else
 					oidPrefix+=temp[i]+".";
 			}
-			this.fullOid = fullOid;
 			setOidDef(oidPrefix, null);
 
 
@@ -432,7 +421,7 @@
 				setObjects(vbList);
 				// the OID of a v2 trap = <enterpriseid>.0.<specificid>
 				// for predefined traps, see RFC1907 / 3413 / 3418 / http://www.oid-info.com/get/1.3.6.1.6.3.13
-				String oidPrefix = mp.getEnterprise()+".0";
+				String oidPrefix = mp.getEnterprise()+"."+String.valueOf(mp.getGeneric());
 				this.objectId = String.valueOf(mp.getSpecific());
 				// check if there is already an OID definition for this prefix. If there is make this MIBObject's 
 				// oidDef reflect that
@@ -440,30 +429,14 @@
 
 			}
 			
-			public void setName(String name){
-				this.name = name;
-			}
-			
-			public String getName(){
-				return this.name;
-			}
-			
-			public void setDescription(String description){
-				this.description = description;
-			}
-			
-			public String getDescription(){
-				return this.description;
-			}
-			
 			public void setObjects(ArrayList<VarBind> vbList) throws NotEnoughInformationException{
 				// there are special conditions in this section that we need to account for, and 
 				// define more MIBObjects. They are all of the n:tags and u:tags
 				// more changes need to be done 
-				Iterator vbIt = vbList.iterator();
+				Iterator<VarBind>vbIt = vbList.iterator();
 				ArrayList<String> oids = new ArrayList<String>(10);
 				while(vbIt.hasNext()){
-					VarBind vb = (VarBind)vbIt.next();
+					VarBind vb = vbIt.next();
 					oids.add(vb.getOid());			
 					if (vb.getTag().matches("^n:.*") || vb.getTag().matches("^u:.*")){
 						createNotifPayloadMibo(vb);
@@ -498,11 +471,7 @@
 				// maybe better way to glean it
 				miboList.add(new MIBObject(name,vb));
 			}
-			
-			public ArrayList<String> getObjects(){
-				return this.objects;
-			}
-			
+						
 			public String printObjects(){
 				StringBuffer buf = new StringBuffer();
 				buf.append("{\n");
@@ -513,7 +482,7 @@
 						buf.append("\t\t"+this.objects.get(index)).append(",\n");
 				}
 				
-				buf.append("\n}\n");
+				buf.append("\n\t\t}\n");
 				return buf.toString();
 			
 			}
@@ -557,15 +526,7 @@
 			public String getName(){
 				return this.name;	
 			}
-			
-			public void setName(String name){
-				this.name = name;
-			}
-			
-			public String getDefinition(){
-				return this.definition;
-			}
-			 
+
 			public void setDefinition(){
 				String temp = "{ ";
 				temp += this.rawOid;
@@ -578,10 +539,6 @@
 				this.rawOid = replaceDottedOid(tokens).trim()+ " ";		
 			}
 			
-			public String getRawOid(){
-				return this.rawOid;
-			}
-			
 			private String replaceDottedOid(String [] tokens){
 				String temp = "";
 				for (int i = 0; i < tokens.length; i++){
@@ -598,6 +555,21 @@
 				buf.append(this.definition);
 				return buf.toString();
 			}
+			
+			@Override
+			public boolean equals(Object o){
+				if (this == o){
+					return true;
+				}
+				
+				if (o == null){
+					return false;
+				}
+				
+				OIDDef that = (OIDDef) o;
+				
+				return (this.rawOid == that.rawOid);
+			}
 		}//end OIDDef
 	
 
@@ -612,14 +584,25 @@
 				this.tablePrefix=ma.getName().substring(0,1).toLowerCase() + ma.getName().substring(1);
 				this.name = this.tablePrefix+"Table";
 				this.maxAccess = "not-accessible";
-				String [] temp = ma.getOid().split("\\.");
-				this.objectId = temp[temp.length-1];
+
 				this.description = (ma.getSnmpDesc()!=null) ? ma.getSnmpDesc() : "";
 				this.rowName = this.tablePrefix+"Entry";
 				this.syntax = this.rowName.substring(0,1).toUpperCase() + this.rowName.substring(1);
 				this.status = (ma.getStatus()!=null) ? ma.getStatus() : "current";
 				setOidDef(ma.getOidPrefix(), ma.getOidDefName());
-				row = new MIBTableRow(this.name, this.tablePrefix, this.rowName, "1", ma.getMode());
+				String [] temp = ma.getOid().split("\\.");
+				// TODO: make this more elegant. 
+							
+				// HACKS::
+				if (temp.length == 3){ // .x.y, .x == TableOid, .y = RowOid
+					this.objectId = temp[1];
+					row = new MIBTableRow(this.name, this.tablePrefix, this.rowName, temp[2], ma.getMode());
+				}
+				else{
+					this.objectId = temp[temp.length-1];
+					row = new MIBTableRow(this.name, this.tablePrefix, this.rowName, "1", ma.getMode());
+				}
+				
 			}
 			
 			
@@ -627,13 +610,13 @@
 			public MIBTable(ManagedBean mb) throws NotEnoughInformationException{
 				this.tablePrefix = mb.getTableName();
 				if (this.tablePrefix == null){
-					throw new NotEnoughInformationException("The mbean "+mb.getName()+" has no table-name attribute defined. Cannot create table definition.");
+					throw new NotEnoughInformationException("The mbean "+mb.getName()+" has no table-name attribute defined. MIB Generation failed.");
 				}
 				this.name = this.tablePrefix+"Table";
 				this.maxAccess = "not-accessible";
 				String oid = mb.getOidPrefix();
 				if (oid == null){
-					throw new NotEnoughInformationException("The mbean "+mb.getName()+" has no oid-prefix attribute defined. Cannot create table definition.");
+					throw new NotEnoughInformationException("The mbean "+mb.getName()+" has no oid-prefix attribute defined. MIB Generation failed.");
 				}
 				String oidPrefix = "";
 				String [] temp = oid.split("\\.");
@@ -641,7 +624,9 @@
 				for (int i = 0; i < temp.length-2; i++){
 					if (i==temp.length-3)
 						oidPrefix += temp[i];
-					else 
+					else if (temp[i].equals("."))
+						continue;
+					else
 						oidPrefix += temp[i]+".";
 				}
 				this.description = (mb.getDesc()!=null) ? mb.getDesc() : "";
@@ -816,9 +801,6 @@
 				if (oidDefMap.containsKey(oidPrefix)){
 					this.oidDef = oidDefMap.get(oidPrefix).getName();
 				}
-				// if they aren't part of the Map, then we add them to the map with a filler name "CHANGE-ME"
-				// as there is no way to glean this name from the attributes.xml without 
-				// complexifying it
 				else{
 					if (oidDefName != null){
 						// the name to be used is in the attributes.xml. use it.

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java	2011-07-19 11:56:24 UTC (rev 111779)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java	2011-07-19 20:45:56 UTC (rev 111780)
@@ -118,13 +118,13 @@
 				parseAttributesXml();
 			}
 			else
-				System.err.println("No attributes file indicated, skipping.");
+				System.out.println("Parser: No attributes file indicated, skipping.");
 			
 			if (this.inputNotificationFile != null){
 				parseNotificationsXml();
 			}
 			else 
-				System.err.println("No notifications file indicated, skipping;");
+				System.out.println("Parser: No notifications file indicated, skipping;");
 		}
 		catch (Exception e){
 			e.printStackTrace();
@@ -147,11 +147,11 @@
 			mappings = (ArrayList)unmarshaller.unmarshal(is,omf,null);
 		}
 		catch (NoClassDefFoundError e){
-			System.err.println("The notifications file is not formatted correctly: '"+this.inputNotificationFile+"'");
+			System.err.println("Parser: The notifications file is not formatted correctly: '"+this.inputNotificationFile+"'");
 			System.exit(1);
 		}
 		catch (FileNotFoundException e){
-			System.err.println("Filename given for notifications does not exist: '"+this.inputNotificationFile+"'");
+			System.err.println("Parser: Filename given for notifications does not exist: '"+this.inputNotificationFile+"'");
 			System.exit(1);
 		}
 		catch (Exception e){
@@ -201,11 +201,11 @@
 		   setMbList(mappings);
 		}
 		catch (NoClassDefFoundError e){
-			System.err.println("The attributes file is not formatted correctly: '"+this.inputAttrFile+"'");
+			System.err.println("Parser: The attributes file is not formatted correctly: '"+this.inputAttrFile+"'");
 			System.exit(1);
 		}
 		catch (FileNotFoundException e){
-			System.err.println("Filename given for attributes.xml does not exist: '"+this.inputAttrFile+"'");
+			System.err.println("Parser: Filename given for attributes.xml does not exist: '"+this.inputAttrFile+"'");
 			System.exit(1);
 		}
 		catch (Exception e){
@@ -225,7 +225,7 @@
 		   return;         
 		}
 			/**
-			 * We have the MBeans now. Put them into the bindungs.
+			 * We have the MBeans now. Put them into the bindings.
 			 */
 
 		 Iterator it = mappings.iterator();
@@ -238,7 +238,7 @@
 			   } catch (Exception e) {}
 			   
 			   if (test == null){
-				   System.err.println("The mbeanName '"+mbeanName+"' could not be converted to an ObjectName. MIB generation failed.");
+				   System.err.println("Parser: The mbeanName '"+mbeanName+"' could not be converted to an ObjectName. MIB generation failed.");
 				   System.exit(1);
 			   }
 			   
@@ -256,7 +256,7 @@
 						  ma.setOidPrefix(oidPrefix);
 					  else{
 						  ma.setOidPrefix(removeLast(ma.getOid()));
-						  ma.setOid(getLast(ma.getOid()));
+						  ma.setOid("."+getLast(ma.getOid()));
 					  }
 					  
 					  ma.setOidDefName(oidDefName);
@@ -267,7 +267,7 @@
 						  maList.add(ma); 
 					  }
 					  else{
-						  System.err.println("The attribute '"+ma.getName()+"' is defined using a duplicated OID. MIB generation failed.");
+						  System.err.println("Parser: The attribute '"+ma.getName()+"' is defined using a duplicated OID. MIB generation failed.");
 						  System.exit(1);
 					  }
 			  }



More information about the jboss-cvs-commits mailing list