[ 
https://issues.apache.org/jira/browse/CAMEL-12519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16478722#comment-16478722
 ] 

ASF GitHub Bot commented on CAMEL-12519:
----------------------------------------

onderson closed pull request #2345: CAMEL-12519 add treeList option and the 
given PDU which has child ele…
URL: https://github.com/apache/camel/pull/2345
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/components/camel-snmp/src/main/docs/snmp-component.adoc 
b/components/camel-snmp/src/main/docs/snmp-component.adoc
index e80f4657103..a41987f2f36 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 af406c84366..e72c9edc693 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 @@
     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 void setSnmpContextEngineId(String 
snmpContextEngineId) {
         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 9d966a1c71d..c76b43434bb 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.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 @@ protected int poll() throws Exception {
         
         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


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> camel-snmp - add treeList option of given PDU has child elements but will be 
> resulted as list
> ---------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-12519
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12519
>             Project: Camel
>          Issue Type: Improvement
>            Reporter: Önder Sezgin
>            Assignee: Önder Sezgin
>            Priority: Minor
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to