@Test public void validateUpdateFlowFileAttributes() { GetSNMP processor = new GetSNMP(); ProcessSession processSession = new MockProcessSession(new SharedSessionState(processor, new AtomicLong()), processor); FlowFile sourceFlowFile = processSession.create(); PDU pdu = new PDU(); pdu.setErrorIndex(0); pdu.setErrorStatus(0); pdu.setType(4); FlowFile f2 = SNMPUtils.updateFlowFileAttributesWithPduProperties(pdu, sourceFlowFile, processSession); assertEquals("0", f2.getAttributes().get(SNMPUtils.SNMP_PROP_PREFIX + "errorIndex")); assertEquals("0", f2.getAttributes().get(SNMPUtils.SNMP_PROP_PREFIX + "errorStatus")); assertEquals("4", f2.getAttributes().get(SNMPUtils.SNMP_PROP_PREFIX + "type")); }
public static FlowFile updateFlowFileAttributesWithPduProperties(PDU response, FlowFile flowFile, ProcessSession processSession) { if (response != null) { try { Method[] methods = PDU.class.getDeclaredMethods(); Map<String, String> attributes = new HashMap<String, String>(); for (Method method : methods) { if (Modifier.isPublic(method.getModifiers()) && (method.getParameterTypes().length == 0) && method.getName().startsWith("get")) { String propertyName = extractPropertyNameFromMethod(method); if (isValidSnmpPropertyName(propertyName)) { Object amqpPropertyValue = method.invoke(response); if (amqpPropertyValue != null) { if (propertyName.equals(SNMP_PROP_PREFIX + "variableBindings") && (amqpPropertyValue instanceof Vector)) { addGetOidValues(attributes, amqpPropertyValue); } else { attributes.put(propertyName, amqpPropertyValue.toString()); } } } } } flowFile = processSession.putAllAttributes(flowFile, attributes); } catch (Exception e) { logger.warn("Failed to update FlowFile with AMQP attributes", e); } } return flowFile; }
SNMPUtils { public static FlowFile updateFlowFileAttributesWithPduProperties(PDU response, FlowFile flowFile, ProcessSession processSession) { if (response != null) { try { Method[] methods = PDU.class.getDeclaredMethods(); Map<String, String> attributes = new HashMap<String, String>(); for (Method method : methods) { if (Modifier.isPublic(method.getModifiers()) && (method.getParameterTypes().length == 0) && method.getName().startsWith("get")) { String propertyName = extractPropertyNameFromMethod(method); if (isValidSnmpPropertyName(propertyName)) { Object amqpPropertyValue = method.invoke(response); if (amqpPropertyValue != null) { if (propertyName.equals(SNMP_PROP_PREFIX + "variableBindings") && (amqpPropertyValue instanceof Vector)) { addGetOidValues(attributes, amqpPropertyValue); } else { attributes.put(propertyName, amqpPropertyValue.toString()); } } } } } flowFile = processSession.putAllAttributes(flowFile, attributes); } catch (Exception e) { logger.warn("Failed to update FlowFile with AMQP attributes", e); } } return flowFile; } }
SNMPUtils { public static FlowFile updateFlowFileAttributesWithPduProperties(PDU response, FlowFile flowFile, ProcessSession processSession) { if (response != null) { try { Method[] methods = PDU.class.getDeclaredMethods(); Map<String, String> attributes = new HashMap<String, String>(); for (Method method : methods) { if (Modifier.isPublic(method.getModifiers()) && (method.getParameterTypes().length == 0) && method.getName().startsWith("get")) { String propertyName = extractPropertyNameFromMethod(method); if (isValidSnmpPropertyName(propertyName)) { Object amqpPropertyValue = method.invoke(response); if (amqpPropertyValue != null) { if (propertyName.equals(SNMP_PROP_PREFIX + "variableBindings") && (amqpPropertyValue instanceof Vector)) { addGetOidValues(attributes, amqpPropertyValue); } else { attributes.put(propertyName, amqpPropertyValue.toString()); } } } } } flowFile = processSession.putAllAttributes(flowFile, attributes); } catch (Exception e) { logger.warn("Failed to update FlowFile with AMQP attributes", e); } } return flowFile; }  }
SNMPUtils { public static FlowFile updateFlowFileAttributesWithPduProperties(PDU response, FlowFile flowFile, ProcessSession processSession) { if (response != null) { try { Method[] methods = PDU.class.getDeclaredMethods(); Map<String, String> attributes = new HashMap<String, String>(); for (Method method : methods) { if (Modifier.isPublic(method.getModifiers()) && (method.getParameterTypes().length == 0) && method.getName().startsWith("get")) { String propertyName = extractPropertyNameFromMethod(method); if (isValidSnmpPropertyName(propertyName)) { Object amqpPropertyValue = method.invoke(response); if (amqpPropertyValue != null) { if (propertyName.equals(SNMP_PROP_PREFIX + "variableBindings") && (amqpPropertyValue instanceof Vector)) { addGetOidValues(attributes, amqpPropertyValue); } else { attributes.put(propertyName, amqpPropertyValue.toString()); } } } } } flowFile = processSession.putAllAttributes(flowFile, attributes); } catch (Exception e) { logger.warn("Failed to update FlowFile with AMQP attributes", e); } } return flowFile; }  static FlowFile updateFlowFileAttributesWithPduProperties(PDU response, FlowFile flowFile, ProcessSession processSession); static FlowFile addAttribute(String key, String value, FlowFile flowFile, ProcessSession processSession); static FlowFile updateFlowFileAttributesWithTreeEventProperties(TreeEvent treeEvent, FlowFile flowFile, ProcessSession processSession); static boolean isValidSnmpPropertyName(String name); static OID getPriv(String privProtocol); static OID getAuth(String authProtocol); static int getSecLevel(String level); }
SNMPUtils { public static FlowFile updateFlowFileAttributesWithPduProperties(PDU response, FlowFile flowFile, ProcessSession processSession) { if (response != null) { try { Method[] methods = PDU.class.getDeclaredMethods(); Map<String, String> attributes = new HashMap<String, String>(); for (Method method : methods) { if (Modifier.isPublic(method.getModifiers()) && (method.getParameterTypes().length == 0) && method.getName().startsWith("get")) { String propertyName = extractPropertyNameFromMethod(method); if (isValidSnmpPropertyName(propertyName)) { Object amqpPropertyValue = method.invoke(response); if (amqpPropertyValue != null) { if (propertyName.equals(SNMP_PROP_PREFIX + "variableBindings") && (amqpPropertyValue instanceof Vector)) { addGetOidValues(attributes, amqpPropertyValue); } else { attributes.put(propertyName, amqpPropertyValue.toString()); } } } } } flowFile = processSession.putAllAttributes(flowFile, attributes); } catch (Exception e) { logger.warn("Failed to update FlowFile with AMQP attributes", e); } } return flowFile; }  static FlowFile updateFlowFileAttributesWithPduProperties(PDU response, FlowFile flowFile, ProcessSession processSession); static FlowFile addAttribute(String key, String value, FlowFile flowFile, ProcessSession processSession); static FlowFile updateFlowFileAttributesWithTreeEventProperties(TreeEvent treeEvent, FlowFile flowFile, ProcessSession processSession); static boolean isValidSnmpPropertyName(String name); static OID getPriv(String privProtocol); static OID getAuth(String authProtocol); static int getSecLevel(String level); final static Pattern OID_PATTERN; final static String SNMP_PROP_DELIMITER; final static String SNMP_PROP_PREFIX; static final Validator SNMP_OID_VALIDATOR; }