Repository: nifi
Updated Branches:
  refs/heads/master 39cfd0339 -> a62523c7f


NIFI-3014 GetSNMP add textual oid attribute to flowfile

Signed-off-by: João Henrique Ferreira de Freitas <[email protected]>
Signed-off-by: Pierre Villard <[email protected]>

This closes #1196.


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/a62523c7
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/a62523c7
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/a62523c7

Branch: refs/heads/master
Commit: a62523c7f5747e29fa2d15ccc5f6f0b96484d4ca
Parents: 39cfd03
Author: João Henrique Ferreira de Freitas <[email protected]>
Authored: Fri Nov 4 09:32:32 2016 -0200
Committer: Pierre Villard <[email protected]>
Committed: Wed Feb 15 20:20:30 2017 +0100

----------------------------------------------------------------------
 .../apache/nifi/snmp/processors/GetSNMP.java    | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/a62523c7/nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/GetSNMP.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/GetSNMP.java
 
b/nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/GetSNMP.java
index bb59fe7..0a4654a 100644
--- 
a/nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/GetSNMP.java
+++ 
b/nifi-nar-bundles/nifi-snmp-bundle/nifi-snmp-processors/src/main/java/org/apache/nifi/snmp/processors/GetSNMP.java
@@ -24,6 +24,8 @@ import java.util.Set;
 
 import org.apache.nifi.annotation.behavior.InputRequirement;
 import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
 import org.apache.nifi.annotation.documentation.CapabilityDescription;
 import org.apache.nifi.annotation.documentation.Tags;
 import org.apache.nifi.components.PropertyDescriptor;
@@ -32,6 +34,7 @@ import org.apache.nifi.processor.ProcessContext;
 import org.apache.nifi.processor.ProcessSession;
 import org.apache.nifi.processor.Processor;
 import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.util.StandardValidators;
 import org.apache.nifi.processor.exception.ProcessException;
 import org.snmp4j.PDU;
 import org.snmp4j.event.ResponseEvent;
@@ -47,6 +50,12 @@ import org.snmp4j.util.TreeEvent;
 @Tags({ "snmp", "get", "oid", "walk" })
 @InputRequirement(Requirement.INPUT_FORBIDDEN)
 @CapabilityDescription("Retrieves information from SNMP Agent and outputs a 
FlowFile with information in attributes and without any content")
+@WritesAttributes({
+    @WritesAttribute(attribute=SNMPUtils.SNMP_PROP_PREFIX + "*", 
description="Attributes retrieved from the SNMP response. It may include:"
+            + " snmp$errorIndex, snmp$errorStatus, snmp$errorStatusText, 
snmp$nonRepeaters, snmp$requestID, snmp$type, snmp$variableBindings"),
+    @WritesAttribute(attribute=SNMPUtils.SNMP_PROP_PREFIX + "textualOid", 
description="This attribute will exist if and only if the strategy"
+            + " is GET and will be equal to the value given in Textual Oid 
property.")
+})
 public class GetSNMP extends AbstractSNMPProcessor<SNMPGetter> {
 
     /** OID to request (if walk, it is the root ID of the request) */
@@ -58,6 +67,16 @@ public class GetSNMP extends 
AbstractSNMPProcessor<SNMPGetter> {
             .addValidator(SNMPUtils.SNMP_OID_VALIDATOR)
             .build();
 
+    /** Textual OID to request */
+    public static final PropertyDescriptor TEXTUAL_OID = new 
PropertyDescriptor.Builder()
+            .name("snmp-textual-oid")
+            .displayName("Textual OID")
+            .description("The textual OID to request")
+            .required(false)
+            .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+            .defaultValue(null)
+            .build();
+
     /** SNMP strategy for SNMP Get processor : simple get or walk */
     public static final PropertyDescriptor SNMP_STRATEGY = new 
PropertyDescriptor.Builder()
             .name("snmp-strategy")
@@ -93,6 +112,7 @@ public class GetSNMP extends 
AbstractSNMPProcessor<SNMPGetter> {
     static {
         List<PropertyDescriptor> _propertyDescriptors = new ArrayList<>();
         _propertyDescriptors.add(OID);
+        _propertyDescriptors.add(TEXTUAL_OID);
         _propertyDescriptors.add(SNMP_STRATEGY);
         _propertyDescriptors.addAll(descriptors);
         propertyDescriptors = 
Collections.unmodifiableList(_propertyDescriptors);
@@ -122,6 +142,8 @@ public class GetSNMP extends 
AbstractSNMPProcessor<SNMPGetter> {
                 FlowFile flowFile = processSession.create();
                 PDU pdu = response.getResponse();
                 flowFile = 
SNMPUtils.updateFlowFileAttributesWithPduProperties(pdu, flowFile, 
processSession);
+                flowFile = SNMPUtils.addAttribute(SNMPUtils.SNMP_PROP_PREFIX + 
"textualOid",
+                        context.getProperty(TEXTUAL_OID).getValue(), flowFile, 
processSession);
                 processSession.getProvenanceReporter().receive(flowFile,
                         this.snmpTarget.getAddress().toString() + "/" + 
context.getProperty(OID).getValue());
                 if(pdu.getErrorStatus() == PDU.noError) {

Reply via email to