[jboss-cvs] JBossAS SVN: r111544 - branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 7 15:14:08 EDT 2011
Author: thauser at redhat.com
Date: 2011-06-07 15:14:08 -0400 (Tue, 07 Jun 2011)
New Revision: 111544
Removed:
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MIBGenerator.java
Log:
move MIBGenerator to it's own dir
Deleted: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MIBGenerator.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MIBGenerator.java 2011-06-07 19:13:51 UTC (rev 111543)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MIBGenerator.java 2011-06-07 19:14:08 UTC (rev 111544)
@@ -1,383 +0,0 @@
-/*
- * 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;
-
-
-import java.io.*;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-import java.util.HashMap;
-
-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 javax.management.MBeanAttributeInfo;
-import javax.management.MBeanServer;
-import javax.management.MBeanServerConnection;
-import javax.management.MBeanInfo;
-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
-* objects gathered from the parsing of XMLs to generate MIBs. Types are determined by either an
-* attribute in the attributes.xml (snmp-type), or, if missing, a check on the attribute's type after
-* querying the server.
-*
-*
-* @author <a href="mailto:tom.hauser at gmail.com">Tom Hauser</a>
-**/
-
-public class MIBGenerator {
- private String outputResName; // the name of the output file (.mib or .xml)
- private AttributeMappings mbList;
- private ArrayList<MIBObject> miboList; //internal list of MIBObjects
- private MBeanServer server; // reference to the MBeanServer, which we will use to query attribute types and other such things
- private ArrayList<MappedAttribute> maList;
- private HashMap<String, OIDDef> oidDefMap;
-
- // need some way to prevent collisions
-
-
- public MIBGenerator(){
- this.outputResName = null;
- this.mbList = null;
- this.miboList = null;
- this.maList = null;
- }
-
- public MIBGenerator(String outputResName, ArrayList<MappedAttribute> maList, AttributeMappings mbList, MBeanServer server){
- this.outputResName = outputResName;
- this.mbList = mbList;
- this.miboList = new ArrayList<MIBObject>();
- this.maList = maList;
- this.server = server;
- this.oidDefMap = new HashMap<String, OIDDef>();
-
- }
-
- //mutators
- public String getOutputResName(){
- return this.outputResName;
- }
-
- public void setOutputResName(String outputResName){
- this.outputResName = outputResName;
- }
-
- public ArrayList<MappedAttribute> getMaList(){
- return this.maList;
- }
-
- public void setMaList(ArrayList<MappedAttribute> maList){
- this.maList = maList;
- }
-
- public AttributeMappings getMbList(){
- return this.mbList;
- }
-
- public void setMbList(AttributeMappings mbList){
- this.mbList = mbList;
- }
-
- public MBeanServer getMBeanServer(){
- return this.server;
- }
-
- public void setMBeanServer(MBeanServer server){
- this.server = server;
- }
-
- public HashMap<String, OIDDef> getOidDefMap(){
- return this.oidDefMap;
- }
-
- public void setOidDefMap(HashMap<String, OIDDef> oidDefMap){
- this.oidDefMap = oidDefMap;
- }
- //we're done gathering attributes. write the MIB.
- public void writeFile(){
- try{
- PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputResName)));
- if (outputResName.contains(".mib")){
- createMibObjects();
- createOidDefinitions();
- writeMibHeader(out);
- writeMibImports(out);
- writeMibDefinitions(out);
- writeMibObjects(out);
- }
- else if (outputResName.contains(".xml")){
- writeXmlHeader(out);
- writeXmlDefinitions(out);
- }
- out.close();
- }
- catch (Exception e){e.printStackTrace();}
- }
-
-
- private void writeMibHeader(PrintWriter out){
- out.println("-- This MIB Generated by the SNMP MIB Generator");
- out.println();
- out.println("JBOSS-AS-MIB DEFINITIONS ::=BEGIN");
- out.println();
- // maybe add more here, if notrrayList we don't need this to be a seperate method.
- }
-
- private void writeMibImports(PrintWriter out){
- out.println("IMPORTS");
- out.println("\tOBJECT-TYPE,");
- out.println("\tNOTIFICATION-TYPE,");
- out.println("\tCounter32,");
- out.println("\tGauge32,");
- out.println("\tCounter64,");
- out.println("\tTimeTicks");
- out.println("\t\tFROM SNMPv2-SMI");
- out.println("\tDisplayString,");
- out.println("\tTruthValue");
- out.println("\t\tFROM SNMPv2-TC;");
- out.println();
- }
-
- /** This method is used to write the definitions of our SYNTAX inside the JBoss MIB
- * For use when we figure out what OIDs we want our metrics to be.
- * @param attrList list of MBeans that we're interested in
- * @param out The PrintWriter that writes to the file we need it to
- * @author Tom Hauser
- */
- private void writeMibDefinitions(PrintWriter out){
- /*org OBJECT IDENTIFIER ::= { iso 3 }
- dod OBJECT IDENTIFIER ::= { org 6 }
- internet OBJECT IDENTIFIER ::= { dod 1 }
-
- private OBJECT IDENTIFIER ::= { internet 4 }
- enterprise OBJECT IDENTIFIER ::= { private 1 }
- redhat OBJECT IDENTIFIER ::= { enterprise 2312 }
- jboss OBJECT IDENTIFIER ::= { redhat 100 }
- as OBJECT IDENTIFIER ::= { jboss 1 }*/
- Iterator<OIDDef> oidIt = oidDefMap.iterator();
- while (oidIt.hasNext()){
- out.println(oidIt.next());
- }
- }
-
- private void writeMibObjects(PrintWriter out){
- Iterator<MIBObject> aIt = miboList.iterator();
- while (aIt.hasNext()){
- out.println(aIt.next());
- }
- out.println("END");
- }
-
- private void createMibObjects(){
- Iterator<MappedAttribute> aIt = maList.iterator();
- while (aIt.hasNext()){
- MIBObject mibO = new MIBObject(aIt.next());
- miboList.add(mibO);
- }
- }
-
- private void createOidDefinitions(){
- // expansion: make a way to discover these, rather than hardcoding them.
- // suggestion: add a map of oid-prefixes from the attributes.xml and create OIDDefs out of those.
- // then how do we get names? :(
- // create ones we know about first
- String as = "1.3.6.1.4.1.2312.100.1";
- String system = "1.3.6.1.2.1.1";
- OIDDef jbossas = new OIDDef("as", as);
- OIDDef mib2system = new OIDDef("system", system);
- this.oidDefMap.put(as, jbossas);
- this.oidDefMap.put(system, mib2system);
- }
-
- private void writeXmlHeader(PrintWriter out){}
- private void writeXmlDefinitions(PrintWriter out){}
- /* Internal Classes ----- */
-
-// private class MIBNotification{
-// MIBNotification(){} // this will model a NOTIFICATION-TYPE for the generated MIB
-// }
-
- private class MIBObject{
- private String name;
- private String syntax;
- private String maxAccess;
- private String status;
- private String description;
- private String objectId;
- private OIDDef oidDef;
-
- //need to modify the information saved in mapped attribute maybe.
- //or just make a new class to hold this info in, instead of an internal one.
- //we need to get the information out of the MappedAttribute and format it
- //correctly for use in an MIB.
-
- MIBObject(MappedAttribute ma){
- this.name = ma.getName().substring(0,1).toLowerCase() + ma.getName().substring(1);
-
- if (ma.getSnmpType()!= null)
- this.syntax = ma.getSnmpType();
- else
- this.syntax = findType(ma);
-
- if (ma.isReadWrite()) // since we only have "rw" and "ro", this needs expansion.
- maxAccess = "read-write";
- else
- maxAccess = "read-only";
-
- this.status = "current";
- this.description = "";
- this.objectId = ma.getOid(); // this will contain the full numerical OID.
-
- if (oidDefMap.containsKey(ma.getOidPrefix())){
- this.oidDef = oidDefMap.get(oidDefMap.get(ma.getOidPrefix()));
- }
- //we don't ever want this to fail :(
- else{
- OIDDef newOidDef = new OIDDef("unknown", ma.getOidPrefix());
- oidDefMap.put(ma.getOidPrefix(), newOidDef);
- }
- }
-
- public String findType(MappedAttribute ma){
- Object o = null;
- try{
- o = server.getAttribute(new ObjectName(ma.getMbean()), ma.getName());
- }catch (Exception e){e.printStackTrace();}
-
- if (o instanceof Long){
- return "DisplayString";
- }
- else if (o instanceof String){
- return "DisplayString";
- }
- else if (o instanceof Integer){
- return "INTEGER";
- }
- else if (o instanceof OID){
- return "OBJECT IDENTIFIER";
- }
- else if (o instanceof TimeTicks){
- return "TimeTicks";
- }
- else if (o instanceof Counter32){
- return "Counter32";
- }
- else{
- return "OCTET STRING (SIZE(0..255))";
- }
- }
-
- @Override
- public String toString(){
- StringBuffer buf = new StringBuffer();
- buf.append(this.name+" OBJECT-TYPE\n");
- buf.append("\tSYNTAX ").append(this.syntax);
- buf.append("\n");
- buf.append("\tACCESS ").append(this.maxAccess);
- buf.append("\n");
- buf.append("\tSTATUS ").append(this.status);
- buf.append("\n");
- buf.append("\tDESCRIPTION ");
- buf.append("\n\t\t");
- buf.append("\""+this.description+"\"");
- buf.append("\n");
- buf.append("::= {").append(" ");
- buf.append("as " + objectId.charAt(1)+ " }");
- buf.append("\n");
- return buf.toString();
- }
- }
-
- private class OIDDef{
- private String name;
- private String definition;
- private String rawOid;
-
- public OIDDef(String name, String oid){
- this.name = name;
- this.rawOid = oid;
- this.definition = parseDefinition(oid);
- }
-
- public String getName(){
- return this.name;
- }
-
- public void setName(String name){
- this.name = name;
- }
-
- public String getDefinition(){
- return this.definition;
- }
-
- public void setDefinition(String def){
- this.definition = def;
- }
-
- public String parseDefinition(String oid){
- String[] tokens = oid.split(".");
- String temp = "{ ";
- for (int i = 0; i < tokens.length;i++){
- temp += tokens[i];
- }
- temp += " }";
- return temp;
- }
-
- @Override
- public String toString(){
- StringBuffer buf = new StringBuffer();
- buf.append(this.name);
- buf.append("\t\tOBJECT IDENTIFIER ::= ");
- buf.append(this.definition);
- return buf.toString();
- }
-
- @Override
- public boolean equals(Object other){
- if (other == null) return false;
- if (other == this) return true;
- if (this.getClass() != other.getClass())return false;
- OIDDef otherDef = (OIDDef)other;
- if(otherDef.rawOid == this.rawOid)
- return true;
- else
- return false;
- }
-
-
- }//end OIDDef
-
-
-
-}// end MIB Generator
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list