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",
try { ResponseEvent response = this.targetResource.set(pdu); if(response.getResponse() == null) { processSession.transfer(processSession.penalize(flowFile), REL_FAILURE); this.getLogger().error("Set request timed out or parameters are incorrect."); context.yield(); } else if(response.getResponse().getErrorStatus() == PDU.noError) { flowFile = SNMPUtils.updateFlowFileAttributesWithPduProperties(pdu, flowFile, processSession); processSession.transfer(flowFile, REL_SUCCESS); processSession.getProvenanceReporter().send(flowFile, this.snmpTarget.getAddress().toString()); } else { final String error = response.getResponse().getErrorStatusText(); flowFile = SNMPUtils.addAttribute(SNMPUtils.SNMP_PROP_PREFIX + "error", error, flowFile, processSession); processSession.transfer(processSession.penalize(flowFile), REL_FAILURE);
IResponseListener listener = new IResponseListener() { public void response(ResponseEvent event) { float f = event.getResponse(); } };
private static SnmpValue[] convertResponseToValues(ResponseEvent responseEvent) { SnmpValue[] retvalues = new Snmp4JValue[responseEvent.getResponse().getVariableBindings().size()]; for (int i = 0; i < retvalues.length; i++) { retvalues[i] = new Snmp4JValue(responseEvent.getResponse().get(i).getVariable()); } return retvalues; }
private static SnmpValue[] convertResponseToValues(ResponseEvent responseEvent) { SnmpValue[] retvalues = new Snmp4JValue[responseEvent.getResponse().getVariableBindings().size()]; for (int i = 0; i < retvalues.length; i++) { retvalues[i] = new Snmp4JValue(responseEvent.getResponse().get(i).getVariable()); } return retvalues; }
private SnmpValue[] convertResponseToValues(ResponseEvent responseEvent) { SnmpValue[] retvalues = new Snmp4JValue[responseEvent.getResponse().getVariableBindings().size()]; for (int i = 0; i < retvalues.length; i++) { retvalues[i] = new Snmp4JValue(responseEvent.getResponse().get(i).getVariable()); } return retvalues; }
/** * Called when a response from a GET is received * * @see org.snmp4j.event.ResponseListener#onResponse(org.snmp4j.event.ResponseEvent ) */ @Override public void onResponse(ResponseEvent event) { dispatchPdu(event.getPeerAddress(), event.getResponse()); }
public void onResponse(ResponseEvent event) { // Always cancel async request when response has been received // otherwise a memory leak is created! Not canceling a request // immediately can be useful when sending a request to a broadcast address. ((Snmp)event.getSource()).cancel(event.getRequest(), this); // check for valid response if (event.getRequest() == null || event.getResponse() == null) { // ignore null requests/responses LOG.debug("Received invalid SNMP event. Request: " + event.getRequest() + " / Response: " + event.getResponse()); return; } PDU pdu = event.getResponse(); processPDU(pdu); }
private void processRegisterResponse(ResponseEvent responseReceivedEvent) throws TransactionUnavailableException, ParseException, InvalidArgumentException, SipException, NoSuchAlgorithmException { Response response = (Response) responseReceivedEvent.getResponse(); if(response.getStatusCode() == Response.UNAUTHORIZED) { sendRegister(response); } else if (response.getStatusCode() == Response.OK) { contactHeader=(ContactHeader)response.getHeader(ContactHeader.NAME); sendInvite(); } }
public int getAsInt(OID oid) throws IOException { ResponseEvent event = get(Arrays.asList(oid)); return event.getResponse().get(0).getVariable().toInt(); }
public long getAsLong(OID oid) throws IOException { ResponseEvent event = get(Arrays.asList(oid)); return event.getResponse().get(0).getVariable().toLong(); }
public String getAsString(OID oid) throws IOException { ResponseEvent event = get(Arrays.asList(oid)); return event.getResponse().get(0).getVariable().toString(); }
public static String extractSingleString(ResponseEvent event) { return event.getResponse().get(0).getVariable().toString(); } }
public String getAsString(OID oid) throws IOException { ResponseEvent event = get(new OID[]{oid}); return event.getResponse().get(0).getVariable().toString(); }
private <T> T get(Class<T> scalarClass, PDU requestPDU) throws IOException, SnmpException, SnmpAnnotationException { try { checkRequestError(requestPDU); ResponseEvent event = getSnmp().get(requestPDU, snmpSession.getReadTarget()); checkEventError(event); PDU responsePDU = event.getResponse(); checkResponseError(responsePDU); T mibObj = scalarClass.newInstance(); populateProperties(mibObj, responsePDU); return mibObj; } catch (InstantiationException | IllegalAccessException e) { throw new SnmpAnnotationException(e); } }
private <T> T getEntryByIndex(T entry, PDU requestPDU) throws IOException, SnmpException, InstantiationException, IllegalAccessException { checkRequestError(requestPDU); ResponseEvent event = getSnmp().get(requestPDU, snmpSession.getReadTarget()); checkEventError(event); PDU responsePDU = event.getResponse(); checkResponseError(responsePDU); populateProperties(entry, responsePDU); return entry; }
public void create(Object entry) throws IOException, SnmpException, SnmpAnnotationException { try { PDU requestPDU = buildCreatePDU(entry); checkRequestError(requestPDU); ResponseEvent event = getSnmp().set(requestPDU, snmpSession.getWriteTarget()); checkEventError(event); PDU responsePDU = event.getResponse(); checkResponseError(responsePDU); } catch (IllegalArgumentException | IllegalAccessException | SecurityException | NoSuchMethodException | InstantiationException | InvocationTargetException e) { throw new SnmpAnnotationException(e); } }
public void delete(Object entry) throws IOException, SnmpException, SnmpAnnotationException { try { PDU requestPDU = buildDeletPDU(entry); checkRequestError(requestPDU); ResponseEvent event = getSnmp().set(requestPDU, snmpSession.getWriteTarget()); checkEventError(event); PDU responsePDU = event.getResponse(); checkResponseError(responsePDU); } catch (IllegalArgumentException | IllegalAccessException e) { throw new SnmpAnnotationException(e); } }
public void set(Object entry) throws IOException, SnmpException, SnmpAnnotationException { try { PDU requestPDU = buildSetPDU(entry); checkRequestError(requestPDU); ResponseEvent event = getSnmp().set(requestPDU, snmpSession.getWriteTarget()); checkEventError(event); PDU responsePDU = event.getResponse(); checkResponseError(responsePDU); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | SecurityException | NoSuchMethodException | InvocationTargetException e) { throw new SnmpAnnotationException(e); } }
private VariableBinding getSingleVariable(OID oid) throws IOException { PDU pdu = this.pduFactory.createPDU(getTarget()); pdu.setType(PDU.GETNEXT); pdu.add(new VariableBinding(oid)); ResponseEvent responseEvent = snmp.send(pdu, getTarget()); PDU responsePDU = null; if (responseEvent != null) responsePDU = responseEvent.getResponse(); VariableBinding vb = null; if (responsePDU != null) vb = responsePDU.get(0); return vb; }