You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/09/06 15:19:10 UTC

[camel] branch master updated (91d1d95 -> 558bd7b)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 91d1d95  Add M4 and RC1 releases to namespace schemas
     new 77a461d  Update SnmpEndpoint.java
     new 0e72d30  Update SnmpProducer.java
     new 558bd7b  Create WalkOIDTest.java

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/camel/component/snmp/SnmpEndpoint.java  |  3 +-
 .../apache/camel/component/snmp/SnmpProducer.java  | 69 ++++++++++++++++++----
 .../snmp/{PollOIDTest.java => WalkOIDTest.java}    |  7 +--
 3 files changed, 62 insertions(+), 17 deletions(-)
 copy components/camel-snmp/src/test/java/org/apache/camel/component/snmp/{PollOIDTest.java => WalkOIDTest.java} (88%)


[camel] 02/03: Update SnmpProducer.java

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 0e72d3026e172be4d27bd21761899902e2bf92c7
Author: cumtwwei <19...@qq.com>
AuthorDate: Fri Sep 6 10:30:49 2019 +0800

    Update SnmpProducer.java
    
    add support to 'snmp walk', use the snmp4j 'GET_NEXT'
---
 .../apache/camel/component/snmp/SnmpProducer.java  | 69 ++++++++++++++++++----
 1 file changed, 57 insertions(+), 12 deletions(-)

diff --git a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpProducer.java b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpProducer.java
index 3cffe4a..cdcada8 100644
--- a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpProducer.java
+++ b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpProducer.java
@@ -74,13 +74,20 @@ public class SnmpProducer extends DefaultProducer {
         this.target.setVersion(this.endpoint.getSnmpVersion());
 
         this.pdu = new PDU();
-        for (OID oid : this.endpoint.getOids()) {
-            this.pdu.add(new VariableBinding(oid));
+        // in here,only POLL do set the oids
+        if (this.actionType == SnmpActionType.POLL) {
+            for (OID oid : this.endpoint.getOids()) {
+                this.pdu.add(new VariableBinding(oid));
+            }
         }
         this.pdu.setErrorIndex(0);
         this.pdu.setErrorStatus(0);
         this.pdu.setMaxRepetitions(0);
-        this.pdu.setType(PDU.GET);
+        // support POLL and GET_NEXT
+        if (this.actionType == SnmpActionType.GET_NEXT)
+          this.pdu.setType(PDU.GETNEXT);
+        else
+          this.pdu.setType(PDU.GET); 
         
     }
     
@@ -121,15 +128,53 @@ public class SnmpProducer extends DefaultProducer {
             log.debug("Snmp: i am sending");
     
             snmp.listen();
-            ResponseEvent responseEvent = snmp.send(this.pdu, this.target);
             
-            log.debug("Snmp: sended");
-    
-            if (responseEvent.getResponse() != null) {
-                exchange.getIn().setBody(new SnmpMessage(getEndpoint().getCamelContext(), responseEvent.getResponse()));
-            } else {
-                throw new TimeoutException("SNMP Producer Timeout");
-            }
+            if (this.actionType == SnmpActionType.GET_NEXT) {
+                // snmp walk
+                List<SnmpMessage> smLst = new ArrayList<>();
+                for (OID oid : this.endpoint.getOids()) {
+                    this.pdu.clear();
+                    this.pdu.add(new VariableBinding(oid));
+
+                    boolean matched = true;
+                    while (matched) {
+                        ResponseEvent responseEvent = snmp.send(this.pdu, this.target);
+                        if (responseEvent == null || responseEvent.getResponse() == null) {
+                            break;
+                        }
+                        PDU response = responseEvent.getResponse();
+                        String nextOid = null;
+                        Vector<? extends VariableBinding> variableBindings = response.getVariableBindings();
+                        for (int i = 0; i < variableBindings.size(); i++) {
+                            VariableBinding variableBinding = variableBindings.elementAt(i);
+                            Variable variable = variableBinding.getVariable();
+                            nextOid = variableBinding.getOid().toDottedString();
+                            if (!nextOid.startsWith(oid.toDottedString())) {
+                                matched = false;
+                                break;
+                            }
+                        }
+                        if (!matched) {
+                            break;
+                        }
+                        this.pdu.clear();
+                        pdu.add(new VariableBinding(new OID(nextOid)));
+                        smLst.add(new SnmpMessage(getEndpoint().getCamelContext(), response));
+                    }
+                }
+                exchange.getIn().setBody(smLst);
+              } else {
+                // snmp get
+                ResponseEvent responseEvent = snmp.send(this.pdu, this.target);
+
+                log.debug("Snmp: sended");
+
+                if (responseEvent.getResponse() != null) {
+                    exchange.getIn().setBody(new SnmpMessage(getEndpoint().getCamelContext(), responseEvent.getResponse()));
+                } else {
+                    throw new TimeoutException("SNMP Producer Timeout");
+                }
+              }
         } finally {
             try {
                 transport.close(); 
@@ -139,4 +184,4 @@ public class SnmpProducer extends DefaultProducer {
             } catch (Exception e) { }
         }
     } //end process
-}
\ No newline at end of file
+}


[camel] 01/03: Update SnmpEndpoint.java

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 77a461dd1a1603ad7a91b627ee04c1ea2fc39365
Author: cumtwwei <19...@qq.com>
AuthorDate: Fri Sep 6 10:25:06 2019 +0800

    Update SnmpEndpoint.java
    
    add the support to 'snmp walk', use snm4j GET_NEXT.
---
 .../src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java    | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java
index 7e86d721..0cacd74 100644
--- a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java
+++ b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpEndpoint.java
@@ -114,7 +114,8 @@ public class SnmpEndpoint extends DefaultPollingEndpoint {
         if (this.type == SnmpActionType.TRAP) {
             return new SnmpTrapProducer(this);
         } else {
-            return new SnmpProducer(this);
+            // add the support: snmp walk (use snmp4j GET_NEXT)
+            return new SnmpProducer(this, this.type);
         }
     }
 


[camel] 03/03: Create WalkOIDTest.java

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 558bd7b34aa5e9ea07b4899553a6b92567d09207
Author: cumtwwei <19...@qq.com>
AuthorDate: Fri Sep 6 10:36:39 2019 +0800

    Create WalkOIDTest.java
    
    the test for snmp walk
---
 .../apache/camel/component/snmp/WalkOIDTest.java   | 63 ++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/components/camel-snmp/src/test/java/org/apache/camel/component/snmp/WalkOIDTest.java b/components/camel-snmp/src/test/java/org/apache/camel/component/snmp/WalkOIDTest.java
new file mode 100644
index 0000000..acac3af
--- /dev/null
+++ b/components/camel-snmp/src/test/java/org/apache/camel/component/snmp/WalkOIDTest.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.snmp;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class WalkOIDTest extends CamelTestSupport {
+    private static final Logger LOG = LoggerFactory.getLogger(PollOIDTest.class);
+
+    // a disabled test... before enabling you must fill in a working IP, Port
+    // and maybe oids in the route below
+    @Ignore
+    @Test
+    public void testOIDWalk() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMinimumMessageCount(1);
+        mock.assertIsSatisfied();
+        List<Exchange> oids = mock.getExchanges();
+        if (LOG.isInfoEnabled()) {
+            for (Exchange e : oids) {
+                LOG.info("OID: " + e.getIn().getBody(String.class));
+            }
+        }
+    }
+    
+    @Test
+    public void testStartRoute() throws Exception {
+        // do nothing here , just make sure the camel route can started.
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                // START SNIPPET: e1
+                from("snmp:10.211.55.6:161?protocol=udp&type=GET_NEXT&oids=1.3.6.1.2.1.2.2.1.2,1.3.6.1.2.1.25.3.3.1.2").transform(body().convertToString()).to("mock:result");
+                // END SNIPPET: e1
+            }
+        };
+    }
+}