Examples of PDU


Examples of org.snmp4j.PDU

    target.setRetries(0);
    target.setTimeout(timeout/2);
    return target;
  }
  private PDU createPDU(Target target, String contextEngine, String contextName) {
    PDU request;
    if (target.getVersion() == SnmpConstants.version3) {
      request = new ScopedPDU();
      ScopedPDU scopedPDU = (ScopedPDU)request;
      if (contextEngine != null) {
        scopedPDU.setContextEngineID(OctetString.fromHexStringPairs(contextEngine));
      }
      if (contextName != null) {
        scopedPDU.setContextName(new OctetString(contextName));
      }
    }
    else {
      request = new PDU();
    }
    request.setType(PDU.GET);
    return request;
  }
View Full Code Here

Examples of org.snmp4j.PDU

            throw new CloudRuntimeException(" Error in sending SNMP Trap, " + e.getMessage());
        }
    }

    private PDU createPDU(SnmpTrapInfo snmpTrapInfo) {
        PDU trap = new PDU();
        trap.setType(PDU.TRAP);

        int alertType = snmpTrapInfo.getAlertType() + 1;
        if (alertType > 0) {
            trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, getOID(CsSnmpConstants.TRAPS_PREFIX + alertType)));
            if (snmpTrapInfo.getDataCenterId() != 0) {
                trap.add(new VariableBinding(getOID(CsSnmpConstants.DATA_CENTER_ID),
                    new UnsignedInteger32(snmpTrapInfo.getDataCenterId())));
            }

            if (snmpTrapInfo.getPodId() != 0) {
                trap.add(new VariableBinding(getOID(CsSnmpConstants.POD_ID), new UnsignedInteger32(snmpTrapInfo
                    .getPodId())));
            }

            if (snmpTrapInfo.getClusterId() != 0) {
                trap.add(new VariableBinding(getOID(CsSnmpConstants.CLUSTER_ID), new UnsignedInteger32(snmpTrapInfo
                    .getClusterId())));
            }

            if (snmpTrapInfo.getMessage() != null) {
                trap.add(new VariableBinding(getOID(CsSnmpConstants.MESSAGE), new OctetString(snmpTrapInfo.getMessage
                    ())));
            } else {
                throw new CloudRuntimeException(" What is the use of alert without message ");
            }

            if (snmpTrapInfo.getGenerationTime() != null) {
                trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME),
                    new OctetString(snmpTrapInfo.getGenerationTime().toString())));
            } else {
                trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME)));
            }
        } else {
            throw new CloudRuntimeException(" Invalid alert Type ");
        }
View Full Code Here

Examples of org.snmp4j.PDU

            target.setAddress(address);
            target.setRetries(retries);
            target.setTimeout(timeout);
            snmp.listen();

            PDU request = createPDU(target);
            if (request.getType() == PDU.GETBULK) {
                request.setMaxRepetitions(maxRepetitions);
                request.setNonRepeaters(nonRepeaters);
            }

            for (Object vb : vbs) {
                request.add((VariableBinding) vb);
            }

            PDU response = null;
            ResponseEvent responseEvent;
            long startTime = System.currentTimeMillis();
            responseEvent = snmp.send(request, target);
            if (responseEvent != null) {
                response = responseEvent.getResponse();
View Full Code Here

Examples of org.snmp4j.PDU

     * processPdu
     *
     * @param e CommandResponderEvent
     */
    public synchronized void processPdu(CommandResponderEvent e) {
        PDU command = e.getPDU();
        if (command != null) {
            if (log.isDebugEnabled())
                log.debug(command.toString());
            if ((command.getType() != PDU.TRAP) && (command.getType() != PDU.V1TRAP)
                && (command.getType() != PDU.REPORT) && (command.getType() != PDU.RESPONSE)) {
                command.setErrorIndex(0);
                command.setErrorStatus(0);
                command.setType(PDU.RESPONSE);
                StatusInformation statusInformation = new StatusInformation();
                StateReference ref = e.getStateReference();
                try {
                    e.getMessageDispatcher().returnResponsePdu(e.getMessageProcessingModel(), e.getSecurityModel(),
                        e.getSecurityName(), e.getSecurityLevel(), command, e.getMaxSizeResponsePDU(), ref,
View Full Code Here

Examples of org.snmp4j.PDU

            }
        }
    }

    public PDU createPDU(Target target) {
        PDU request;
        if (target.getVersion() == SnmpConstants.version3) {
            request = new ScopedPDU();
            ScopedPDU scopedPDU = (ScopedPDU) request;
            if (contextEngineID != null) {
                scopedPDU.setContextEngineID(contextEngineID);
            }

            if (contextName != null) {
                scopedPDU.setContextName(contextName);
            }
        } else {
            if (pduType == PDU.V1TRAP) {
                v1TrapPDU.setTimestamp(sysUpTime.toLong());
                request = v1TrapPDU;
            } else {
                request = new PDU();
            }
        }

        request.setType(pduType);
        return request;
    }
View Full Code Here

Examples of org.snmp4j.PDU

        setSysUpTimeFromBootTime(bootTime); // needs to be called before checkTrapVariables();
        setTrapOIDFromAlertParameters(alertParameters); // needs to be called before checkTrapVariables();
        checkTrapVariables(this.vbs);
        try {
            PDU response = send();
            if ((getPduType() == PDU.TRAP) || (getPduType() == PDU.V1TRAP)) {
                return (PDU.getTypeString(getPduType()) + " sent successfully");
            } else if (response == null) {
                return ("Request timed out.");
            } else if (response.getType() == PDU.REPORT) {
                return getReport(response);
            } else if (this.operation == DEFAULT) {
                return "Response received with requestID=" + response.getRequestID() + ", errorIndex="
                    + response.getErrorIndex() + ", " + "errorStatus=" + response.getErrorStatusText() + "("
                    + response.getErrorStatus() + ")" + "\n" + getVariableBindings(response);
            } else {
                return "Received something strange: requestID=" + response.getRequestID() + ", errorIndex="
                    + response.getErrorIndex() + ", " + "errorStatus=" + response.getErrorStatusText() + "("
                    + response.getErrorStatus() + ")" + "\n" + getVariableBindings(response);
            }
        } catch (IOException ex) {
            log.error(ex.getMessage());
            return "Error while trying to send request: " + ex.getMessage();
        } catch (IllegalArgumentException ex) {
View Full Code Here

Examples of org.snmp4j.PDU

        assertEquals(result.getState(), SUCCESS, result.getFailureMessages().toString());
        while (receivedTraps.peek() == null) {
            Thread.sleep(1000);
        }
        PDU pdu = receivedTraps.poll();
        assertNull(receivedTraps.peek(), "Only one trap should have been received");

        assertExpectedPdu(pdu, new PduExpectedValues(snmpTrapOid, resourceName, alertDefinitionName, alertPriority,
            platformName, alertConditions, alertUrl));
    }
View Full Code Here

Examples of org.snmp4j.PDU

    enum Severity {
        high, medium, info;
    }

    protected void sendTrap(String message) {
        PDU pdu = new PDU();
        pdu.setType(PDU.TRAP);
        add(pdu, alertName, message);
        add(pdu, alertSeverity, Severity.medium);

        CommunityTarget target = new CommunityTarget();
        target.setCommunity(community);
View Full Code Here

Examples of org.snmp4j.PDU

     */
    public void processPdu(CommandResponderEvent cre) {

        if (log.isDebugEnabled())
            log.debug("recv: " + cre);
        PDU pdu = cre.getPDU();
        String sourceAddr;
        Address addr = cre.getPeerAddress();
        if (addr instanceof IpAddress) {
            sourceAddr = ((IpAddress) addr).getInetAddress().toString();
            if (sourceAddr.startsWith("/"))
                sourceAddr = sourceAddr.substring(1);
        } else {
            // Don't use addr.toString() as this would contain the port and generate too many
            // EventSources
            sourceAddr = "snmp-agent";
        }
        if (pdu != null) {
            StringBuffer payload = new StringBuffer();
            // SNMP v1
            if (pdu instanceof PDUv1) {
                PDUv1 v1pdu = (PDUv1) pdu;
                long timeTicks = v1pdu.getTimestamp();
                payload.append("Traptype (generic, specific): ");
                payload.append(v1pdu.getGenericTrap()).append(", ").append(v1pdu.getSpecificTrap()).append("\n");
                payload.append("Timestamp: " + new TimeTicks(timeTicks).toString());
                payload.append("\n");
            }

            SnmpTrapdComponent.trapCount++;
            EventSeverity severity = EventSeverity.INFO;

            Vector<VariableBinding> vbs = pdu.getVariableBindings();
            for (VariableBinding vb : vbs) {
                OID oid = vb.getOid();
                Variable var = vb.getVariable();
                int syntax = vb.getSyntax();

View Full Code Here

Examples of org.snmp4j.PDU

    }

    @NotNull
    public List<SNMPValue> getBulk(String mibName) throws SNMPException {
        List<SNMPValue> values = new ArrayList<SNMPValue>();
        PDU request = createPDU(mibName, PDU.GETBULK);
        request.setMaxRepetitions(GETBULK_MAX_REPETITIONS);
        request.setNonRepeaters(GETBULK_NON_REPEATERS);
        PDU response = sendRequest(request, mibName);
        Vector<VariableBinding> varBindings = response.getVariableBindings();
        for (VariableBinding varBinding : varBindings) {
            values.add(new SNMPValue(varBinding));
        }

        return values;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.