[jboss-cvs] JBossAS SVN: r111604 - branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jun 13 16:59:49 EDT 2011
Author: thauser at redhat.com
Date: 2011-06-13 16:59:49 -0400 (Mon, 13 Jun 2011)
New Revision: 111604
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/TrapFactory.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java
Log:
merging changes from mobicents; adding v3 support; exposing binding map
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-06-13 20:57:16 UTC (rev 111603)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java 2011-06-13 20:59:49 UTC (rev 111604)
@@ -27,6 +27,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.SortedMap;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -128,7 +129,9 @@
// Initialise
this.trapFactory.set(this.snmpAgentService.getClock(),
- this.snmpAgentService.getTrapCounter());
+ this.snmpAgentService.getTrapCounter(),
+ this.snmpAgentService.getRequestHandler().getBindings(),
+ this.snmpAgentService.getServer());
// Start the trap factory
this.trapFactory.start();
@@ -163,30 +166,25 @@
return;
}
}
-
+
+ // Locate mapping for incomming event
+ int index = findMappingIndex(n);
+ if(index < 0) {
+ log.debug("No SNMP notifications configured for Notification " + n.getType() + " doing nothing");
+ return;
+ }
+
+ Mapping m = (Mapping)this.notificationMapList.get(index);
+ // Get the coresponding wrapper to get access to notification payload
+ NotificationWrapper wrapper =
+ (NotificationWrapper)this.notificationWrapperCache.get(index);
+
// Cache the translated notification
PDUv1 v1TrapPdu = null;
PDU v2cTrapPdu = null;
ScopedPDU v3TrapPdu = null;
if(managers.size() > 0) {
- // Locate mapping for incomming event
- int index = -1;
-
- try
- {
- index = findMappingIndex(n);
- }
- catch (IndexOutOfBoundsException e)
- {
- throw new MappingFailedException("No mapping found for notification type: '" +
- n.getType() + "'");
- }
-
- Mapping m = (Mapping)this.notificationMapList.get(index);
- // Get the coresponding wrapper to get access to notification payload
- NotificationWrapper wrapper =
- (NotificationWrapper)this.notificationWrapperCache.get(index);
// Send trap. Synchronise on the subscription collection while
// iterating
@@ -194,7 +192,7 @@
// Iterate over sessions and emit the trap on each one
Iterator i = this.managers.iterator();
while (i.hasNext()) {
- //ManagerRecord t = (ManagerRecord)i.next();
+
Target t = (Target)i.next();
try {
@@ -203,9 +201,6 @@
if (v1TrapPdu == null)
v1TrapPdu = this.trapFactory.generateV1Trap(n, m, wrapper);
- //Should work, but need to upgrade to snmp4j v.1.10.2
-// v1TrapPdu.setAgentAddress((IpAddress)t.getAddress());
-
sendTrap(v1TrapPdu, t, m.getSecurityName());
break;
@@ -219,14 +214,7 @@
case SnmpConstants.version3:
if (v3TrapPdu == null)
v3TrapPdu = this.trapFactory.generateV3Trap(n, m, wrapper);
-
- // if (contextEngineID != null) {
- // trapPdu.setContextEngineID(contextEngineID);
- // }
- // if (contextName != null) {
- // trapPdu.setContextName(contextName);
- // }
-
+
sendTrap(v3TrapPdu, t, m.getSecurityName());
break;
@@ -234,15 +222,10 @@
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 +
- ">");
+ } catch(MappingFailedException e) {
+ log.error("Translating notification failed ", e);
+ } catch(Exception e) {
+ log.error("SNMP send error for " + t.getAddress().toString(), e);
}
}
}
@@ -325,8 +308,7 @@
}
}
}
- // Signal "no mapping found"
- throw new IndexOutOfBoundsException();
+ return -1;
}
/**
@@ -382,7 +364,7 @@
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.
@@ -492,6 +474,9 @@
break;
case 2:
m.setVersion(SnmpConstants.version2c);
+ break;
+ case 3:
+ m.setVersion(SnmpConstants.version3);
}
}
@@ -552,8 +537,7 @@
AbstractTransportMapping transport;
if (address instanceof TcpAddress) {
transport = new DefaultTcpTransportMapping();
- }
- else {
+ } else {
transport = new DefaultUdpTransportMapping();
}
// Could save some CPU cycles:
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java 2011-06-13 20:57:16 UTC (rev 111603)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java 2011-06-13 20:59:49 UTC (rev 111604)
@@ -20,11 +20,13 @@
package org.jboss.jmx.adaptor.snmp.agent;
import javax.management.Notification;
+import javax.management.MBeanServer;
import org.jboss.jmx.adaptor.snmp.config.notification.Mapping;
import org.snmp4j.PDUv1;
import org.snmp4j.PDU;
import org.snmp4j.ScopedPDU;
+import java.util.SortedMap;
/**
* <tt>TrapFactory </tt> takes care of translation of Notifications into
@@ -70,7 +72,7 @@
* Sets the name of the file containing the notification/trap mappings,
* the uptime clock and the trap counter
**/
- public void set(Clock uptime, Counter count);
+ public void set(Clock uptime, Counter count, SortedMap bindings, MBeanServer server);
/**
* Performs all the required initialisation in order for the mapper to
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-13 20:57:16 UTC (rev 111603)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java 2011-06-13 20:59:49 UTC (rev 111604)
@@ -21,8 +21,10 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.SortedMap;
import javax.management.Notification;
+import javax.management.MBeanServer;
import org.jboss.jmx.adaptor.snmp.config.notification.Mapping;
import org.jboss.jmx.adaptor.snmp.config.notification.VarBind;
@@ -91,6 +93,12 @@
/** Trap counter */
private Counter trapCount = null;
+ /** attributes gathered from attributes.xml, used for bindings **/
+ private SortedMap bindings = null;
+
+ /** MBeanServer instance to query about BindEntry objects contained in the bindings map**/
+ private MBeanServer server = null;
+
/**
* Create TrapFactorySupport
**/
@@ -103,10 +111,12 @@
* Sets the name of the file containing the notification/trap mappings,
* the uptime clock and the trap counter
**/
- public void set(Clock clock, Counter count)
+ public void set(Clock clock, Counter count, SortedMap bindings, MBeanServer server)
{
this.clock = clock;
this.trapCount = count;
+ this.bindings = bindings;
+ this.server = server;
}
/**
@@ -148,6 +158,9 @@
// Append the specified varbinds. Get varbinds from mapping and for
// each one of the former use the wrapper to get the corresponding
// values
+
+ // we don't want to use the wrapper for getting the values. we want to use the MBeanServer to
+ // directly query the included OID. This is how traps should have been done.
if(wrapper != null)
{
@@ -276,6 +289,14 @@
// wrapper in order for it to locate the required value. That
// value and the aforementioned OID are used to generate the
// variable binding
+
+ /**
+ * This is incorrect. we should not be using this "tag" system at all, but
+ * we should be using the OID itself as a key to find a BindEntry that matches
+ * the OID. Trap variable bindings must consist of MIB-defined Objects, not arbitrarily
+ * defined variables.
+ */
+
trapPdu.add(
this.snmpVBFactory.make(vb.getOid(), wrapper.get(vb.getTag())));
}
More information about the jboss-cvs-commits
mailing list