camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1336469 - /camel/trunk/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpConverters.java
Date Thu, 10 May 2012 01:58:47 GMT
Author: ningjiang
Date: Thu May 10 01:58:47 2012
New Revision: 1336469

URL: http://svn.apache.org/viewvc?rev=1336469&view=rev
Log:
CAMEL-5255 Add all SNMPv1 TRAP PDU information to message body for camel-snmp component

Modified:
    camel/trunk/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpConverters.java

Modified: camel/trunk/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpConverters.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpConverters.java?rev=1336469&r1=1336468&r2=1336469&view=diff
==============================================================================
--- camel/trunk/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpConverters.java
(original)
+++ camel/trunk/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpConverters.java
Thu May 10 01:58:47 2012
@@ -21,6 +21,7 @@ import java.util.StringTokenizer;
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
 import org.snmp4j.PDU;
+import org.snmp4j.PDUv1;
 import org.snmp4j.smi.OID;
 import org.snmp4j.smi.VariableBinding;
 
@@ -67,6 +68,14 @@ public final class SnmpConverters {
         return list;
     }
 
+    private static void entryAppend(StringBuilder sb, String tag, String value) {
+        sb.append(ENTRY_TAG_OPEN);
+        sb.append("<" + tag + ">");
+        sb.append(value);
+        sb.append("</" + tag + ">");
+        sb.append(ENTRY_TAG_CLOSE);
+    }
+
     /**
      * Converts the given snmp pdu to a String body.
      *
@@ -79,7 +88,21 @@ public final class SnmpConverters {
         StringBuilder sb = new StringBuilder();
 
         // prepare the header
-        sb.append(SNMP_TAG_OPEN);
+        if (pdu.getType() == PDU.V1TRAP) {
+            sb.append("<" + SNMP_TAG + " messageType=\"v1\">");
+        } else {
+            sb.append(SNMP_TAG_OPEN);
+        }
+
+        // Extract SNMPv1 specific variables
+        if (pdu.getType() == PDU.V1TRAP) {
+            PDUv1 v1pdu = (PDUv1) pdu;
+            entryAppend(sb, "enterprise", v1pdu.getEnterprise().toString());
+            entryAppend(sb, "agent-addr", v1pdu.getAgentAddress().toString());
+            entryAppend(sb, "generic-trap", Integer.toString(v1pdu.getGenericTrap()));
+            entryAppend(sb, "specific-trap", Integer.toString(v1pdu.getSpecificTrap()));
+            entryAppend(sb, "time-stamp", Long.toString(v1pdu.getTimestamp()));
+        }
 
         // now loop all variables of the response
         for (Object o : pdu.getVariableBindings()) {



Mime
View raw message