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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4439247  CAMEL-12519 add treeList option and the given PDU which has 
child elements will be resulted as list or will be added to list
4439247 is described below

commit 4439247b4501791887bf05fe6f42126769f970a5
Author: Sezgin <onder.sez...@nokia.com>
AuthorDate: Thu May 17 09:53:48 2018 +0300

    CAMEL-12519 add treeList option and the given PDU which has child elements 
will be resulted as list or will be added to list
    
    CAMEL-12519 - code review adjustment
---
 .../camel-snmp/src/main/docs/snmp-component.adoc   |  3 +-
 .../apache/camel/component/snmp/SnmpEndpoint.java  | 14 ++++++++
 .../apache/camel/component/snmp/SnmpOIDPoller.java | 39 ++++++++++++++++++++--
 3 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/components/camel-snmp/src/main/docs/snmp-component.adoc 
b/components/camel-snmp/src/main/docs/snmp-component.adoc
index e80f465..a41987f 100644
--- a/components/camel-snmp/src/main/docs/snmp-component.adoc
+++ b/components/camel-snmp/src/main/docs/snmp-component.adoc
@@ -68,7 +68,7 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (34 parameters):
+==== Query Parameters (35 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -85,6 +85,7 @@ with the following path and query parameters:
 | *snmpContextName* (consumer) | Sets the context name field of this scoped 
PDU. |  | String
 | *snmpVersion* (consumer) | Sets the snmp version for the request. The value 
0 means SNMPv1, 1 means SNMPv2c, and the value 3 means SNMPv3 | 0 | int
 | *timeout* (consumer) | Sets the timeout value for the request in millis. | 
1500 | int
+| *treeList* (consumer) | Sets the flag whether the scoped PDU will be 
displayed as the list if it has got child elements in its tree | false | boolean
 | *type* (consumer) | Which operation to perform such as poll, trap, etc. |  | 
SnmpActionType
 | *exceptionHandler* (consumer) | To let the consumer use a custom 
ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this 
options is not in use. By default the consumer will deal with exceptions, that 
will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer 
creates an exchange. |  | ExchangePattern
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 af406c8..e72c9ed 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
@@ -85,6 +85,8 @@ public class SnmpEndpoint extends DefaultPollingEndpoint {
     private String snmpContextEngineId;
     @UriParam(javaType = "java.lang.String")
     private OIDList oids = new OIDList();
+    @UriParam(label = "consumer", defaultValue = "false")
+    private boolean treeList;
 
     /**
      * creates a snmp endpoint
@@ -387,6 +389,18 @@ public class SnmpEndpoint extends DefaultPollingEndpoint {
         this.snmpContextEngineId = snmpContextEngineId;
     }
 
+    public boolean isTreeList() {
+        return treeList;
+    }
+
+    /**
+     * Sets the flag whether the scoped PDU will be displayed as the list
+     * if it has child elements in its tree
+     */
+    public void setTreeList(boolean treeList) {
+        this.treeList = treeList;
+    }
+
     @Override
     public String toString() {
         // only show address to avoid user and password details to be shown
diff --git 
a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpOIDPoller.java
 
b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpOIDPoller.java
index 9d966a1..c76b434 100644
--- 
a/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpOIDPoller.java
+++ 
b/components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpOIDPoller.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.snmp;
 
+import java.util.List;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.impl.ScheduledPollConsumer;
@@ -50,6 +52,9 @@ import org.snmp4j.smi.OctetString;
 import org.snmp4j.smi.VariableBinding;
 import org.snmp4j.transport.DefaultTcpTransportMapping;
 import org.snmp4j.transport.DefaultUdpTransportMapping;
+import org.snmp4j.util.DefaultPDUFactory;
+import org.snmp4j.util.TreeEvent;
+import org.snmp4j.util.TreeUtils;
 
 public class SnmpOIDPoller extends ScheduledPollConsumer implements 
ResponseListener {
 
@@ -167,9 +172,37 @@ public class SnmpOIDPoller extends ScheduledPollConsumer 
implements ResponseList
         
         this.pdu.setType(type);
 
-        // prepare the request items
-        for (OID oid : this.endpoint.getOids()) {
-            this.pdu.add(new VariableBinding(oid));
+        if (!endpoint.isTreeList()) {
+            // prepare the request items
+            for (OID oid : this.endpoint.getOids()) {
+                this.pdu.add(new VariableBinding(oid));
+            }
+        } else {
+            TreeUtils treeUtils = new TreeUtils(snmp, new DefaultPDUFactory());
+            for (OID oid : this.endpoint.getOids()) {
+                List events = treeUtils.getSubtree(target, new OID(oid));
+                for (Object eventObj : events) {
+                    TreeEvent event = (TreeEvent) eventObj;
+                    if (event == null) {
+                        LOG.warn("Event is null");
+                        continue;
+                    }
+                    if (event.isError()) {
+                        LOG.error("Error in event: {}", 
event.getErrorMessage());
+                        continue;
+                    }
+                    VariableBinding[] varBindings = 
event.getVariableBindings();
+                    if (varBindings == null || varBindings.length == 0) {
+                        continue;
+                    }
+                    for (VariableBinding varBinding : varBindings) {
+                        if (varBinding == null) {
+                            continue;
+                        }
+                        this.pdu.add(varBinding);
+                    }
+                }
+            }
         }
 
         // send the request

-- 
To stop receiving notification emails like this one, please contact
ond...@apache.org.

Reply via email to