[jboss-cvs] JBossAS SVN: r111489 - in branches/snmp4j-int/varia/src: main/java/org/jboss/jmx/adaptor/snmp/config/attribute and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 31 13:38:59 EDT 2011
Author: thauser at redhat.com
Date: 2011-05-31 13:38:58 -0400 (Tue, 31 May 2011)
New Revision: 111489
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/SnmpAgentService.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/TrapFactorySupport.java
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/manager/Manager.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/system/MIB2SystemGroupService.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/system/MIB2SystemGroupServiceMBean.java
branches/snmp4j-int/varia/src/resources/services/snmp/deploy/META-INF/jboss-service.xml
branches/snmp4j-int/varia/src/resources/services/snmp/deploy/attributes.xml
Log:
backport mobicents v3 trap + commit MIBGenerator work
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-05-31 16:26:15 UTC (rev 111488)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2011-05-31 17:38:58 UTC (rev 111489)
@@ -34,10 +34,7 @@
import java.util.Vector;
import javax.management.Attribute;
-import javax.management.MBeanAttributeInfo;
import javax.management.MBeanServer;
-import javax.management.MBeanServerConnection;
-import javax.management.MBeanInfo;
import javax.management.ObjectName;
import org.jboss.jmx.adaptor.snmp.config.attribute.AttributeMappings;
@@ -110,7 +107,6 @@
bindings = new TreeMap();
oidKeys = new TreeSet();
objectKeys = new TreeSet();
- mibGenerator = new MIBGenerator();
}
// RequestHandler Implementation ---------------------------------
@@ -604,7 +600,6 @@
log.debug("Reading resource: '" + resourceName + "'");
// arraylists for the MIB Generator, to query things like description and type
- ArrayList<MBeanAttributeInfo[]> attrInfo = new ArrayList<MBeanAttributeInfo[]>();
ArrayList<MappedAttribute> maList = new ArrayList<MappedAttribute>();
ObjectModelFactory omf = new AttributeMappingsBinding();
@@ -651,10 +646,7 @@
String oidPrefix = mmb.getOidPrefix();
List attrs = mmb.getAttributes();
//we need this info for the MIB Generator
- MBeanInfo mbInfo = server.getMBeanInfo(new ObjectName(mmb.getName()));
-
- attrInfo.add(mbInfo.getAttributes());
-
+
Iterator aIt = attrs.iterator();
while (aIt.hasNext())
{
@@ -678,7 +670,8 @@
}
}
//last step, to be indicated in choice somewhere.
- generateMib(mibResName, attrInfo, maList);
+ //if (genMib) -- check to be added; don't want to always gen the MIB
+ generateMib(mibResName, mappings, maList);
}
@@ -687,7 +680,7 @@
* @param ArrayList<MBeanAttributeInfo[]> information about the attributes gathered during initialization
* @param ArrayList<MappedAttribute> information about the attributes in the .xml, namely the desired OID value and r/w perms
*/
- private void generateMib(String mibResName, ArrayList<MBeanAttributeInfo[]> attrList, ArrayList<MappedAttribute> maList){
+ private void generateMib(String mibResName, AttributeMappings attrList, ArrayList<MappedAttribute> maList){
this.mibGenerator = new MIBGenerator(mibResName, attrList, maList);
mibGenerator.writeMib();
}
@@ -1068,7 +1061,7 @@
}
// if the tailSet is empty...there aren't any OID larger than the one given. so we're at the End of the MIB.
else{
- log.debug("getNextOid: Placeholder. There is no lexically larger OID than the input.");
+ log.debug("getNextOid: There is no lexically larger OID than the input.");
throw new EndOfMibViewException();
}
@@ -1082,23 +1075,11 @@
}
else
{
- log.debug("getNextOid: Placeholder. There is no lexically larger OID than the input.");
+ log.debug("getNextOid: There is no lexically larger OID than the input.");
// end of list
throw new EndOfMibViewException();
}
}
-
- // Check if still in subtree if requested to stay within
- // THIS SHOULD BE A MANAGER FUNCTION, NOT AGENT.
-/* if (stayInSubtree && roid != null)
- {
- //OID parent = coid.removeLast();
- // this emulates the functionality of the "isRoot" in SnmpObjectId from joesnmp
- if (coid.leftMostCompare((coid.size()-1), roid) != 0){
- log.debug("getNextOid: Placeholder. The traversal has left the subtree.");
- throw new EndOfMibViewException();
- }
- }*/
return roid;
}
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-05-31 16:26:15 UTC (rev 111488)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentService.java 2011-05-31 17:38:58 UTC (rev 111489)
@@ -23,7 +23,10 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import javax.management.Notification;
import javax.management.ObjectName;
@@ -164,8 +167,10 @@
private MessageDispatcherImpl dispatcher;
- // Constructors --------------------------------------------------
+ private Map<String, User> userMap = new HashMap<String, User>();
+ // Constructors --------------------------------------------------
+
/**
* Default CTOR
*/
@@ -516,6 +521,14 @@
protected void startService()
throws Exception
{
+
+ // initialise the snmp agent
+ log.debug("Starting snmp agent ...");
+
+ startAgent();
+
+ log.info("SNMP agent going active");
+
// initialize clock and trapCounter
this.clock = new Clock();
this.trapCounter = new Counter(0);
@@ -524,11 +537,7 @@
// ListenerServiceMBeanSupport baseclass
log.debug("Instantiating trap emitter ...");
- this.trapEmitter = new TrapEmitter(this.getTrapFactoryClassName(),
- this.trapCounter,
- this.clock,
- this.getManagersResName(),
- this.getNotificationMapResName());
+ this.trapEmitter = new TrapEmitter(this);
// Start trap emitter
log.debug("Starting trap emitter ...");
@@ -543,14 +552,7 @@
heartbeat.start();
// subscribe for notifications, with the option for dynamic subscriptions
- super.subscribe(this.dynamicSubscriptions);
-
- // initialise the snmp agent
- log.debug("Starting snmp agent ...");
-
- startAgent();
-
- log.info("SNMP agent going active");
+ super.subscribe(this.dynamicSubscriptions);
// Send the cold start!
this.sendNotification(new Notification(EventTypes.COLDSTART, this,
@@ -664,8 +666,8 @@
MappingObjectModelFactory momf = new MappingObjectModelFactory();
momf.mapElementToClass("user-list", ArrayList.class);
momf.mapElementToClass("user", User.class);
-
- ArrayList<User> userList = null;
+
+ List<User> userList = null;
InputStream is = null;
try {
// locate users.xml
@@ -697,6 +699,7 @@
user.getPrivacyProtocolID(),
new OctetString(user.getPrivacyPassphrase()));
this.usm.addUser(usmUser.getSecurityName(), usm.getLocalEngineID(),usmUser);
+ this.userMap.put(user.getSecurityName(), user);
}
}
@@ -759,4 +762,25 @@
return usersResName;
}
+ /**
+ * @return the clock
+ */
+ public Clock getClock() {
+ return clock;
+ }
+
+ /**
+ * @return the trapCounter
+ */
+ public Counter getTrapCounter() {
+ return trapCounter;
+ }
+
+ /**
+ * @return the userList
+ */
+ public Map<String, User> getUserMap() {
+ return userMap;
+ }
+
}
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-05-31 16:26:15 UTC (rev 111488)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java 2011-05-31 17:38:58 UTC (rev 111489)
@@ -33,25 +33,27 @@
import org.jboss.bootstrap.api.as.config.JBossASServerConfig;
import org.jboss.jmx.adaptor.snmp.config.manager.Manager;
+import org.jboss.jmx.adaptor.snmp.config.user.User;
import org.jboss.logging.Logger;
import org.jboss.xb.binding.MappingObjectModelFactory;
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
-
import org.snmp4j.CommunityTarget;
-import org.snmp4j.PDUv1;
import org.snmp4j.PDU;
+import org.snmp4j.PDUv1;
import org.snmp4j.ScopedPDU;
-import org.snmp4j.Target;
import org.snmp4j.Snmp;
+import org.snmp4j.Target;
import org.snmp4j.UserTarget;
-import org.snmp4j.mp.MPv3;
import org.snmp4j.mp.SnmpConstants;
+import org.snmp4j.security.Priv3DES;
+import org.snmp4j.security.SecurityLevel;
+import org.snmp4j.security.SecurityModel;
import org.snmp4j.security.SecurityModels;
import org.snmp4j.security.SecurityProtocols;
import org.snmp4j.security.USM;
+import org.snmp4j.security.UsmUser;
import org.snmp4j.smi.Address;
-import org.snmp4j.smi.IpAddress;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.TcpAddress;
import org.snmp4j.smi.UdpAddress;
@@ -79,38 +81,16 @@
/** Reference to the utilised trap factory*/
private TrapFactory trapFactory = null;
- /** The actual trap factory to instantiate */
- private String trapFactoryClassName = null;
-
- /** The managers resource name */
- private String managersResName = null;
+ private SnmpAgentService snmpAgentService;
- /** The notification map resource name */
- private String notificationMapResName = null;
-
- /** Provides trap count */
- private Counter trapCount = null;
-
- /** Uptime clock */
- private Clock uptime = null;
-
/** Holds the manager subscriptions. Accessed through synch'd wrapper */
private Set managers = Collections.synchronizedSet(new HashSet());
/**
* Builds a TrapEmitter object for sending SNMP V1 or V2 traps. <P>
**/
- public TrapEmitter(String trapFactoryClassName,
- Counter trapCount,
- Clock uptime,
- String managersResName,
- String notificationMapResName)
- {
- this.trapFactoryClassName = trapFactoryClassName;
- this.trapCount = trapCount;
- this.uptime = uptime;
- this.managersResName = managersResName;
- this.notificationMapResName = notificationMapResName;
+ public TrapEmitter(SnmpAgentService snmpAgentService) {
+ this.snmpAgentService = snmpAgentService;
}
/**
@@ -123,14 +103,14 @@
load();
// Instantiate the trap factory
- this.trapFactory = (TrapFactory) Class.forName(this.trapFactoryClassName,
+ this.trapFactory = (TrapFactory) Class.forName(this.snmpAgentService.getTrapFactoryClassName(),
true,
this.getClass().getClassLoader()).newInstance();
// Initialise
- this.trapFactory.set(this.notificationMapResName,
- this.uptime,
- this.trapCount);
+ this.trapFactory.set(this.snmpAgentService.getNotificationMapResName(),
+ this.snmpAgentService.getClock(),
+ this.snmpAgentService.getTrapCounter());
// Start the trap factory
this.trapFactory.start();
@@ -157,9 +137,7 @@
* @throws Exception if an error occurs during the preparation or
* sending of the trap
**/
- public void send(Notification n)
- throws Exception
- {
+ public void send(Notification n) throws Exception {
// Beeing paranoid
synchronized(this.trapFactory) {
if(this.trapFactory == null) {
@@ -179,89 +157,83 @@
//The target to send to
Target t = null;
- // Send trap. Synchronise on the subscription collection while
- // iterating
- synchronized(this.managers) {
-
- // Iterate over sessions and emit the trap on each one
- Iterator i = this.managers.iterator();
- while (i.hasNext()) {
- //ManagerRecord t = (ManagerRecord)i.next();
- t = (Target)i.next();
-
- try {
- snmp = createSnmpSession(t.getAddress());
- switch (t.getVersion()) {
- case SnmpConstants.version1:
- //case SnmpAgentService.SNMPV1:
- if (v1TrapPdu == null)
- v1TrapPdu = this.trapFactory.generateV1Trap(n);
-
- // fix the agent ip in the trap depending on which local address is bound
- //Should work, but need to upgrade to snmp4j v.1.10.2
- //v1TrapPdu.setAgentAddress((IpAddress)t.getAddress());
-
- // Advance the trap counter
- this.trapCount.advance();
-
- // Send
- //s.getSession().send(v1TrapPdu);
- log.debug("Sending trap: "+v1TrapPdu.toString() + "\n to target: "+ t.toString());
- snmp.send(v1TrapPdu, t);
- break;
-
- case SnmpConstants.version2c:
- //case SnmpAgentService.SNMPV2:
- if (v2cTrapPdu == null)
- v2cTrapPdu = this.trapFactory.generateV2cTrap(n);
-
- // Advance the trap counter
- this.trapCount.advance();
-
- // Send
- //t.getSession().send(v2TrapPdu);
- snmp.send(v2cTrapPdu, t);
- break;
-
- case SnmpConstants.version3:
-
- if (v3TrapPdu == null)
- v3TrapPdu = this.trapFactory.generateV3Trap(n);
-
-// if (contextEngineID != null) {
-// trapPdu.setContextEngineID(contextEngineID);
-// }
-// if (contextName != null) {
-// trapPdu.setContextName(contextName);
-// }
-
- // Advance the trap counter
- this.trapCount.advance();
-
- // Send
- snmp.send(v3TrapPdu, t);
- break;
-
- default:
- log.error("Skipping session: Unknown SNMP version found");
- }
- }
- catch(MappingFailedException e) {
- log.error("Translating notification - " + e.getMessage());
- }
- catch(Exception e) {
- log.error("SNMP send error for " +
- t.getAddress().toString() + ":" +
- ": <" + e +
- ">");
- }
- }
- if (snmp != null){
- snmp.close();
- }
- else {
- log.warn("No SNMP managers to send traps to");
- }
+ if(managers.size() > 0) {
+ // Send trap. Synchronise on the subscription collection while
+ // iterating
+ synchronized(this.managers) {
+ // Iterate over sessions and emit the trap on each one
+ Iterator i = this.managers.iterator();
+ while (i.hasNext()) {
+ //ManagerRecord t = (ManagerRecord)i.next();
+ t = (Target)i.next();
+
+ try {
+ snmp = createSnmpSession(t.getAddress());
+ switch (t.getVersion()) {
+ case SnmpConstants.version1:
+ if (v1TrapPdu == null)
+ v1TrapPdu = this.trapFactory.generateV1Trap(n);
+
+ //Should work, but need to upgrade to snmp4j v.1.10.2
+// v1TrapPdu.setAgentAddress((IpAddress)t.getAddress());
+
+ // Advance the trap counter
+ this.snmpAgentService.getTrapCounter().advance();
+
+ // Send
+ log.debug("Sending trap: "+v1TrapPdu.toString() + "\n to target: "+ t.toString());
+ snmp.send(v1TrapPdu, t);
+ break;
+
+ case SnmpConstants.version2c:
+ if (v2cTrapPdu == null)
+ v2cTrapPdu = this.trapFactory.generateV2cTrap(n);
+
+ // Advance the trap counter
+ this.snmpAgentService.getTrapCounter().advance();
+
+ // Send
+ snmp.send(v2cTrapPdu, t);
+ break;
+
+ case SnmpConstants.version3:
+ if (v3TrapPdu == null)
+ v3TrapPdu = this.trapFactory.generateV3Trap(n);
+
+ // if (contextEngineID != null) {
+ // trapPdu.setContextEngineID(contextEngineID);
+ // }
+ // if (contextName != null) {
+ // trapPdu.setContextName(contextName);
+ // }
+
+ // Advance the trap counter
+ this.snmpAgentService.getTrapCounter().advance();
+
+ // Send
+ snmp.send(v3TrapPdu, t);
+ break;
+
+ default:
+ log.error("Skipping session: Unknown SNMP version found");
+ }
+ if (snmp != null){
+ snmp.close();
+ }
+ }
+ catch(MappingFailedException e) {
+ log.error("Translating notification - " + e.getMessage());
+ }
+ catch(Exception e) {
+ log.error("SNMP send error for " +
+ t.getAddress().toString() + ":" +
+ ": <" + e +
+ ">");
+ }
+ }
+ }
+ } else {
+ log.warn("No SNMP managers to send traps to");
}
}
@@ -270,7 +242,7 @@
**/
private void load() throws Exception
{
- log.debug("Reading resource: '" + this.managersResName + "'");
+ log.debug("Reading resource: '" + this.snmpAgentService.getManagersResName() + "'");
// configure ObjectModelFactory for mapping XML to POJOs
// we'll be simply getting an ArrayList of Manager objects
@@ -283,7 +255,7 @@
try
{
// locate managers.xml
- final String resName = this.managersResName;
+ final String resName = this.snmpAgentService.getManagersResName();
is = SecurityActions.getThreadContextClassLoaderResource(resName);
// create unmarshaller
@@ -295,7 +267,7 @@
}
catch (Exception e)
{
- log.error("Accessing resource '" + managersResName + "'");
+ log.error("Accessing resource '" + snmpAgentService.getManagersResName() + "'");
throw e;
}
finally
@@ -313,40 +285,22 @@
// Read the monitoring manager's particulars
Manager m = (Manager)i.next();
fixManagerVersion(m);
-// try
-// {
- // Create a record of the manager's interest
-
- Target target = createTarget(m);
- if (target == null){
- log.warn("createTarget: manager m: "+m.toString() + " is null!");
- continue;
- }
-
-// ManagerRecord mr = new ManagerRecord(
-// InetAddress.getByName(m.getAddress()),
-// m.getPort(),
-// toInetAddressWithDefaultBinding(m.getLocalAddress()),
-// m.getLocalPort(),
-// m.getVersion()
-// );
-
- // Add the record to the list of monitoring managers. If
- // successfull open the session to the manager as well.
- if (this.managers.add(target) == false)
- {
- log.warn("Ignoring duplicate manager: " + m);
- }
- //else
- //{
- // Open the session to the manager
- //mr.openSession();
- //}
-// }
-// catch (Exception e)
-// {
-// log.warn("Error enabling monitoring manager: " + m, e);
-// }
+ if(m.getVersion() == 3 && m.getSecurityName() != null && snmpAgentService.getUserMap().get(m.getSecurityName()) == null) {
+ throw new IllegalArgumentException("Manager Security Name " + m.getSecurityName() + " doesn't match any user defined in users.xml");
+ }
+
+ Target target = createTarget(m);
+ if (target == null){
+ log.warn("createTarget: manager m: "+m.toString() + " is null!");
+ continue;
+ }
+
+ // Add the record to the list of monitoring managers. If
+ // successfull open the session to the manager as well.
+ if (this.managers.add(target) == false)
+ {
+ log.warn("Ignoring duplicate manager: " + m);
+ }
}
}
@@ -389,39 +343,31 @@
private Target createTarget(Manager m){
Target target = null;
-// String newAddr;
-// if (m.getAddress() != null){
-// System.out.println("*************************************");
-// System.out.println("Address" + m.getAddress());
-// System.out.println("Port" + m.getPort());
-// System.out.println("*************************************");
-// newAddr = m.getAddress()+"/"+m.getPort();
-// }
-// else {return null;}
-
+
int version = m.getVersion();
try{
if (version == SnmpConstants.version1 || version == SnmpConstants.version2c){
-
- //change 'public' to a constant somewhere
- //target = new CommunityTarget(new TcpAddress(newAddr), new OctetString("public"));
-
- if (m.getAddress() != null){
- target = new CommunityTarget(new UdpAddress(InetAddress.getByName(m.getAddress()), m.getPort()), new OctetString(m.getCommunityString()));
- //try defining retries/timeout period in notifications.xml
- //Timeout and Retries needs to be a field later on
- //target.setRetries(3);
- target.setTimeout(8000);
- }
+ if (m.getAddress() != null){
+ target = new CommunityTarget(new UdpAddress(InetAddress.getByName(m.getAddress()), m.getPort()), new OctetString(m.getCommunityString()));
+ //try defining retries/timeout period in notifications.xml
+ //Timeout and Retries needs to be a field later on
+ //target.setRetries(3);
+ target.setTimeout(8000);
+ }
}
else if (version == SnmpConstants.version3) {
//won't be used at the moment
target = new UserTarget();
+ target.setRetries(1);
+ target.setTimeout(8000);
target.setAddress(new UdpAddress(InetAddress.getByName(m.getAddress()), m.getPort()));
+ ((UserTarget)target).setSecurityName(new OctetString(m.getSecurityName()));
+ ((UserTarget)target).setSecurityLevel(snmpAgentService.getUserMap().get(m.getSecurityName()).getSecurityLevel());
+ ((UserTarget)target).setSecurityModel(SecurityModel.SECURITY_MODEL_USM);
}
else {
//unrecognized version
- return null;
+ throw new IllegalArgumentException("version " + version + " is not supported in managers.xml, only 1, 2 and 3 are valid values");
}
} catch (UnknownHostException e) {} //something goes here
@@ -443,24 +389,24 @@
// transport.setAsyncMsgProcessingSupported(false);
Snmp snmp = new Snmp(transport);
- OctetString localEngineID =
- new OctetString(snmp.getLocalEngineID());
- USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
- SecurityModels.getInstance().addSecurityModel(usm);
+ OctetString localEngineID =new OctetString(snmp.getLocalEngineID());
+ USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
+ SecurityProtocols.getInstance().addDefaultProtocols();
+ // all other privacy and authentication protocols are provided by the above method
+ SecurityProtocols.getInstance().addPrivacyProtocol(new Priv3DES());
+ SecurityModels.getInstance().addSecurityModel(usm);
+
+ for (Iterator<User> userIt = snmpAgentService.getUserMap().values().iterator(); userIt.hasNext(); ) {
+ User user = userIt.next();
+
+ UsmUser usmUser = new UsmUser(new OctetString(user.getSecurityName()),
+ user.getAuthenticationProtocolID(),
+ new OctetString(user.getAuthenticationPassphrase()),
+ user.getPrivacyProtocolID(),
+ new OctetString(user.getPrivacyPassphrase()));
+ usm.addUser(usmUser.getSecurityName(), usm.getLocalEngineID(),usmUser);
+ }
-
-// SNMPv3 stuff ~ add and fix later
-//
-// ((MPv3)snmp.getMessageProcessingModel(MPv3.ID)).
-// setLocalEngineID(localEngineID.getValue());
-//
-// if (version == SnmpConstants.version3) {
-// USM usm = new USM(SecurityProtocols.getInstance(),
-// localEngineID,
-// engineBootCount);
-// SecurityModels.getInstance().addSecurityModel(usm);
-// addUsmUser(snmp);
-// }
return snmp;
}
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-05-31 16:26:15 UTC (rev 111488)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java 2011-05-31 17:38:58 UTC (rev 111489)
@@ -20,8 +20,6 @@
package org.jboss.jmx.adaptor.snmp.agent;
import java.io.InputStream;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -43,7 +41,10 @@
import org.snmp4j.PDU;
import org.snmp4j.PDUv1;
import org.snmp4j.ScopedPDU;
+import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.OID;
+import org.snmp4j.smi.TimeTicks;
+import org.snmp4j.smi.VariableBinding;
import org.xml.sax.Attributes;
/**
@@ -367,14 +368,18 @@
PDU trapPdu = new PDU();
trapPdu.setType(PDU.TRAP);
+ // Get the coresponding wrapper
+ NotificationWrapper wrapper =
+ (NotificationWrapper)this.notificationWrapperCache.get(index);
+
+ // Those 2 Variable Bindings are mandatory for v2c and v3 traps and inform
+ trapPdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(this.clock.uptime())));
+ // For generic traps, values are defined in RFC 1907, for vendor specific traps snmpTrapOID is essentially a concatenation of the SNMPv1 Enterprise parameter and two additional sub-identifiers, '0', and the SNMPv1 Specific trap code parameter.
+ trapPdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(m.getEnterprise() + ".0." + m.getSpecific())));
+
// Append the specified varbinds. Get varbinds from mapping and for
// each one of the former use the wrapper to get data from the
// notification
-
- // Get the coresponding wrapper
- NotificationWrapper wrapper =
- (NotificationWrapper)this.notificationWrapperCache.get(index);
-
if (wrapper != null)
{
// Prime the wrapper with the notification contents
@@ -431,25 +436,27 @@
// Create trap
ScopedPDU trapPdu = new ScopedPDU();
- trapPdu.setType(PDU.TRAP);
-
- // Append the specified varbinds. Get varbinds from mapping and for
- // each one of the former use the wrapper to get data from the
- // notification
+ trapPdu.setType(ScopedPDU.TRAP);
// Get the coresponding wrapper
NotificationWrapper wrapper =
(NotificationWrapper)this.notificationWrapperCache.get(index);
- if (wrapper != null)
- {
+ // Those 2 Variable Bindings are mandatory for v2c and v3 traps and inform
+ trapPdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(this.clock.uptime())));
+ // For generic traps, values are defined in RFC 1907, for vendor specific traps snmpTrapOID is essentially a concatenation of the SNMPv1 Enterprise parameter and two additional sub-identifiers, '0', and the SNMPv1 Specific trap code parameter.
+ trapPdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(m.getEnterprise() + ".0." + m.getSpecific())));
+
+ // Append the specified varbinds. Get varbinds from mapping and for
+ // each one of the former use the wrapper to get data from the
+ // notification
+ if (wrapper != null) {
// Prime the wrapper with the notification contents
wrapper.prime(n);
List vbList = m.getVarBindList().getVarBindList();
- for (int i = 0; i < vbList.size(); i++)
- {
+ for (int i = 0; i < vbList.size(); i++) {
VarBind vb = (VarBind)vbList.get(i);
// Append the var bind. Interrogate read vb for OID and
@@ -460,9 +467,7 @@
trapPdu.add(
this.snmpVBFactory.make(vb.getOid(), wrapper.get(vb.getTag())));
}
- }
- else
- {
+ } else {
log.warn("Varbind mapping failure: null wrapper defined for " +
" notification type '" + m.getNotificationType() + "'" );
}
Modified: 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-05-31 16:26:15 UTC (rev 111488)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/attribute/MIBGenerator.java 2011-05-31 17:38:58 UTC (rev 111489)
@@ -27,7 +27,11 @@
import java.util.Iterator;
import org.jboss.jmx.adaptor.snmp.config.attribute.MappedAttribute;
+
import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanServer;
+import javax.management.MBeanInfo;
+import javax.management.ObjectName;
/**
@@ -39,7 +43,7 @@
public class MIBGenerator {
private String mibResName; // the name of the output MIB file
- private ArrayList<MBeanAttributeInfo> attrInfo;
+ private AttributeMappings attrInfo;
private ArrayList<MappedAttribute> maList; // a list of all mapped attributes algamated from all attributes.xml
private ArrayList<MIBObject> miboList; //internal list of MIBObjects
@@ -50,12 +54,11 @@
this.miboList = null;
}
- public MIBGenerator(String mibResName, ArrayList<MBeanAttributeInfo[]> attrInfo, ArrayList<MappedAttribute> maList){
- ArrayList<MBeanAttributeInfo[]> tempAttrInfo = attrInfo;
+ public MIBGenerator(String mibResName, AttributesMapping attrInfo, ArrayList<MappedAttribute> maList){
this.mibResName = mibResName;
this.maList = maList;
- this.attrInfo = processMBeanInfo(tempAttrInfo); //modify attrInfo to be a large 1-d array of MBeanAttributeInfo objects
- addDescriptions(); // insert the proper description into each MappedAttribute so we can create MIBObjects from them
+ this.attrInfo = attrInfo;
+ this.miboList = new ArrayList<MIBObject>();
}
//mutators
@@ -84,20 +87,18 @@
}
//we're done gathering attributes. write the MIB.
- public void writeMib(){
+ public void writeMib() throws Exception{
try{
- PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("mibResName")));
+ PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(mibResName)));
writeHeader(out);
writeDefinitions(miboList,out);
out.println("END");
out.close();
}
- catch (Exception e){
- System.out.println("herpderp!");
- }
+ catch (Exception e){throw e;}
}
- private void addDescriptions(){
+/* private void addDescriptions(){
Iterator<MappedAttribute> maIt = this.maList.iterator();
while (maIt.hasNext()){
MappedAttribute tempMa = maIt.next();
@@ -109,9 +110,9 @@
}
}
}
- }
+ }*/
- private ArrayList<MBeanAttributeInfo> processMBeanInfo(ArrayList<MBeanAttributeInfo[]> attrInfo){
+/* private ArrayList<MBeanAttributeInfo> processMBeanInfo(ArrayList<MBeanAttributeInfo[]> attrInfo){
ArrayList<MBeanAttributeInfo> retval = new ArrayList<MBeanAttributeInfo>(10);
Iterator<MBeanAttributeInfo[]> mbaIt = attrInfo.iterator();
while (mbaIt.hasNext()){
@@ -122,16 +123,27 @@
}
//done adding all MBeanAttributeInfos
return retval;
- }
+ }*/
private void writeHeader(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 not we don't need this to be a seperate method.
}
- private void writeDefinitions(ArrayList<MIBObject>miboList, PrintWriter out){
+ /** This method is used to write the definitions of our SYNTAX inside the JBoss MIB
+ *
+ * @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 writeDefinitions(AttributeMappings attrList, PrintWriter out){
+
+ }
+
+ private void writeObjects(ArrayList<MIBObject>miboList, PrintWriter out){
createMIBObjects(this.maList);
Iterator<MIBObject> aIt = miboList.iterator();
while (aIt.hasNext()){
@@ -165,7 +177,7 @@
//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(ma.getName().lastIndexOf('='), ma.getName().length());
+ this.name = ma.getName();
this.syntax = "STRING"; // definitely need a better way to find this out.
// maybe need to parse notifications.xml to find out trap objects
@@ -191,7 +203,7 @@
buf.append("\n");
buf.append("\tDESCRIPTION ");
buf.append("\n\t\t");
- buf.append(this.description);
+ buf.append("\"DESCRIPTION\"");
buf.append("\n");
buf.append("::= {").append(" ");
buf.append(objectId + " }");
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/manager/Manager.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/manager/Manager.java 2011-05-31 16:26:15 UTC (rev 111488)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/config/manager/Manager.java 2011-05-31 17:38:58 UTC (rev 111489)
@@ -42,6 +42,7 @@
private int localPort;
private int version;
private String communityString;
+ private String securityName;
// Constructors -------------------------------------------------
@@ -179,6 +180,20 @@
this.communityString = communityString;
}
+ /**
+ * @param securityName the securityName to set
+ */
+ public void setSecurityName(String securityName) {
+ this.securityName = securityName;
+ }
+
+ /**
+ * @return the securityName
+ */
+ public String getSecurityName() {
+ return securityName;
+ }
+
// Object overrides ----------------------------------------------
public String toString()
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/system/MIB2SystemGroupService.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/system/MIB2SystemGroupService.java 2011-05-31 16:26:15 UTC (rev 111488)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/system/MIB2SystemGroupService.java 2011-05-31 17:38:58 UTC (rev 111489)
@@ -45,17 +45,19 @@
{
// Constants -----------------------------------------------------
- /** JBoss OID Prefix */
- public static final String JBOSS_PREFIX = "1.3.6.1.4.1.18016";
+ /** JBoss OID Prefix http://www.wtcs.org/snmp4tpc/snmp.htm
+ 2312 is red hat prefix from http://www.oid-info.com/get/1.3.6.1.4.1.2312
+ we define 100 arbitrary as the JBoss division
+ */
+
+ public static final String JBOSS_PREFIX = "1.3.6.1.4.1.2312.100";
- /** Product JBossAS */
- public static final String PRODUCT = ".1.1";
+ // Private Data --------------------------------------------------
+
+ // JBoss AS product is 1
+ private String product;
+ private String version;
- /** Version 4.0.x */
- public static final String VERSION = ".2";
-
- // Private Data --------------------------------------------------
-
private String sysDescr; // system.1
private OID sysObjectId; // system.2
// private long sysUpTime; // system.3
@@ -76,7 +78,39 @@
}
// Attributes ----------------------------------------------------
-
+
+ /**
+ * @param product the product to set
+ * @jmx:managed-attribute
+ */
+ public void setProduct(String product) {
+ this.product = product;
+ }
+
+ /**
+ * @return the product
+ * @jmx:managed-attribute
+ */
+ public String getProduct() {
+ return product;
+ }
+
+ /**
+ * @param version the product version to set
+ * @jmx:managed-attribute
+ */
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ /**
+ * @return the product version
+ * @jmx:managed-attribute
+ */
+ public String getVersion() {
+ return version;
+ }
+
/**
* @jmx:managed-attribute
*/
@@ -205,11 +239,12 @@
String serverConfig = ServerConfigLocator.locate().getServerName();
ObjectName name = new ObjectName(ServerInfoMBean.OBJECT_NAME_STR);
String hostAddress = (String)server.getAttribute(name, "HostAddress");
-
+
this.sysName = serverConfig + "@" + hostAddress;
log.debug("Setting sysName name to " + sysName);
}
- this.sysObjectId = new OID(JBOSS_PREFIX + PRODUCT + VERSION);
+
+ this.sysObjectId = new OID(JBOSS_PREFIX + product + version);
}
}
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/system/MIB2SystemGroupServiceMBean.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/system/MIB2SystemGroupServiceMBean.java 2011-05-31 16:26:15 UTC (rev 111488)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/system/MIB2SystemGroupServiceMBean.java 2011-05-31 17:38:58 UTC (rev 111489)
@@ -41,7 +41,12 @@
ObjectName OBJECT_NAME = ObjectNameFactory.create("jboss.jmx:name=SnmpAgent,service=MIB2SystemGroup");
// Attributes ----------------------------------------------------
-
+ void setProduct(String product);
+ String getProduct();
+
+ void setVersion(String version);
+ String getVersion();
+
/** The snmp agent */
void setSnmpAgent(ObjectName agent);
ObjectName getSnmpAgent();
Modified: branches/snmp4j-int/varia/src/resources/services/snmp/deploy/META-INF/jboss-service.xml
===================================================================
--- branches/snmp4j-int/varia/src/resources/services/snmp/deploy/META-INF/jboss-service.xml 2011-05-31 16:26:15 UTC (rev 111488)
+++ branches/snmp4j-int/varia/src/resources/services/snmp/deploy/META-INF/jboss-service.xml 2011-05-31 17:38:58 UTC (rev 111489)
@@ -94,6 +94,8 @@
<attribute name="TrapFactoryClassName">org.jboss.jmx.adaptor.snmp.agent.TrapFactorySupport</attribute>
<attribute name="NotificationMapResName">/notifications.xml</attribute>
<attribute name="ManagersResName">/managers.xml</attribute>
+ <attribute name="UsersResName">/users.xml</attribute>
+ <attribute name="MibResName">test.mib</attribute>
<attribute name="HeartBeatPeriod">0</attribute>
<attribute name="BindAddress">
<!-- Get the interface from the ServiceBindingManager -->
@@ -154,4 +156,4 @@
<mbean code="org.jboss.jmx.adaptor.snmp.test.NotificationProducerService"
name="jboss.jmx:name=SnmpAgent,service=notification,type=producer"/>
-->
-</service>
\ No newline at end of file
+</service>
Modified: branches/snmp4j-int/varia/src/resources/services/snmp/deploy/attributes.xml
===================================================================
--- branches/snmp4j-int/varia/src/resources/services/snmp/deploy/attributes.xml 2011-05-31 16:26:15 UTC (rev 111488)
+++ branches/snmp4j-int/varia/src/resources/services/snmp/deploy/attributes.xml 2011-05-31 17:38:58 UTC (rev 111489)
@@ -19,9 +19,9 @@
</mbean>
<!-- tomcat global http request processing -->
- <mbean name="jboss.web:name=http-0.0.0.0-8080,type=GlobalRequestProcessor">
+ <!--<mbean name="jboss.web:name=http-0.0.0.0-8080,type=GlobalRequestProcessor">
<attribute name="requestCount" oid=".1.2.3.4.1.5"/>
- </mbean>
+ </mbean>-->
<!-- Tx Manager statistics -->
<!-- these attributes no longer exist in the AS -->
@@ -42,10 +42,10 @@
<attribute name="SysDescr" oid=".1" mode="rw"/> <!-- can be modified over snmp -->
<attribute name="SysObjectId" oid=".2"/>
<attribute name="SysUpTime" oid=".3"/>
- <attribute name="SysContact" oid=".4"/>
- <attribute name="SysName" oid=".5"/>
- <attribute name="SysLocation" oid=".6"/>
- <attribute name="SysServices" oid=".7"/>
- </mbean>
+ <attribute name="SysContact" oid=".4"/>
+ <attribute name="SysName" oid=".5"/>
+ <attribute name="SysLocation" oid=".6"/>
+ <attribute name="SysServices" oid=".7"/>
+ </mbean>-->
-</attribute-mappings>
\ No newline at end of file
+</attribute-mappings>
More information about the jboss-cvs-commits
mailing list