Package org.snmp4j

Examples of org.snmp4j.PDUv1


        }
        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++;


        if (to != null) {
          pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(to)));
        }
      }
      else if (type == PDU.V1TRAP) {
        PDUv1 pduV1 = (PDUv1)pdu;
        String aa =
            (String) ArgumentParser.getValue(settings, oAgentAddr, 0);
        if (aa != null) {
          pduV1.setAgentAddress(new IpAddress(aa));
        }
        Integer gid = (Integer) ArgumentParser.getValue(settings, oGenericID, 0);
        if (gid != null) {
          pduV1.setGenericTrap(gid.intValue());
        }
        Integer sid = (Integer) ArgumentParser.getValue(settings, oSpecificID, 0);
        if (sid != null) {
          pduV1.setSpecificTrap(sid.intValue());
        }
        String e =
            (String) ArgumentParser.getValue(settings, oEnterprise, 0);
        if (e != null) {
          pduV1.setEnterprise(new OID(e));
        }
      }
      if (pdu instanceof ScopedPDU) {
        ScopedPDU scoped = (ScopedPDU)pdu;
        String cEngineID =

            sb.append(SNMP_TAG_OPEN);
        }

        // Extract SNMPv1 specific variables
        if (pdu.getType() == PDU.V1TRAP) {
            PDUv1 v1pdu = (PDUv1) pdu;
            entryAppend(sb, "enterprise", v1pdu.getEnterprise().toString());
            entryAppend(sb, "agent-addr", v1pdu.getAgentAddress().toString());
            entryAppend(sb, "generic-trap", Integer.toString(v1pdu.getGenericTrap()));
            entryAppend(sb, "specific-trap", Integer.toString(v1pdu.getSpecificTrap()));
            entryAppend(sb, "time-stamp", Long.toString(v1pdu.getTimestamp()));
        }

        // now loop all variables of the response
        for (Object o : pdu.getVariableBindings()) {
            VariableBinding b = (VariableBinding)o;

   
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString(community));
    target.setAddress(targetAddress);
   
    PDUv1 pdu = new PDUv1();
    pdu.setType(PDU.V1TRAP);
    VariableBinding vb = new VariableBinding();
    OID oidMessage = new OID (alarmMessageOid);
    vb.setOid(oidMessage);
    if(message.length() < MAX_ALARM_MESSAGE_SIZE) {
      vb.setVariable(new OctetString(message));
    } else {
      String tmpMessage = message.substring(0,MAX_ALARM_MESSAGE_SIZE);
      logger.info(" message too long " + message  +
          ". send " + tmpMessage);
      vb.setVariable(new OctetString(tmpMessage));
    }
    pdu.add(vb);   
    OID oid  = new OID(trapId);
    if(trapType == CRITICAL_TRAP) {
      pdu.setSpecificTrap(CRITICAL_TRAP);
    } else {
      pdu.setSpecificTrap(WARNING_TRAP);
    }
    pdu.setEnterprise(oid);
    pdu.setGenericTrap(PDUv1.ENTERPRISE_SPECIFIC);
   
    try {
      DefaultUdpTransportMapping udpTransportMap = new
        DefaultUdpTransportMapping();
      Snmp snmp = new Snmp(udpTransportMap);

    checkNoNulls(address, enterprise, bindings);
    checkV1Bindings(bindings);

    final Target target = this.createTarget(address);
    final PDUv1 requestPdu = (PDUv1) this.createRequestPdu(PDU.V1TRAP, target, bindings);
    requestPdu.setEnterprise(enterprise);
    requestPdu.setGenericTrap(genericTrap);
    requestPdu.setSpecificTrap(specificTrap);
    this.getSnmp().send(requestPdu, target);
  }

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

    PDUv1 v1PDU = new PDUv1();
    pdu.setPdu(v1PDU);
    v1PDU.decodeBER(wholeMsg);

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

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

    // create state reference
    StateReference stateRef =
        new StateReference(sendPduHandle,
                           transportAddress,

TOP

Related Classes of org.snmp4j.PDUv1

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.