private void checkOptions() { if ((operation == WALK) && ((pduType != PDU.GETBULK) && (pduType != PDU.GETNEXT))) { throw new IllegalArgumentException( "Walk operation is not supported for PDU type: "+ PDU.getTypeString(pduType)); } else if ((operation == WALK) && (vbs.size() != 1)) { throw new IllegalArgumentException( "There must be exactly one OID supplied for walk operations"); } if ((pduType == PDU.V1TRAP) && (version != SnmpConstants.version1)) { throw new IllegalArgumentException( "V1TRAP PDU type is only available for SNMP version 1"); } }
private void checkOptions() { if ((operation == WALK) && ((pduType != PDU.GETBULK) && (pduType != PDU.GETNEXT))) { throw new IllegalArgumentException( "Walk operation is not supported for PDU type: "+ PDU.getTypeString(pduType)); } else if ((operation == WALK) && (vbs.size() != 1)) { throw new IllegalArgumentException( "There must be exactly one OID supplied for walk operations"); } if ((pduType == PDU.V1TRAP) && (version != SnmpConstants.version1)) { throw new IllegalArgumentException( "V1TRAP PDU type is only available for SNMP version 1"); } }
/** * Constructs a new trap information instance that contains the sending * agent, the community string, and the Protocol Data Unit. * * @param agent * The sending agent's address * @param community * The community string from the SNMP packet. * @param pdu * The encapsulated Protocol Data Unit. */ public Snmp4JV2TrapInformation(InetAddress agent, String community, PDU pdu) { super(agent, community); m_pdu = pdu; m_pduTypeString = PDU.getTypeString(m_pdu.getType()); }
/** * Constructs a new trap information instance that contains the sending * agent, the community string, and the Protocol Data Unit. * * @param agent * The sending agent's address * @param community * The community string from the SNMP packet. * @param pdu * The encapsulated Protocol Data Unit. * @param trapProcessor The trap processor used to process the trap data * */ public Snmp4JV2TrapInformation(InetAddress agent, String community, PDU pdu, TrapProcessor trapProcessor) { super(agent, community, trapProcessor); m_pdu = pdu; m_pduTypeString = PDU.getTypeString(m_pdu.getType()); }
/** * Constructs a new trap information instance that contains the sending * agent, the community string, and the Protocol Data Unit. * * @param agent * The sending agent's address * @param community * The community string from the SNMP packet. * @param pdu * The encapsulated Protocol Data Unit. */ public Snmp4JV2TrapInformation(InetAddress agent, String community, PDU pdu) { super(agent, community); m_pdu = pdu; m_pduTypeString = PDU.getTypeString(m_pdu.getType()); }
/** * Returns a string representation of the object. * * @return a string representation of the object. */ public String toString() { StringBuilder buf = new StringBuilder(); buf.append(getTypeString(type)); buf.append("[requestID="); buf.append(requestID); buf.append(", errorStatus="); buf.append(getErrorStatusText()).append("(").append(errorStatus).append(")"); buf.append(", errorIndex="); buf.append(errorIndex); buf.append(", VBS["); for (int i = 0; i < variableBindings.size(); i++) { buf.append(variableBindings.get(i)); if (i + 1 < variableBindings.size()) { buf.append("; "); } } buf.append("]]"); return buf.toString(); }
/** * Returns a string representation of the object. * * @return a string representation of the object. */ public String toString() { StringBuffer buf = new StringBuffer(); buf.append(getTypeString(type)); buf.append("[requestID="); buf.append(requestID); buf.append(", errorStatus="); buf.append(getErrorStatusText()+"("+errorStatus+")"); buf.append(", errorIndex="); buf.append(errorIndex); buf.append(", VBS["); for (int i=0; i<variableBindings.size(); i++) { buf.append(variableBindings.get(i)); if (i+1 < variableBindings.size()) { buf.append("; "); } } buf.append("]]"); return buf.toString(); }
/** * Returns a string representation of the object. * * @return a string representation of the object. */ public String toString() { StringBuilder buf = new StringBuilder(); buf.append(getTypeString(type)); buf.append("[requestID="); buf.append(requestID); buf.append(", errorStatus="); buf.append(getErrorStatusText()).append("(").append(errorStatus).append(")"); buf.append(", errorIndex="); buf.append(errorIndex); buf.append(", VBS["); for (int i=0; i<variableBindings.size(); i++) { buf.append(variableBindings.get(i)); if (i+1 < variableBindings.size()) { buf.append("; "); } } buf.append("]]"); return buf.toString(); }
@Override public void processPdu(CommandResponderEvent e) { PDU pdu = e.getPDU(); if (pdu != null){ if (pdu instanceof PDUv1){ processPDUv1((PDUv1)pdu); } else if (pdu instanceof ScopedPDU) { processScopedPDU((ScopedPDU)pdu); } else if (pdu instanceof PDU){ processPDUv2c(pdu); } else { log.warn("Unknown PDU type: " + PDU.getTypeString(pdu.getType())); } } }
@Override public void processPdu(CommandResponderEvent e) { PDU pdu = e.getPDU(); if (pdu != null){ if (pdu instanceof PDUv1){ processPDUv1((PDUv1)pdu); } else if (pdu instanceof ScopedPDU) { processScopedPDU((ScopedPDU)pdu); } else if (pdu instanceof PDU){ processPDUv2c(pdu); } else { log.warn("Unknown PDU type: " + PDU.getTypeString(pdu.getType())); } } }
log.debug("Received Snmp request of type: "+PDU.getTypeString(pdu.getType())); default: log.warn("Cannot process request PDU of type: " + PDU.getTypeString(type) + "unsupported"); return;
log.debug("Received Snmp request of type: "+PDU.getTypeString(pdu.getType())); default: log.warn("Cannot process request PDU of type: " + PDU.getTypeString(type) + "unsupported"); return;
(snmpRequest.getPduType() == PDU.V1TRAP) || (snmpRequest.getPduType() == PDU.RESPONSE)) { System.out.println(PDU.getTypeString(snmpRequest.getPduType()) + " sent successfully");
(pduType == PDU.V1TRAP) || (pduType == PDU.RESPONSE)) { out.println(PDU.getTypeString(pduType) + " sent successfully"); } else if (response == null) {
protected void validate() { int pduType = getPdu().getType(); if (pduType != PDU.TRAP && pduType != PDU.INFORM) { throw new IllegalArgumentException("Received not SNMPv2 Trap|Inform from host " + getTrapAddress() + " PDU Type = " + PDU.getTypeString(getPdu().getType()));
private void processResponse(final PDU response) throws SnmpException { try { LOG.debug("Received a tracker PDU of type {} from {} of size {}, errorStatus = {}, errorStatusText = {}, errorIndex = {}", PDU.getTypeString(response.getType()), getAddress(), response.size(), response.getErrorStatus(), response.getErrorStatusText(), response.getErrorIndex()); if (response.getType() == PDU.REPORT) { handleAuthError("A REPORT PDU was returned from the agent. This is most likely an authentication problem. Please check the config"); } else { if (!processErrors(response.getErrorStatus(), response.getErrorIndex())) { if (response.size() == 0) { // NMS-6484 handleError("A PDU with no errors and 0 varbinds was returned from the agent at " + getAddress() + ". This seems to be related with a broken SNMP agent."); } else { for (int i = 0; i < response.size(); i++) { final VariableBinding vb = response.get(i); final SnmpObjId receivedOid = SnmpObjId.get(vb.getOid().getValue()); final SnmpValue val = new Snmp4JValue(vb.getVariable()); Snmp4JWalker.this.processResponse(receivedOid, val); } } } buildAndSendNextPdu(); } } catch (final RuntimeException|SnmpException e) { handleFatalError(e); } }
private void processResponse(final PDU response) throws SnmpException { try { LOG.debug("Received a tracker PDU of type {} from {} of size {}, errorStatus = {}, errorStatusText = {}, errorIndex = {}", PDU.getTypeString(response.getType()), getAddress(), response.size(), response.getErrorStatus(), response.getErrorStatusText(), response.getErrorIndex()); if (response.getType() == PDU.REPORT) { handleAuthError("A REPORT PDU was returned from the agent. This is most likely an authentication problem. Please check the config"); } else { if (!processErrors(response.getErrorStatus(), response.getErrorIndex())) { if (response.size() == 0) { // NMS-6484 handleError("A PDU with no errors and 0 varbinds was returned from the agent at " + getAddress() + ". This seems to be related with a broken SNMP agent."); } else { for (int i = 0; i < response.size(); i++) { final VariableBinding vb = response.get(i); final SnmpObjId receivedOid = SnmpObjId.get(vb.getOid().getValue()); final SnmpValue val = new Snmp4JValue(vb.getVariable()); Snmp4JWalker.this.processResponse(receivedOid, val); } } } buildAndSendNextPdu(); } } catch (final RuntimeException|SnmpException e) { handleFatalError(e); } }
int pduType = getPdu().getType(); if (pduType != PDU.TRAP && pduType != PDU.INFORM) { throw new SnmpException("Received not SNMPv2 Trap|Inform from host " + getTrapAddress() + " PDU Type = " + PDU.getTypeString(getPdu().getType()));
int pduType = getPdu().getType(); if (pduType != PDU.TRAP && pduType != PDU.INFORM) { throw new SnmpException("Received not SNMPv2 Trap|Inform from host " + getTrapAddress() + " PDU Type = " + PDU.getTypeString(getPdu().getType()));
private void processResponse(PDU response) { try { if (log().isDebugEnabled()) { log().debug("Received a tracker PDU of type "+PDU.getTypeString(response.getType())+" from "+getAddress()+" of size "+response.size()+", errorStatus = "+response.getErrorStatus()+", errorStatusText = "+response.getErrorStatusText()+", errorIndex = "+response.getErrorIndex()); } if (response.getType() == PDU.REPORT) { handleAuthError("A REPORT PDU was returned from the agent. This is most likely an authentication problem. Please check the config"); } else { if (!processErrors(response.getErrorStatus(), response.getErrorIndex())) { for (int i = 0; i < response.size(); i++) { VariableBinding vb = response.get(i); SnmpObjId receivedOid = SnmpObjId.get(vb.getOid().getValue()); SnmpValue val = new Snmp4JValue(vb.getVariable()); Snmp4JWalker.this.processResponse(receivedOid, val); } } buildAndSendNextPdu(); } } catch (Throwable e) { handleFatalError(e); } }