From a62523c7f5747e29fa2d15ccc5f6f0b96484d4ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Henrique=20Ferreira=20de=20Freitas?= Date: Fri, 4 Nov 2016 09:32:32 -0200 Subject: [PATCH] NIFI-3014 GetSNMP add textual oid attribute to flowfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Henrique Ferreira de Freitas Signed-off-by: Pierre Villard This closes #1196. --- .../apache/nifi/snmp/processors/GetSNMP.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 bb59fe7ec6..0a4654a748 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 { /** OID to request (if walk, it is the root ID of the request) */ @@ -58,6 +67,16 @@ public class GetSNMP extends AbstractSNMPProcessor { .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 { static { List _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 { 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) {