mirror of https://github.com/apache/nifi.git
NIFI-3014 GetSNMP add textual oid attribute to flowfile
Signed-off-by: João Henrique Ferreira de Freitas <joaohf@gmail.com> Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #1196.
This commit is contained in:
parent
39cfd03397
commit
a62523c7f5
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue