Class: RequestLogAnalyzer::Filter::Anonymize
- Inherits:
-
Base
- Object
- Base
- RequestLogAnalyzer::Filter::Anonymize
show all
- Defined in:
- lib/request_log_analyzer/filter/anonymize.rb
Overview
Filter to anonymize parsed values Options
-
:mode
:reject or :accept.
-
:field
Specific field to accept or reject.
-
:value
Value that the field should match to be accepted or rejected.
Instance Attribute Summary
Attributes inherited from Base
#file_format, #options
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#anonymize_url(value) ⇒ Object
14
15
16
|
# File 'lib/request_log_analyzer/filter/anonymize.rb', line 14
def anonymize_url(value)
return value.sub(/^https?\:\/\/[A-Za-z0-9\.-]+\//, "http://example.com/")
end
|
#filter(request) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/request_log_analyzer/filter/anonymize.rb', line 22
def filter(request)
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
|
#fuzz(value) ⇒ Object
18
19
20
|
# File 'lib/request_log_analyzer/filter/anonymize.rb', line 18
def fuzz(value)
value * ((75 + rand(50)) / 100.0)
end
|
#generate_random_ip ⇒ Object
10
11
12
|
# File 'lib/request_log_analyzer/filter/anonymize.rb', line 10
def generate_random_ip
"#{rand(256)}.#{rand(256)}.#{rand(256)}.#{rand(256)}"
end
|