Exemplo n.º 1
0
 /** {@inheritDoc} */
 @Override
 protected void addUsmUser(USM usm) {
   UsmUser user =
       new UsmUser(
           new OctetString("SHADES"),
           AuthSHA.ID,
           new OctetString("SHADESAuthPassword"),
           PrivDES.ID,
           new OctetString("SHADESPrivPassword"));
   usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
   user =
       new UsmUser(
           new OctetString("TEST"),
           AuthSHA.ID,
           new OctetString("maplesyrup"),
           PrivDES.ID,
           new OctetString("maplesyrup"));
   usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
   user =
       new UsmUser(
           new OctetString("opennmsUser"),
           AuthMD5.ID,
           new OctetString("0p3nNMSv3"),
           PrivDES.ID,
           new OctetString("0p3nNMSv3"));
   usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
   user =
       new UsmUser(
           new OctetString("SHA"), AuthSHA.ID, new OctetString("SHAAuthPassword"), null, null);
   usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
 }
Exemplo n.º 2
0
  @Test
  public void testGetNextMultipleVarbinds() throws Exception {

    request(".1.0.8802.1.1.2.1.3.1")
        .andExpect(".1.0.8802.1.1.2.1.3.1.0", SMIConstants.SYNTAX_INTEGER32, new Integer32(4));

    doGetNext();

    m_agent.getUsm().setEngineBoots(15);

    byte[] hexString =
        new byte[] {(byte) 0x80, (byte) 0x71, (byte) 0x1F, (byte) 0x8F, (byte) 0xAF, (byte) 0xC0};
    request(".1.0.8802.1.1.2.1.3.1")
        .andExpect(".1.0.8802.1.1.2.1.3.1.0", SMIConstants.SYNTAX_INTEGER32, new Integer32(4));
    request(".1.0.8802.1.1.2.1.3.2")
        .andExpect(
            ".1.0.8802.1.1.2.1.3.2.0",
            SMIConstants.SYNTAX_OCTET_STRING,
            new OctetString(hexString));
    request(".1.0.8802.1.1.2.1.3.3")
        .andExpect(
            ".1.0.8802.1.1.2.1.3.3.0",
            SMIConstants.SYNTAX_OCTET_STRING,
            new OctetString("penrose-mx480".getBytes()));

    doGetNext();

    // This statement breaks the internal state of the SNMP4J agent
    // m_agent.getUsm().setLocalEngine(m_agent.getUsm().getLocalEngineID(), 15, 200);
    m_agent.getUsm().removeEngineTime(m_usm.getLocalEngineID());
    m_usm.removeEngineTime(m_agent.getUsm().getLocalEngineID());

    request(".1.0.8802.1.1.2.1.3.1")
        .andExpect(".1.0.8802.1.1.2.1.3.1.0", SMIConstants.SYNTAX_INTEGER32, new Integer32(4));
    doGetNext();
  }
Exemplo n.º 3
0
 private Target createTarget(OctetString userInfo) {
   if ((userInfo == null) || (userInfo.length() == 0)) {
     return defaultTarget;
   }
   if (version == SnmpConstants.version3) {
     if ((securityModel == SecurityModel.SECURITY_MODEL_USM) && (usm != null)) {
       UsmUserEntry user = usm.getUser(null, userInfo);
       UserTarget target = new UserTarget();
       if (user != null) {
         if (user.getAuthenticationKey() != null) {
           if (user.getPrivacyKey() != null) {
             target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
           } else {
             target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
           }
         } else {
           target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
         }
       }
       target.setVersion(version);
       target.setSecurityName(userInfo);
       target.setSecurityModel(securityModel);
       target.setTimeout(timeout);
       target.setRetries(retries);
       return target;
     } else if (securityModel == SecurityModel.SECURITY_MODEL_TSM) {
       CertifiedTarget target = new CertifiedTarget(userInfo);
       target.setVersion(version);
       target.setSecurityModel(securityModel);
       target.setTimeout(timeout);
       target.setRetries(retries);
       return target;
     }
   } else {
     CommunityTarget target = new CommunityTarget();
     target.setCommunity(userInfo);
     target.setVersion(version);
     target.setSecurityModel(securityModel);
     target.setTimeout(timeout);
     target.setRetries(retries);
     return target;
   }
   return null;
 }
Exemplo n.º 4
0
  public Result execute(Result previousResult, int nr) {
    Result result = previousResult;
    result.setNrErrors(1);
    result.setResult(false);

    String servername = environmentSubstitute(serverName);
    int nrPort = Const.toInt(environmentSubstitute("" + port), DEFAULT_PORT);
    String Oid = environmentSubstitute(oid);
    int timeOut = Const.toInt(environmentSubstitute("" + timeout), DEFAULT_TIME_OUT);
    int retry = Const.toInt(environmentSubstitute("" + nrretry), 1);
    String messageString = environmentSubstitute(message);

    Snmp snmp = null;

    try {
      TransportMapping transMap = new DefaultUdpTransportMapping();
      snmp = new Snmp(transMap);

      UdpAddress udpAddress = new UdpAddress(InetAddress.getByName(servername), nrPort);
      ResponseEvent response = null;
      if (targettype.equals(target_type_Code[0])) {
        // Community target
        String community = environmentSubstitute(comString);

        CommunityTarget target = new CommunityTarget();
        PDUv1 pdu1 = new PDUv1();
        transMap.listen();

        target.setCommunity(new OctetString(community));
        target.setVersion(SnmpConstants.version1);
        target.setAddress(udpAddress);
        if (target.getAddress().isValid()) {
          if (log.isDebug()) {
            logDebug("Valid IP address");
          }
        } else {
          throw new KettleException("Invalid IP address");
        }
        target.setRetries(retry);
        target.setTimeout(timeOut);

        // create the PDU
        pdu1.setGenericTrap(6);
        pdu1.setSpecificTrap(PDUv1.ENTERPRISE_SPECIFIC);
        pdu1.setEnterprise(new OID(Oid));
        pdu1.add(new VariableBinding(new OID(Oid), new OctetString(messageString)));

        response = snmp.send(pdu1, target);

      } else {
        // User target
        String userName = environmentSubstitute(user);
        String passPhrase = environmentSubstitute(passphrase);
        String engineID = environmentSubstitute(engineid);

        UserTarget usertarget = new UserTarget();
        transMap.listen();
        usertarget.setAddress(udpAddress);
        if (usertarget.getAddress().isValid()) {
          if (log.isDebug()) {
            logDebug("Valid IP address");
          }
        } else {
          throw new KettleException("Invalid IP address");
        }

        usertarget.setRetries(retry);
        usertarget.setTimeout(timeOut);
        usertarget.setVersion(SnmpConstants.version3);
        usertarget.setSecurityLevel(SecurityLevel.AUTH_PRIV);
        usertarget.setSecurityName(new OctetString("MD5DES"));

        // Since we are using SNMPv3 we use authenticated users
        // this is handled by the UsmUser and USM class

        UsmUser uu =
            new UsmUser(
                new OctetString(userName),
                AuthMD5.ID,
                new OctetString(passPhrase),
                PrivDES.ID,
                new OctetString(passPhrase));

        USM usm = snmp.getUSM();

        if (usm == null) {
          throw new KettleException("Null Usm");
        } else {
          usm =
              new USM(
                  SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
          usm.addUser(new OctetString(userName), uu);
          if (log.isDebug()) {
            logDebug("Valid Usm");
          }
        }

        // create the PDU
        ScopedPDU pdu = new ScopedPDU();
        pdu.add(new VariableBinding(new OID(Oid), new OctetString(messageString)));
        pdu.setType(PDU.TRAP);
        if (!Const.isEmpty(engineID)) {
          pdu.setContextEngineID(new OctetString(engineID));
        }

        // send the PDU
        response = snmp.send(pdu, usertarget);
      }

      if (response != null) {
        if (log.isDebug()) {
          logDebug("Received response from: " + response.getPeerAddress() + response.toString());
        }
      }

      result.setNrErrors(0);
      result.setResult(true);
    } catch (Exception e) {
      logError(BaseMessages.getString(PKG, "JobEntrySNMPTrap.ErrorGetting", e.getMessage()));
    } finally {
      try {
        if (snmp != null) {
          snmp.close();
        }
      } catch (Exception e) {
        /* Ignore */
      }
    }

    return result;
  }