/** * Construct the PDU to perform the SNMP Get request and returns * the result in order to create the flow file. * @return {@link ResponseEvent} */ public ResponseEvent get() { try { PDU pdu = null; if(this.target.getVersion() == SnmpConstants.version3) { pdu = new ScopedPDU(); } else { pdu = new PDU(); } pdu.add(new VariableBinding(this.oid)); pdu.setType(PDU.GET); return this.snmp.get(pdu, this.target); } catch (IOException e) { logger.error("Failed to get information from SNMP agent; " + this, e); throw new ProcessException(e); } }
pdu.setType(PDU.SET); try { ResponseEvent response = this.targetResource.set(pdu);
public static void main(String[] args) throws Exception { // Create PDU PDU trap = new PDU(); trap.setType(PDU.TRAP); OID oid = new OID("1.2.3.4.5"); trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid)); trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000))); // put your uptime here trap.add(new VariableBinding(SnmpConstants.sysDescr, new OctetString("System Description"))); //Add Payload Variable var = new OctetString("some string"); trap.add(new VariableBinding(oid, var)); // Specify receiver Address targetaddress = new UdpAddress("10.101.21.32/162"); CommunityTarget target = new CommunityTarget(); target.setCommunity(new OctetString("public")); target.setVersion(SnmpConstants.version2c); target.setAddress(targetaddress); // Send Snmp snmp = new Snmp(new DefaultUdpTransportMapping()); snmp.send(trap, target, null, null); }
protected Snmp4JV2TrapBuilder(Snmp4JStrategy strategy, PDU pdu, int type) { m_strategy = strategy; m_pdu = pdu; m_pdu.setType(type); }
protected Snmp4JV2TrapBuilder(Snmp4JStrategy strategy, PDU pdu, int type) { m_strategy = strategy; m_pdu = pdu; m_pdu.setType(type); }
protected Snmp4JV2TrapBuilder(Snmp4JStrategy strategy, PDU pdu, int type) { m_strategy = strategy; m_pdu = pdu; m_pdu.setType(type); }
private PDU createPDU(SnmpTrapInfo snmpTrapInfo) { PDU trap = new PDU(); trap.setType(PDU.TRAP);
protected PDU sendGetPDU(Row firstCacheRow, ResponseListener responseListener, PDU pdu) { try { session.send(pdu, target, firstCacheRow, responseListener); pdu = pduFactory.createPDU(target); pdu.setType(PDU.GET); } catch (IOException e) { logger.error(e); } return pdu; }
private PDU buildDeletPDU(Object entry) throws IllegalArgumentException, IllegalAccessException, SnmpAnnotationException { PDU pdu = new PDU(); pdu.setType(PDU.SET); pdu.add(buildDeleteVariableBinding(entry)); return pdu; } }
/** * Creates an SNMP4J PDU based on the SNMP4J version constants. * A v3 request requires a ScopedPDU. * * @param type * @return */ public PDU createPdu(int type) { PDU pdu = getVersion() == SnmpConstants.version3 ? new ScopedPDU() : new PDU(); pdu.setType(type); return pdu; }
public PDU buildGetPDU(Class scalarClass, String[] fields) throws SecurityException, NoSuchFieldException { PDU pdu = new PDU(); pdu.setType(PDU.GET); for (String fn : fields) { Field field = scalarClass.getDeclaredField(fn); MibObjectType mib = field.getAnnotation(MibObjectType.class); pdu.add(new VariableBinding(new OID(mib.oid()))); } return pdu; }
public SnmpUriResponse updateByValue(URI url, List<Variable> values) throws UnknownHostException { SnmpUriResponse response; Request request = createSnmpRequest(url); PDU pdu = request.getPdu(); pdu.setType(PDU.SET); OID[] oids = request.getOIDs(); for (int i=0; i<oids.length && i<values.size(); i++) { pdu.add(new VariableBinding(oids[i], values.get(i))); } response = sendSnmpRequest(request, pdu); return response; }
public SnmpUriResponse updateByValue(URI url, List<Variable> values) throws UnknownHostException { SnmpUriResponse response; Request request = createSnmpRequest(url); PDU pdu = request.getPdu(); pdu.setType(PDU.SET); OID[] oids = request.getOIDs(); for (int i=0; i<oids.length && i<values.size(); i++) { pdu.add(new VariableBinding(oids[i], values.get(i))); } response = sendSnmpRequest(request, pdu); return response; }
public ResponseEvent get(List<OID> oids) throws IOException { PDU pdu = new PDU(); for (OID oid : oids) { pdu.add(new VariableBinding(oid)); } pdu.setType(PDU.GET); ResponseEvent event = snmp.send(pdu, getTarget(), null); if(event != null) { return event; } throw new RuntimeException("GET timed out"); }
public SnmpUriResponse sendByBinding(URI url, List<VariableBinding> values, int pduType) throws UnknownHostException { SnmpUriResponse response; Request request = createSnmpRequest(url); PDU pdu = request.getPdu(); pdu.setType(pduType); for (VariableBinding vb : values) { pdu.add(vb); } response = sendSnmpRequest(request, pdu); return response; }
public SnmpUriResponse sendByBinding(URI url, List<VariableBinding> values, int pduType) throws UnknownHostException { SnmpUriResponse response; Request request = createSnmpRequest(url); PDU pdu = request.getPdu(); pdu.setType(pduType); for (VariableBinding vb : values) { pdu.add(vb); } response = sendSnmpRequest(request, pdu); return response; }
@Override public void poll() throws Exception { this.pdu.clear(); this.pdu.setType(PDU.GET); // prepare the request items for (OID oid : oids) { this.pdu.add(new VariableBinding(oid)); } // send the request snmp.send(pdu, target, null, this); }
private PDU createResponse() { PDU resp = (PDU) requestEvent.getPDU().clone(); resp.clear(); resp.setType(PDU.RESPONSE); resp.setRequestID(requestEvent.getPDU().getRequestID()); resp.setErrorIndex(0); resp.setErrorStatus(PDU.noError); return resp; }
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; }
private PDU createResponse() { PDU resp = (PDU) source.getPDU().clone(); resp.clear(); resp.setType(PDU.RESPONSE); resp.setRequestID(source.getPDU().getRequestID()); resp.setErrorIndex(0); resp.setErrorStatus(PDU.noError); return resp; }