Package org.snmp4j

Examples of org.snmp4j.PDU


  public ResponseEvent informSync(final A address, final VariableBinding... bindings) throws IOException {

    checkNoNulls(address, bindings);

    final Target target = this.createTarget(address);
    final PDU requestPdu = this.createRequestPdu(PDU.INFORM, target, bindings);
    return this.getSnmp().send(requestPdu, target);
  }
View Full Code Here


  public void notify(final A address, final VariableBinding... bindings) throws IOException {

    checkNoNulls(address, bindings);

    final Target target = this.createTarget(address);
    final PDU requestPdu = this.createRequestPdu(PDU.NOTIFICATION, target, bindings);
    this.getSnmp().send(requestPdu, target);
  }
View Full Code Here

        target.setRetries(this.endpoint.getRetries());
        target.setTimeout(this.endpoint.getTimeout());
        target.setVersion(this.endpoint.getSnmpVersion());

        // creating PDU
        this.pdu = new PDU();

        // listen to the transport
        if (LOG.isDebugEnabled()) {
            LOG.debug("Starting OID poller on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
        }
View Full Code Here

            // ignore null requests/responses
            LOG.debug("Received invalid SNMP event. Request: " + event.getRequest() + " / Response: " + event.getResponse());
            return;
        }
       
        PDU pdu = event.getResponse();
        processPDU(pdu);
    }
View Full Code Here


        for (Alert alert : alerts) {

            // Create PDU          
            PDU trap = new PDU();
            trap.setType(PDU.TRAP);

            OID oid = new OID(seyrenConfig.getSnmpOID());
            trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid));
            trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
            trap.add(variableBinding(SnmpConstants.sysDescr, "Seyren Alert"));

            //Add Payload
            trap.add(variableBinding(oid, check.getName()));
            trap.add(variableBinding(oid, alert.getTarget()));
            trap.add(variableBinding(oid, check.getState().name()));
            trap.add(variableBinding(oid, alert.getValue().toString()));
            trap.add(variableBinding(oid, check.getWarn().toString()));
            trap.add(variableBinding(oid, check.getError().toString()));

            // Send
            sendAlert(check, snmp, target, trap);
        }
View Full Code Here

            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

    securityName.decodeBER(wholeMsg);
    securityLevel.setValue(SecurityLevel.NOAUTH_NOPRIV);
    securityModel.setValue(SecurityModel.SECURITY_MODEL_SNMPv2c);
    messageProcessingModel.setValue(ID);

    PDU v2cPDU = new PDU();
    pdu.setPdu(v2cPDU);
    v2cPDU.decodeBER(wholeMsg);

    BER.checkSequenceLength(length,
                            (int)wholeMsg.getPosition() - startPos,
                            v2cPDU);

    sendPduHandle.setTransactionID(v2cPDU.getRequestID().getValue());

    // create state reference
    StateReference stateRef =
        new StateReference(sendPduHandle,
                           transportAddress,
View Full Code Here

    Snmp snmp = new Snmp(transport);
    // Iterating over map
    for (Entry<Object, Object> entry : p.entrySet()) {
      oidValue = entry.getValue().toString();
      descr = entry.getKey().toString();
      PDU pdu = new PDU();
      pdu.add(new VariableBinding(new OID(oidValue)));
      pdu.setRequestID(new Integer32(1));
      pdu.setType(PDU.GET);

      try {
        response = snmp.get(pdu, comtarget);
      } catch (IOException e) {
      }
      // Process Agent Response
      if (response != null) {
        PDU responsePDU = response.getResponse();
        if (responsePDU != null) {
          int errorStatus = responsePDU.getErrorStatus();
          int errorIndex = responsePDU.getErrorIndex();
          String errorStatusText = responsePDU.getErrorStatusText();

          if (errorStatus == PDU.noError) {
            String resp = (String) responsePDU.getVariableBindings().toString();
            // Split answer into OID and description
            String[] helperArray = resp.replaceAll("[\\[|\\]]", "").split(" = ");
            if (helperArray.length > 1) {
              oid.put(descr, helperArray[1]);
              //count++;
View Full Code Here

    Variable var = providerCmd.getValue(itemName, command);
    OID oid = providerCmd.getOID(itemName, command);
      VariableBinding varBind = new VariableBinding(oid,var);

    // Create the PDU
    PDU pdu = new PDU();
      pdu.add(varBind);
      pdu.setType(PDU.SET);
      pdu.setRequestID(new Integer32(1));

    logger.debug("SNMP: Send CMD PDU {} {}", providerCmd.getAddress(itemName, command), pdu);

    if (snmp == null) {
      logger.error("SNMP: snmp not initialised - aborting request");
View Full Code Here

            target.setRetries(retries);
            target.setTimeout(timeout);
            target.setVersion(SnmpConstants.version1);

          // Create the PDU
          PDU pdu = new PDU();
            pdu.add(new VariableBinding(provider.getOID(itemName)));
            pdu.setType(PDU.GET);

          logger.debug("SNMP: Send PDU {} {}", provider.getAddress(itemName), pdu);

          if (snmp == null) {
            logger.error("SNMP: snmp not initialised - aborting request");
View Full Code Here

TOP

Related Classes of org.snmp4j.PDU

Copyright © 2018 www.massapicom. 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.