Пример #1
0
  protected void execute(String[] command, long timestamp)
      throws ValidationException, DatastoreException {
    Validator.validateNotNullOrEmpty("metricName", command[1]);

    String metricName = command[1];

    DataPoint dp;
    try {
      if (command[3].contains("."))
        dp = m_doubleFactory.createDataPoint(timestamp, Double.parseDouble(command[3]));
      else dp = m_longFactory.createDataPoint(timestamp, Util.parseLong(command[3]));
    } catch (NumberFormatException e) {
      throw new ValidationException(e.getMessage());
    }

    ImmutableSortedMap.Builder<String, String> tags = Tags.create();

    int tagCount = 0;
    for (int i = 4; i < command.length; i++) {
      String[] tag = command[i].split("=");
      validateTag(tagCount, tag);

      tags.put(tag[0], tag[1]);
      tagCount++;
    }

    if (tagCount == 0) tags.put("add", "tag");

    m_counter.incrementAndGet();
    m_datastore.putDataPoint(metricName, tags.build(), dp);
  }
Пример #2
0
  @Override
  public void doFilter(
      ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
      throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
    HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;

    // Skip oauth for local connections
    if (!"127.0.0.1".equals(servletRequest.getRemoteAddr())) {
      // Read the OAuth parameters from the request
      OAuthServletRequest request = new OAuthServletRequest(httpRequest);
      OAuthParameters params = new OAuthParameters();
      params.readRequest(request);

      String consumerKey = params.getConsumerKey();

      // Set the secret(s), against which we will verify the request
      OAuthSecrets secrets = new OAuthSecrets();
      secrets.setConsumerSecret(m_tokenStore.getToken(consumerKey));

      // Check that the timestamp has not expired
      String timestampStr = params.getTimestamp();
      if (timestampStr == null) {
        logger.warn("Missing OAuth headers");
        httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Missing OAuth headers");
        return;
      }

      long msgTime = Util.parseLong(timestampStr) * 1000L; // Message time is in seconds
      long currentTime = System.currentTimeMillis();

      // if the message is older than 5 min it is no good
      if (Math.abs(msgTime - currentTime) > 300000) {
        logger.warn(
            "OAuth message time out, msg time: " + msgTime + " current time: " + currentTime);
        httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Message expired");
        return;
      }

      // Verify the signature
      try {
        if (!OAuthSignature.verify(request, params, secrets)) {
          logger.warn("Invalid OAuth signature");

          httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid OAuth signature");
          return;
        }
      } catch (OAuthSignatureException e) {
        logger.warn("OAuth exception", e);

        httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid OAuth request");
        return;
      }
    }

    filterChain.doFilter(servletRequest, servletResponse);
  }
Пример #3
0
  @Override
  public void execute(Channel chan, String[] command) throws DatastoreException {
    m_counter.incrementAndGet();

    DataPointSet dps = new DataPointSet(command[1]);

    long timestamp = Util.parseLong(command[2]);
    // Backwards compatible hack for the next 30 years
    // This allows clients to send seconds to us
    if (timestamp < 3000000000L) timestamp *= 1000;

    DataPoint dp;
    if (command[3].contains(".")) dp = new DataPoint(timestamp, Double.parseDouble(command[3]));
    else dp = new DataPoint(timestamp, Util.parseLong(command[3]));

    dps.addDataPoint(dp);

    for (int i = 4; i < command.length; i++) {
      String[] tag = command[i].split("=");
      dps.addTag(tag[0], tag[1]);
    }

    m_datastore.putDataPoints(dps);
  }
Пример #4
0
 @Override
 public void execute(Channel chan, String[] command)
     throws DatastoreException, ValidationException {
   long timestamp = Util.parseLong(command[2]);
   execute(command, timestamp);
 }