infinum_graylog 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/infinum_graylog.rb +1 -0
- data/lib/infinum_graylog/cleaner.rb +123 -0
- data/lib/infinum_graylog/process_action_controller.rb +26 -2
- data/lib/infinum_graylog/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49569ea1e932e8f9252b96592f7e934932311273f799e320be8caea2e25936cf
|
4
|
+
data.tar.gz: 5dac3718045d2ae7542a7285ae226e69cddf04b28e345e40e07dff3505029ee1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd5bad3f451ab0dafb635dfd58c0750197803b940360ce12db68b1517d761b0273fbdff351da8c196cb3da293f75bdaf116f92083656ef2e72e8de7a954fd78e
|
7
|
+
data.tar.gz: 14f9c4bf3f901aea6f492adc656cd07e13a3b5bd678c442cdec87375088874574d7a0149e8bbc0c89d60692bb98503d1c41eb34128f94eec1104a6fe2c3e86ff
|
data/lib/infinum_graylog.rb
CHANGED
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module InfinumGraylog
|
4
|
+
class Cleaner
|
5
|
+
ENCODING_OPTIONS = {:invalid => :replace, :undef => :replace}.freeze
|
6
|
+
FILTERED = '[FILTERED]'.freeze
|
7
|
+
RECURSION = '[RECURSION]'.freeze
|
8
|
+
OBJECT = '[OBJECT]'.freeze
|
9
|
+
RAISED = '[RAISED]'.freeze
|
10
|
+
|
11
|
+
def initialize(filters)
|
12
|
+
@filters = Array(filters)
|
13
|
+
@deep_filters = @filters.any? {|f| f.kind_of?(Regexp) && f.to_s.include?("\\.".freeze) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def clean_object(obj)
|
17
|
+
traverse_object(obj, {}, nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
def traverse_object(obj, seen, scope)
|
21
|
+
return nil if obj.nil?
|
22
|
+
|
23
|
+
# Protect against recursion of recursable items
|
24
|
+
protection = if obj.is_a?(Hash) || obj.is_a?(Array) || obj.is_a?(Set)
|
25
|
+
return seen[obj] if seen[obj]
|
26
|
+
seen[obj] = RECURSION
|
27
|
+
end
|
28
|
+
|
29
|
+
value = case obj
|
30
|
+
when Hash
|
31
|
+
clean_hash = {}
|
32
|
+
obj.each do |k,v|
|
33
|
+
if filters_match_deeply?(k, scope)
|
34
|
+
clean_hash[k] = FILTERED
|
35
|
+
else
|
36
|
+
clean_hash[k] = traverse_object(v, seen, [scope, k].compact.join('.'))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
clean_hash
|
40
|
+
when Array, Set
|
41
|
+
obj.map { |el| traverse_object(el, seen, scope) }
|
42
|
+
when Numeric, TrueClass, FalseClass
|
43
|
+
obj
|
44
|
+
when String
|
45
|
+
clean_string(obj)
|
46
|
+
else
|
47
|
+
str = obj.to_s rescue RAISED
|
48
|
+
# avoid leaking potentially sensitive data from objects' #inspect output
|
49
|
+
if str =~ /#<.*>/
|
50
|
+
OBJECT
|
51
|
+
else
|
52
|
+
clean_string(str)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
seen[obj] = value if protection
|
57
|
+
value
|
58
|
+
end
|
59
|
+
|
60
|
+
def clean_string(str)
|
61
|
+
if defined?(str.encoding) && defined?(Encoding::UTF_8)
|
62
|
+
if str.encoding == Encoding::UTF_8
|
63
|
+
str.valid_encoding? ? str : str.encode('utf-16', ENCODING_OPTIONS).encode('utf-8')
|
64
|
+
else
|
65
|
+
str.encode('utf-8', ENCODING_OPTIONS)
|
66
|
+
end
|
67
|
+
elsif defined?(Iconv)
|
68
|
+
Iconv.conv('UTF-8//IGNORE', 'UTF-8', str) || str
|
69
|
+
else
|
70
|
+
str
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.clean_object_encoding(obj)
|
75
|
+
new(nil).clean_object(obj)
|
76
|
+
end
|
77
|
+
|
78
|
+
def clean_url(url)
|
79
|
+
return url if @filters.empty?
|
80
|
+
|
81
|
+
uri = URI(url)
|
82
|
+
return url unless uri.query
|
83
|
+
|
84
|
+
query_params = uri.query.split('&').map { |pair| pair.split('=') }
|
85
|
+
query_params.map! do |key, val|
|
86
|
+
if filters_match?(key)
|
87
|
+
"#{key}=#{FILTERED}"
|
88
|
+
else
|
89
|
+
"#{key}=#{val}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
uri.query = query_params.join('&')
|
94
|
+
uri.to_s
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def filters_match?(key)
|
100
|
+
str = key.to_s
|
101
|
+
|
102
|
+
@filters.any? do |f|
|
103
|
+
case f
|
104
|
+
when Regexp
|
105
|
+
str.match(f)
|
106
|
+
else
|
107
|
+
str.include?(f.to_s)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# If someone has a Rails filter like /^stuff\.secret/, it won't match "request.params.stuff.secret",
|
113
|
+
# so we try it both with and without the "request.params." bit.
|
114
|
+
def filters_match_deeply?(key, scope)
|
115
|
+
return true if filters_match?(key)
|
116
|
+
return false unless @deep_filters
|
117
|
+
|
118
|
+
long = [scope, key].compact.join('.')
|
119
|
+
short = long.sub(/^request\.params\./, '')
|
120
|
+
filters_match?(long) || filters_match?(short)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -15,8 +15,9 @@ module InfinumGraylog
|
|
15
15
|
request_id: event.transaction_id,
|
16
16
|
duration: event.duration,
|
17
17
|
application: configuration.application,
|
18
|
-
status: event_status
|
19
|
-
|
18
|
+
status: event_status,
|
19
|
+
headers: headers,
|
20
|
+
}.reverse_merge(cleaned_payload)
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
@@ -31,6 +32,29 @@ module InfinumGraylog
|
|
31
32
|
ActionDispatch::ExceptionWrapper.status_code_for_exception(event.payload[:exception].first)
|
32
33
|
end
|
33
34
|
|
35
|
+
def cleaned_payload
|
36
|
+
Cleaner.new(nil).clean_object(event.payload)
|
37
|
+
end
|
38
|
+
|
39
|
+
def headers
|
40
|
+
return nil unless event.payload[:headers]
|
41
|
+
headers = {}
|
42
|
+
|
43
|
+
event.payload[:headers].each_pair do |key, value|
|
44
|
+
if key.to_s.start_with?("HTTP_")
|
45
|
+
header_key = key[5..-1]
|
46
|
+
elsif ["CONTENT_TYPE", "CONTENT_LENGTH"].include?(key)
|
47
|
+
header_key = key
|
48
|
+
else
|
49
|
+
next
|
50
|
+
end
|
51
|
+
|
52
|
+
headers[header_key.split("_").map {|s| s.capitalize}.join("-")] = value
|
53
|
+
end
|
54
|
+
|
55
|
+
headers
|
56
|
+
end
|
57
|
+
|
34
58
|
def configuration
|
35
59
|
InfinumGraylog.configuration
|
36
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infinum_graylog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stjepan Hadjic
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- bin/setup
|
87
87
|
- infinum_graylog.gemspec
|
88
88
|
- lib/infinum_graylog.rb
|
89
|
+
- lib/infinum_graylog/cleaner.rb
|
89
90
|
- lib/infinum_graylog/configuration.rb
|
90
91
|
- lib/infinum_graylog/notifier.rb
|
91
92
|
- lib/infinum_graylog/process_action_controller.rb
|