Sha256: 9cb2dff95048899d46df9335ce781ef791525623d468be6381ca0bccf4bb7ac0

Contents?: true

Size: 1.07 KB

Versions: 47

Compression:

Stored size: 1.07 KB

Contents

module RequestLogAnalyzer::Filter

  # Filter to anonymize parsed values
  # Options
  # * <tt>:mode</tt> :reject or :accept.
  # * <tt>:field</tt> Specific field to accept or reject.
  # * <tt>:value</tt> Value that the field should match to be accepted or rejected.
  class Anonymize < Base

    def generate_random_ip
      "#{rand(256)}.#{rand(256)}.#{rand(256)}.#{rand(256)}"
    end

    def anonymize_url(value)
      return value.sub(/^https?\:\/\/[A-Za-z0-9\.-]+\//, "http://example.com/")
    end

    def fuzz(value)
      value * ((75 + rand(50)) / 100.0)
    end

    def filter(request)
      # TODO: request.attributes is bad practice
      request.attributes.each do |key, value|
        if key == :ip
          request.attributes[key] = generate_random_ip
        elsif key == :url
          request.attributes[key] = anonymize_url(value)
        elsif [ :duration, :view, :db, :type, :after_filters_time, :before_filters_time,
                :action_time].include?(key)
          request.attributes[key] = fuzz(value)
        end
      end

      return request
    end
  end

end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
request-log-analyzer-1.13.1 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.13.0 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.11 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.10 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.9 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.8 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.7 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.6 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.5 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.4 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.3 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.2 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.1 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.12.0 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.11.1 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.11.0 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.10.1 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.10.0 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.9.10 lib/request_log_analyzer/filter/anonymize.rb
request-log-analyzer-1.9.9 lib/request_log_analyzer/filter/anonymize.rb