[jboss-cvs] JBossAS SVN: r111678 - in branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp: config/notification and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jun 27 16:36:34 EDT 2011
Author: thauser at redhat.com
Date: 2011-06-27 16:36:31 -0400 (Mon, 27 Jun 2011)
New Revision: 111678
Modified:
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentService.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentServiceMBean.java
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/config/notification/Mapping.java
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/MIBGenerator.java
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/ParserAttributeBindings.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserNotificationBindings.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/AttributeMappings.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java
Log:
MIB Generator to handle wild cards. MIB generator to standalone jar. MIB Generator refactoring. some merging from mobicents adaptor
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentService.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentService.java 2011-06-27 11:07:25 UTC (rev 111677)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentService.java 2011-06-27 20:36:31 UTC (rev 111678)
@@ -105,9 +105,6 @@
/** Name of resource file containing get/set mappings */
private String requestHandlerResName = null;
- /** Path to the output MIB file */
- private String mibResName = null;
-
/** Name of the trap factory class to be utilised */
private String trapFactoryClassName = null;
@@ -660,20 +657,7 @@
this.session.addCommandResponder(responder);
}
- private void createMib() throws Exception{
- // TODO: Make the parser accept a list of InputStreams instead of just one, so that the Deployer can provide
- // useful information
- InputStream notifications = SecurityActions.getThreadContextClassLoaderResource(this.notificationMapResName);
- InputStream attributes = SecurityActions.getThreadContextClassLoaderResource(this.requestHandlerResName);
-
- Parser parser = new Parser(attributes, notifications);
- parser.parse();
- Generator generator = new Generator(mibResName, parser.getMaList(), parser.getMbList(), parser.getNmList());
- generator.writeFile();
-
- }
-
/*
* Read the users from the users.xml and add them to the usm
*/
@@ -731,8 +715,7 @@
initTransportMapping();
initSession();
addUsmUsers();
- createMib();
-
+
session.listen();
}
@@ -842,12 +825,4 @@
trapEmitter.removeNotifications(notifications);
}
-public String getMibResName(){
- return this.mibResName;
- }
-
-public void setMibResName(String mibResName){
- this.mibResName = mibResName;
- }
-
}
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentServiceMBean.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentServiceMBean.java 2011-06-27 11:07:25 UTC (rev 111677)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentServiceMBean.java 2011-06-27 20:36:31 UTC (rev 111678)
@@ -56,10 +56,6 @@
void setUsersResName(String usersResName);
String getUsersResName();
- /**The name of the output file for the MIB */
- void setMibResName(String mibResName);
- String getMibResName();
-
/** The name of the file containing the notification/trap mappings */
void setNotificationMapResName(String notificationMapResName);
String getNotificationMapResName();
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-06-27 11:07:25 UTC (rev 111677)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java 2011-06-27 20:36:31 UTC (rev 111678)
@@ -97,7 +97,7 @@
// private SortedMap bindings = null;
/** MBeanServer instance to query about BindEntry objects contained in the bindings map**/
-// private MBeanServer server = null;
+ // private MBeanServer server = null;
/**
* Create TrapFactorySupport
@@ -115,7 +115,6 @@
{
this.clock = clock;
this.trapCount = count;
-// this.bindings = bindings;
// this.server = server;
}
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/notification/Mapping.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/notification/Mapping.java 2011-06-27 11:07:25 UTC (rev 111677)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/notification/Mapping.java 2011-06-27 20:36:31 UTC (rev 111678)
@@ -21,6 +21,9 @@
*/
package org.jboss.jmx.adaptor.snmp.config.notification;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+
/**
* Simple POJO class to model XML data
*
@@ -47,98 +50,84 @@
/**
* Default CTOR
*/
- public Mapping()
- {
+ public Mapping() {
// empty
}
// Accessors/Modifiers -------------------------------------------
- public String getEnterprise()
- {
+ public String getEnterprise(){
return enterprise;
}
- public int getGeneric()
- {
+ public int getGeneric() {
return generic;
}
- public String getNotificationType()
- {
+ public String getNotificationType() {
return notificationType;
}
- public int getSpecific()
- {
+ public int getSpecific() {
return specific;
}
- public VarBindList getVarBindList()
- {
+ public VarBindList getVarBindList() {
return varBindList;
}
- public String getName(){
- return this.name;
- }
- public void setEnterprise(String enterprise)
- {
- this.enterprise = enterprise;
- }
- public void setGeneric(int generic)
- {
- this.generic = generic;
- }
-
- public void setNotificationType(String notificationType)
- {
- this.notificationType = notificationType;
- }
+ @XmlAttribute(name="enterprise")
+ public void setEnterprise(String enterprise) {
+ this.enterprise = enterprise;
+ }
- public void setSpecific(int specific)
- {
- this.specific = specific;
- }
+ @XmlAttribute(name="generic")
+ public void setGeneric(int generic) {
+ this.generic = generic;
+ }
- public void setVarBindList(VarBindList varBindList)
- {
- this.varBindList = varBindList;
- }
-
- public void setName(String name){
- this.name = name;
- }
-
- /**
- * @param inform the inform to set
- */
- public void setInform(boolean inform) {
- this.inform = inform;
- }
-
- /**
- * @return the inform
- */
- public boolean isInform() {
- return inform;
- }
-
- /**
- * @param securityName the securityName to set
- */
- public void setSecurityName(String securityName) {
- this.securityName = securityName;
- }
+ @XmlAttribute(name="notification-type")
+ public void setNotificationType(String notificationType) {
+ this.notificationType = notificationType;
+ }
- /**
- * @return the securityName
- */
- public String getSecurityName() {
- return securityName;
- }
+
+ @XmlAttribute(name="specific")
+ public void setSpecific(int specific) {
+ this.specific = specific;
+ }
+
+ @XmlElement(name="var-bind-list")
+ public void setVarBindList(VarBindList varBindList) {
+ this.varBindList = varBindList;
+ }
+
+ /**
+ * @param inform
+ * the inform to set
+ */
+ @XmlAttribute(name="inform")
+ public void setInform(boolean inform) {
+ this.inform = inform;
+ }
+
+ /**
+ * @return the inform
+ */
+ public boolean isInform() {
+ return inform;
+ }
+
+ /**
+ * @param securityName
+ * the securityName to set
+ */
+ @XmlAttribute(name="security-name")
+ public void setSecurityName(String securityName) {
+ this.securityName = securityName;
+ }
public void setOidDef(String en){
this.oidDefName = en;
@@ -147,6 +136,25 @@
public String getOidDef(){
return this.oidDefName;
}
+
+ /**
+ * @return the securityName
+ */
+ public String getSecurityName() {
+ return securityName;
+ }
+
+
+
+ public void setName(String name){
+ this.name = name;
+ }
+
+ public String getName(){
+ return this.name;
+ }
+
+
// Object overrides ----------------------------------------------
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-06-27 11:07:25 UTC (rev 111677)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Generator.java 2011-06-27 20:36:31 UTC (rev 111678)
@@ -27,13 +27,14 @@
import java.util.Iterator;
import java.util.Set;
import java.util.HashMap;
+import java.util.List;
-import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
-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.notification.Mapping;
-import org.jboss.jmx.adaptor.snmp.config.notification.VarBind;
-import org.jboss.jmx.adaptor.snmp.config.notification.VarBindList;
+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 javax.management.ObjectName;
@@ -56,10 +57,12 @@
private String outputResName; // the name of the output file (.mib or .xml)
private ArrayList<MIBObject> miboList; // internal list of MIBObjects
private ArrayList<MIBNotification> mibnList;
+ private ArrayList<MIBTable> tableList;
private ArrayList<MappedAttribute> maList; // list of Mapped Attributes we care about
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;
@@ -94,24 +97,9 @@
this.oidDefMap = new HashMap<String, OIDDef>();
this.nmList = nmList;
this.mibnList = new ArrayList<MIBNotification>();
+ this.tableList = new ArrayList<MIBTable>();
}
- /**
- * Constructor without notifications mapping. Called from MIBGenerator.
- *
- * @param outputResName the output filename
- * @param maList the list of MappedAttributes, received from the Parser.
- * @param mbList the list of ManagedBeans. This can be null if, for example, we're parsing an MIB.
- */
-
- public Generator(String outputResName, ArrayList<MappedAttribute> maList, AttributeMappings mbList){
- this.outputResName = outputResName;
- this.mbList = mbList;
- this.miboList = new ArrayList<MIBObject>();
- this.maList = maList;
- this.oidDefMap = new HashMap<String, OIDDef>();
- }
-
//mutators
public String getOutputResName(){
return this.outputResName;
@@ -153,14 +141,11 @@
public void writeFile(){
try{
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputResName)));
- createMibObjects();
- createMibNotifications();
+ createEntries();
writeMibHeader(out);
writeMibImports(out);
writeMibObjectDefinitions(out);
- writeMibObjects(out);
- //writeMibNotificationDefinitions(out);
- writeMibNotifications(out);
+ writeEntries(out);
out.println("END");
out.close();
}
@@ -224,11 +209,16 @@
* @param out
*/
- private void writeMibObjects(PrintWriter out){
- Iterator<MIBObject> aIt = miboList.iterator();
- while (aIt.hasNext()){
- out.println(aIt.next());
+ private void writeEntries(PrintWriter out){
+ for (MIBObject mibo : miboList){
+ out.println(mibo);
}
+ for (MIBNotification noti : mibnList){
+ out.println(noti);
+ }
+ for (MIBTable table : tableList){
+ out.println(table);
+ }
}
/**
@@ -236,57 +226,40 @@
* it to this instance's list of mibObjects for writing to the file.
*/
- private void createMibObjects(){
- Iterator<MappedAttribute> aIt = maList.iterator();
- while (aIt.hasNext()){
- MIBObject mibO = new MIBObject(aIt.next());
- miboList.add(mibO);
+ private void createEntries(){
+ for (MappedAttribute ma : maList){
+ miboList.add(new MIBObject(ma));
}
- }
-
- /**
- * This method generates a list of MIBNotifications from a given ArrayList of Mappings from the parser,
- * and adds it to this instance's list of MIBNotifications for writing to the file
- */
-
- private void createMibNotifications(){
- Iterator<Mapping> nIt = nmList.iterator();
- while (nIt.hasNext()){
- MIBNotification mibN = new MIBNotification(nIt.next());
- mibnList.add(mibN);
+ for(Mapping mibN : nmList){
+ mibnList.add(new MIBNotification(mibN));
}
- }
-
- /**
- * Method to write the gathered Notifications out into the MIB
- * @param out
- */
- private void writeMibNotifications(PrintWriter out){
- Iterator<MIBNotification> nIt = mibnList.iterator();
- while(nIt.hasNext()){
- out.println(nIt.next());
+ for(ManagedBean mb : mbList){
+ // we only want to make a table if the MBean's name is a wildcard.
+ ObjectName test = null;
+ try{
+ test = new ObjectName(mb.getName());
+ }catch(Exception e){}
+ if (test != null && test.isPattern()){
+ tableList.add(new MIBTable(mb));
+ }
}
- }
+ }
/* Internal Classes ----- */
-
+
/**
* Internal class used to represent a single MIB Object. Created by reading the required
* data from a MappedAttribute object, and filling in the rest.
*/
- private class MIBObject{
- private String name;
- private String syntax;
- private String maxAccess;
- private String status;
- private String description;
- private String objectId;
+ private class MIBObject extends MIBEntity{
private String fullOid;
- private String oidDef;
+ private boolean rowEntry; //internally used to avoid adding an OIDDef for a member of an entry
+
MIBObject(String name, String fullOid, String oidDefName){
+ super();
this.name = name;
this.syntax = "DisplayString";
this.maxAccess = "read-only";
@@ -305,11 +278,15 @@
setOidDef(oidPrefix, oidDefName);
}
+ MIBObject(MappedAttribute ma){
+ this(ma, false);
+ }
- MIBObject(MappedAttribute ma){
+ MIBObject(MappedAttribute ma, boolean rowEntry){
// names must begin with lowercase, or the manager complains / gives warnings
this.name = ma.getName().substring(0,1).toLowerCase() + ma.getName().substring(1);
+ this.rowEntry = rowEntry; // default value with this constructor.
//if the ma has an snmpType defined, we use that as the type. Otherwise we cannot know it, use
//the general OCTET STRING type.
if (ma.getSnmpType()!= null)
@@ -319,22 +296,24 @@
//there are more values possible here for an MIB, but not for a JMX attr; we only
//need to worry about these possibilities
- if (ma.isReadWrite())
- maxAccess = "read-write";
- else
- maxAccess = "read-only";
+ this.maxAccess = ma.getMaxAccess();
- /**
- * Possible values for STATUS ::= "current"
- * | deprecated
- * | obsolete
- * Not quite sure how these other values correspond to any meaning for JMX attributes. May
- * be worth further investigation.
- */
- this.status = "current";
+ if (this.maxAccess == null){
+ if (ma.isReadWrite())
+ maxAccess = "read-write";
+ else
+ maxAccess = "read-only";
+ }
+
+ if (ma.isIndex())
+ maxAccess = "not-accessible";
+
+ this.status = (ma.getStatus()!=null) ? ma.getStatus() : "current";
+
// perhaps have this as an optional attribute in the attributes.xml? Left as blank
// because there is no way to query the server about a given attribute
- this.description = "";
+ this.description = (ma.getSnmpDesc()!= null) ? ma.getSnmpDesc() : "";
+
String[] temp = ma.getOid().split("\\."); // this will contain the full numerical OID.
// We need the last element in the array to be the registered OID, so we can put the correct
// name in the output MIB
@@ -342,33 +321,13 @@
this.fullOid = ma.getOidPrefix()+"."+this.objectId;
// check if there is already an OID definition for this prefix. If there is make this MIBObject's
// oidDef reflect that
- setOidDef(ma.getOidPrefix(), ma.getOidDefName());
+ if (this.rowEntry)
+ this.oidDef = ma.getOidDefName();
+ else
+ setOidDef(ma.getOidPrefix(), ma.getOidDefName());
}
- public void setOidDef(String oidPrefix, String oidDefName){
- 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.
- OIDDef newOidDef = new OIDDef(oidDefName, oidPrefix);
- oidDefMap.put(oidPrefix, newOidDef);
- this.oidDef=oidDefName;
- }
- else { // everything failed. the attributes.xml doesn't specify a name for the oid definition to be used,
- // nor do we already know about it.
- OIDDef newOidDef = new OIDDef("UNKNOWN", oidPrefix);
- oidDefMap.put(oidPrefix, newOidDef);
- this.oidDef="UNKNOWN";
- }
- }
- }
-
public String getName(){
return this.name;
}
@@ -403,23 +362,18 @@
* @author <a href="mailto:tom.hauser at gmail.com>Tom Hauser
*/
- private class MIBNotification{
- private String name;
- private String status;
- private String description;
- private String oidDef;
- private String objectId;
+ private class MIBNotification extends MIBEntity{
private ArrayList<String> objects;
public MIBNotification(Mapping mp){
this.objects = new ArrayList<String>();
- if (mp.getName()!=null)
- this.name = mp.getName();
- else
- this.name = "UNDEFINED";
- this.status = "current";
- this.description = ""; // TODO: improve this!!
+ this.name = (mp.getName()!=null) ? mp.getName() : "UNDEFINED";
+
+ this.status = (mp.getStatus()!=null) ? mp.getStatus() : "current";
+
+ this.description = (mp.getDesc()!=null) ? mp.getDesc() : "";
+
ArrayList<VarBind> vbList = (ArrayList<VarBind>)mp.getVarBindList().getVarBindList();
setObjects(vbList);
// the OID of a v2 trap = <enterpriseid>.0.<specificid>
@@ -428,24 +382,7 @@
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
- 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
- else{
- if (mp.getOidDef() != null){
- // the name to be used is in the xml being parsed. use it.
- OIDDef newOidDef = new OIDDef(mp.getOidDef(),oidPrefix);
- oidDefMap.put(oidPrefix, newOidDef);
- this.oidDef=mp.getOidDef();
- }
- else { // everything failed. the attributes.xml doesn't specify a name for the oid definition to be used,
- // nor do we already know about it.
- OIDDef newOidDef = new OIDDef("UNKNOWN", oidPrefix);
- oidDefMap.put(oidPrefix, newOidDef);
- this.oidDef="UNKNOWN";
- }
- }
+ setOidDef(oidPrefix, mp.getOidDef());
}
public void setName(String name){
@@ -539,7 +476,7 @@
buf.append("\n\t\t");
buf.append("\""+this.description+"\"");
buf.append("\n");
- buf.append("::= {").append(" ");
+ buf.append("::= { ");
buf.append(this.oidDef + " " + this.objectId + " }");
buf.append("\n");
return buf.toString();
@@ -605,13 +542,192 @@
public String toString(){
StringBuffer buf = new StringBuffer();
buf.append(this.name);
- buf.append("\t\tOBJECT IDE" +
- "NTIFIER ::= ");
+ buf.append("\t\tOBJECT IDENTIFIER ::= ");
buf.append(this.definition);
return buf.toString();
}
}//end OIDDef
+ /** Internal class representing a Table entry in the MIB **/
+ private class MIBTable extends MIBEntity{
+ private String rowName;
+ private MIBTableRow row; // the row created from information contained in
+ // this MIBTable
+
+ // if we find a managedbean with a wildcard object name, we make a table
+ public MIBTable(ManagedBean mb){
+ this.name = (mb.getTableName()!=null) ? mb.getTableName() : "UNKNOWNTABLE";
+ this.maxAccess = "not-accessible";
+ String oid = mb.getOidPrefix();
+ String oidPrefix = "";
+ String [] temp = oid.split("\\.");
+ this.objectId = temp[temp.length-2];
+ for (int i = 0; i < temp.length-2; i++){
+ if (i==temp.length-3)
+ oidPrefix += temp[i];
+ else
+ oidPrefix += temp[i]+".";
+ }
+ this.description = (mb.getDesc()!=null) ? mb.getDesc() : "";
+ this.rowName = (mb.getRowName()!=null) ? mb.getRowName() : "UNKNOWNROW";
+ this.syntax = this.rowName.substring(0,1).toUpperCase() + this.rowName.substring(1);
+ this.status = (mb.getStatus()!=null) ? mb.getStatus() : "current";
+ setOidDef(oidPrefix, mb.getOidDefinition());
+ ArrayList<String>indexNames = findIndexes(mb.getAttributes());
+ row = new MIBTableRow(this.name, this.rowName, indexNames, temp[temp.length-1], (ArrayList<MappedAttribute>)mb.getAttributes());
+ }
+
+ private ArrayList<String> findIndexes(List<MappedAttribute> maList){
+ ArrayList<String> retVal = new ArrayList<String>(1);
+ for (MappedAttribute ma : maList){
+ if (ma.isIndex())
+ retVal.add(ma.getName());
+ }
+ return retVal;
+ }
+
+ @Override
+ public String toString(){
+ StringBuffer buf = new StringBuffer();
+ buf.append(this.name).append(" OBJECT-TYPE").append("\n")
+ .append("\tSYNTAX\tSEQUENCE OF ").append(this.syntax).append("\n")
+ .append("\tMAX-ACCESS\t").append(this.maxAccess).append("\n")
+ .append("\tSTATUS\t").append(this.status).append("\n")
+ .append("\tDESCRIPTION\t\n\t\t").append("\""+this.description+"\"").append("\n")
+ .append("::= { ").append(this.oidDef+" " +this.objectId+" }\n\n")
+ .append(row);
+ return buf.toString();
+ }
+
+ }
+
+ /**Internal class representing a Table Row entry in the MIB **/
+
+ private class MIBTableRow extends MIBEntity{
+ private ArrayList<String> indexes;
+ private ArrayList<MIBObject> rowObjects;
+ private String tableName;
+ private String typeName;
+
+ MIBTableRow(String tableName, String rowName, ArrayList<String> indexNames, String rowOid, ArrayList<MappedAttribute> attrList){
+ this.name = rowName;
+ this.objectId = rowOid;
+ this.tableName = tableName;
+ this.typeName = this.name.substring(0,1).toUpperCase() + this.name.substring(1);
+ this.syntax = rowName;
+ this.maxAccess = "not-accessible";
+ this.status = "current"; // doesn't make sense to define a table that is not current
+ this.description = "";
+ this.indexes = indexNames;
+ setRowObjects(attrList);
+ }
+
+ private void setRowObjects(ArrayList<MappedAttribute> attrList){
+ this.rowObjects = new ArrayList<MIBObject>(1);
+ for (MappedAttribute ma : attrList){
+ ma.setOidDefName(this.name);
+ rowObjects.add(new MIBObject(ma,true));
+
+ }
+ }
+
+ private String printIndexes(){
+ StringBuffer buf = new StringBuffer();
+ buf.append("INDEX\t{");
+ for (int i = 0; i < indexes.size(); i++){
+ if (i == indexes.size()-1) // if it's the last, we don't put a coma
+ buf.append("\t"+indexes.get(i));
+ else
+ buf.append("\t"+indexes.get(i)+",");
+ }
+ buf.append("\n}");
+ return buf.toString();
+ }
+
+ private String writeRowDefinition(){
+ StringBuffer buf = new StringBuffer();
+ buf.append(this.typeName + " ::= SEQUENCE {\n");
+ for (int i = 0; i < rowObjects.size(); i++){
+ if(i == rowObjects.size()-1)
+ buf.append("\t"+rowObjects.get(i).getName()+"\t"+rowObjects.get(i).getSyntax());
+ else
+ buf.append("\t"+rowObjects.get(i).getName()+"\t"+rowObjects.get(i).getSyntax()+",\n");
+ }
+ buf.append("\n}\n");
+ return buf.toString();
+ }
+
+ @Override
+ public String toString(){
+ StringBuffer buf = new StringBuffer();
+ buf.append(this.name) .append(" OBJECT-TYPE") .append("\n")
+ .append("\tSYNTAX\t") .append(this.typeName) .append("\n")
+ .append("\tMAX-ACCESS\t") .append(this.maxAccess) .append("\n")
+ .append("\tSTATUS\t") .append(this.status) .append("\n")
+ .append("\tDESCRIPTION\n\t").append("\""+this.description+"\"\n")
+ .append("\t").append(printIndexes()) .append("\n")
+ .append("::= { ").append(this.tableName).append(" "+this.objectId)
+ .append(" }\t\t\n\n");
+ buf.append(writeRowDefinition()+"\n");
+ // print the rest of the objects
+ for (MIBObject object : rowObjects){
+ buf.append(object).append("\n");
+ }
+ return buf.toString();
+ }
+
+ }
+
+ /** Abstract class containing all the different common fields of an entry in the MIB **/
+ private abstract class MIBEntity{
+ String name;
+ String syntax;
+ String maxAccess;
+ String status;
+ String description;
+ String oidDef;
+ String objectId;
+
+ MIBEntity(){
+ name="";
+ syntax="";
+ maxAccess="";
+ status="";
+ description="";
+ oidDef="";
+ objectId="";
+ }
+
+ public String getSyntax(){
+ return this.syntax;
+ }
+
+ public abstract String toString();
+
+ public void setOidDef(String oidPrefix, String oidDefName){
+ 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.
+ OIDDef newOidDef = new OIDDef(oidDefName, oidPrefix);
+ oidDefMap.put(oidPrefix, newOidDef);
+ this.oidDef=oidDefName;
+ }
+ else { // everything failed. the attributes.xml doesn't specify a name for the oid definition to be used,
+ // nor do we already know about it.
+ OIDDef newOidDef = new OIDDef("UNKNOWN", oidPrefix);
+ oidDefMap.put(oidPrefix, newOidDef);
+ this.oidDef="UNKNOWN";
+ }
+ }
+ }
+ }
+
}// end MIB Generator
\ No newline at end of file
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java 2011-06-27 11:07:25 UTC (rev 111677)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/MIBGenerator.java 2011-06-27 20:36:31 UTC (rev 111678)
@@ -45,20 +45,19 @@
*/
public static void main (String [] args){
CmdLineParser cmdParser = new CmdLineParser();
+ Parser parser = new Parser();
/*
* Adds the desired options to the command line parser.
* Options:
* -h , --help : display the usage information
- * -r , --reverse : convert an MIB into an XML, as opposed to XML into MIB
- * -s , --snmptype : preserve snmp types gleaned from parsing the MIB. (only usable with -r)
- * -a , --append : do not overwrite the existing MIB; instead, add the newly parsed attributes to it.
- * --import=<FILENAME> : add the import entries contained in the file to the MIB named by FILENAME to the produced MIB (valid only for xml -> mib)
- * --oiddef=<FILENAME> : add the OID definitions in the given file to the generator
+ * -a , --attributes : indicate the name of attributes.xml, if any
+ * -n , --notifications : indicate the name of the notification.xml file, if any.
+ * -m , --mib : indicate the desired name of the MIB file. this can be a path.
*/
CmdLineParser.Option help = cmdParser.addBooleanOption('h', "help");
- CmdLineParser.Option append = cmdParser.addBooleanOption('a', "append");
- CmdLineParser.Option importOpt = cmdParser.addStringOption('i', "import");
- CmdLineParser.Option oiddef = cmdParser.addStringOption('o', "oiddef");
+ CmdLineParser.Option attributes = cmdParser.addStringOption('a', "attributes");
+ CmdLineParser.Option notifications = cmdParser.addStringOption('n', "notifications");
+ CmdLineParser.Option mib = cmdParser.addStringOption('m', "mib");
try {
cmdParser.parse(args);
@@ -66,17 +65,37 @@
catch (Exception e){
printUsageMessage();
}
+ Boolean isHelp = (Boolean)cmdParser.getOptionValue(help, Boolean.FALSE);
+ String aFile = (String)cmdParser.getOptionValue(attributes);
+ String nFile = (String)cmdParser.getOptionValue(notifications);
+ String mibFile = (String)cmdParser.getOptionValue(mib);
- String [] remArgs = cmdParser.getRemainingArgs();
- Parser parser = new Parser(remArgs[0], remArgs[1]);
+ if (isHelp){
+ printUsageMessage();
+ System.exit(0);
+ }
+
+ if (aFile != null && nFile != null){
+ parser = new Parser(aFile, nFile);
+ }
+ else if (aFile != null){
+ parser = new Parser(aFile);
+ }
+ else if (nFile != null){
+ parser = new Parser(nFile);
+ }
parser.parse();
- Generator generator = new Generator(remArgs[2], parser.getMaList(), parser.getMbList(), parser.getNmList());
+ Generator generator = new Generator(mibFile, parser.getMaList(), parser.getMbList(), parser.getNmList());
generator.writeFile();
}
- private static String printUsageMessage(){
- return "";
+ private static void printUsageMessage(){
+ System.out.println("Usage: java -jar jboss-as-varia-mib-generator [OPTION] [FILENAME] .. [OPTION] [FILENAME].." +
+ "OPTION:\n-h , --help : display the usage information" +
+ "-a , --attributes : indicate the name of attributes.xml, if any" +
+ "-n , --notifications : indicate the name of the notification.xml file, if any." +
+ "-m , --mib : indicate the desired name of the MIB file. this can be a path.");
}
}
\ No newline at end of file
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-06-27 11:07:25 UTC (rev 111677)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/Parser.java 2011-06-27 20:36:31 UTC (rev 111678)
@@ -27,12 +27,15 @@
import java.util.Iterator;
import java.util.List;
+import javax.management.ObjectName;
-import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
-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.notification.Mapping;
+
+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.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
@@ -57,16 +60,10 @@
ArrayList<Mapping> nmList;//list of notifications that we care about.
AttributeMappings mbList;
- public Parser(InputStream aIs, InputStream nIs){
- this.inputAttrFile = null;
- this.inputNotificationFile = null;
- this.inputAttrStream = aIs;
- this.inputNotiStream = nIs;
- this.maList = new ArrayList<MappedAttribute>(1);
- this.mbList = new AttributeMappings();
- this.nmList = new ArrayList<Mapping>(1);
+ public Parser(){
+
}
-
+
// constructor with a single input file; simple, just parse this one file.
public Parser(String inputAttrFile){
this.inputAttrFile = inputAttrFile;
@@ -198,7 +195,8 @@
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
// let JBossXB do it's magic using the AttributeMappingsBinding
- mappings = (AttributeMappings)unmarshaller.unmarshal(is, omf, null);
+ mappings = (AttributeMappings)unmarshaller.unmarshal(is, omf, null);
+ setMbList(mappings);
}
catch (Exception e){
throw e;
@@ -223,25 +221,33 @@
Iterator it = mappings.iterator();
while (it.hasNext()){
ManagedBean mmb = (ManagedBean)it.next();
- String oidPrefix = mmb.getOidPrefix();
- String oidDefName = mmb.getOidDefinition();
- List attrs = mmb.getAttributes();
- Iterator aIt = attrs.iterator();
- while (aIt.hasNext()){
- Object check = aIt.next();
-
- MappedAttribute ma = (MappedAttribute)check;
-
- if (oidPrefix != null)
- ma.setOidPrefix(oidPrefix);
- else
- ma.setOidPrefix(removeLast(ma.getOid()));
-
- ma.setOidDefName(oidDefName);
-
- // for the MIB Generator
- ma.setMbean(mmb.getName());
- maList.add(ma);
+ String mbeanName = mmb.getName();
+ ObjectName test = null;
+ try {
+ test = new ObjectName(mbeanName);
+ } catch (Exception e) {}
+
+ if(!test.isPattern()){
+ String oidPrefix = mmb.getOidPrefix();
+ String oidDefName = mmb.getOidDefinition();
+ List attrs = mmb.getAttributes();
+ Iterator aIt = attrs.iterator();
+ while (aIt.hasNext()){
+ Object check = aIt.next();
+
+ MappedAttribute ma = (MappedAttribute)check;
+
+ if (oidPrefix != null)
+ ma.setOidPrefix(oidPrefix);
+ else
+ ma.setOidPrefix(removeLast(ma.getOid()));
+
+ ma.setOidDefName(oidDefName);
+
+ // for the MIB Generator
+ ma.setMbean(mmb.getName());
+ maList.add(ma);
+ }
}
}
}//end parseXml
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserAttributeBindings.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserAttributeBindings.java 2011-06-27 11:07:25 UTC (rev 111677)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserAttributeBindings.java 2011-06-27 20:36:31 UTC (rev 111678)
@@ -23,9 +23,9 @@
import java.util.ArrayList;
-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.generator.metrics.MappedAttribute;
+import org.jboss.jmx.adaptor.snmp.generator.metrics.AttributeMappings;
+import org.jboss.jmx.adaptor.snmp.generator.metrics.ManagedBean;
import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.UnmarshallingContext;
import org.xml.sax.Attributes;
@@ -69,10 +69,18 @@
String name = attrs.getValue("name");
String oidPrefix = attrs.getValue("oid-prefix");
String oidDefinition = attrs.getValue("definition-name");
+ String tableName = attrs.getValue("table-name");
+ String rowName = attrs.getValue("row-name");
+ String desc = attrs.getValue("description");
+ String status = attrs.getValue("status");
ManagedBean child = new ManagedBean();
child.setName(name);
child.setOidPrefix(oidPrefix);
- child.setOidDefinition(oidDefinition);// the name of the oid definition to put into the mib
+ child.setOidDefinition(oidDefinition);
+ child.setTableName(tableName);
+ child.setRowName(rowName);
+ child.setDesc(desc);
+ child.setStatus(status);
return child;
}
return null;
@@ -90,15 +98,24 @@
MappedAttribute attribute = null;
if ("attribute".equals(localName)) {
+ String name = attrs.getValue("name");
String oid = attrs.getValue("oid");
- String name = attrs.getValue("name");
String mode = attrs.getValue("mode");
String snmpType = attrs.getValue("snmp-type");
+ String maxAccess = attrs.getValue("max-access");
+ String desc = attrs.getValue("description");
+ String status = attrs.getValue("status");
+ String indexCheck = attrs.getValue("index");
attribute = new MappedAttribute();
- attribute.setMode(mode);
- attribute.setName(name);
+ attribute.setName(name);
attribute.setOid(oid);
+ attribute.setMode(mode);
attribute.setSnmpType(snmpType);
+ attribute.setMaxAccess(maxAccess);
+ attribute.setSnmpDesc(desc);
+ attribute.setStatus(status);
+ boolean index = (indexCheck != null)? (indexCheck.equalsIgnoreCase("true")) : false;
+ attribute.setIsIndex(index);
}
return attribute;
}
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserNotificationBindings.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserNotificationBindings.java 2011-06-27 11:07:25 UTC (rev 111677)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/ParserNotificationBindings.java 2011-06-27 20:36:31 UTC (rev 111678)
@@ -23,9 +23,9 @@
import java.util.ArrayList;
-import org.jboss.jmx.adaptor.snmp.config.notification.Mapping;
-import org.jboss.jmx.adaptor.snmp.config.notification.VarBind;
-import org.jboss.jmx.adaptor.snmp.config.notification.VarBindList;
+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.xb.binding.GenericObjectModelFactory;
import org.jboss.xb.binding.UnmarshallingContext;
import org.xml.sax.Attributes;
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/AttributeMappings.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/AttributeMappings.java 2011-06-27 11:07:25 UTC (rev 111677)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/AttributeMappings.java 2011-06-27 20:36:31 UTC (rev 111678)
@@ -19,7 +19,7 @@
* 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;
+package org.jboss.jmx.adaptor.snmp.generator.metrics;
import java.util.ArrayList;
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java 2011-06-27 11:07:25 UTC (rev 111677)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/generator/metrics/MappedAttribute.java 2011-06-27 20:36:31 UTC (rev 111678)
@@ -40,7 +40,7 @@
private String oidPrefix = ""; // all of these metrics are useful in the MIB Generator
private String oidDefName = "";
private String maxAccess = "";
- private String snmpDescription = "";
+ private String description = "";
private String status = "";
private boolean isIndex = false;
More information about the jboss-cvs-commits
mailing list