use of org.snmp4j.util.TreeEvent in project nifi by apache.
the class GetSNMP method onTriggerSnmp.
/**
* Delegate method to supplement
* {@link #onTrigger(ProcessContext, ProcessSession)}. It is implemented by
* sub-classes to perform {@link Processor} specific functionality.
*
* @param context
* instance of {@link ProcessContext}
* @param processSession
* instance of {@link ProcessSession}
* @throws ProcessException Process exception
*/
@Override
protected void onTriggerSnmp(ProcessContext context, ProcessSession processSession) throws ProcessException {
if ("GET".equals(context.getProperty(SNMP_STRATEGY).getValue())) {
final ResponseEvent response = this.targetResource.get();
if (response.getResponse() != null) {
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) {
processSession.transfer(flowFile, REL_SUCCESS);
} else {
processSession.transfer(flowFile, REL_FAILURE);
}
} else {
this.getLogger().error("Get request timed out or parameters are incorrect.");
context.yield();
}
} else if ("WALK".equals(context.getProperty(SNMP_STRATEGY).getValue())) {
final List<TreeEvent> events = this.targetResource.walk();
if ((events != null) && !events.isEmpty() && (events.get(0).getVariableBindings() != null)) {
FlowFile flowFile = processSession.create();
for (TreeEvent treeEvent : events) {
flowFile = SNMPUtils.updateFlowFileAttributesWithTreeEventProperties(treeEvent, flowFile, processSession);
}
processSession.getProvenanceReporter().receive(flowFile, this.snmpTarget.getAddress().toString() + "/" + context.getProperty(OID).getValue());
processSession.transfer(flowFile, REL_SUCCESS);
} else {
this.getLogger().error("Get request timed out or parameters are incorrect.");
context.yield();
}
}
}
use of org.snmp4j.util.TreeEvent in project nifi by apache.
the class SNMPGetter method walk.
/**
* Perform a SNMP walk and returns the list of {@link TreeEvent}
* @return the list of {@link TreeEvent}
*/
public List<TreeEvent> walk() {
TreeUtils treeUtils = new TreeUtils(this.snmp, new DefaultPDUFactory());
@SuppressWarnings("unchecked") List<TreeEvent> events = treeUtils.getSubtree(this.target, this.oid);
return events;
}
Aggregations