fluent-plugin-filter-logs 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/fluent-plugin-filter-logs.gemspec +1 -1
- data/lib/fluent/plugin/filter_logs.rb +31 -46
- data/test/plugin/test_filter_logs.rb +409 -365
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38acc5285e3ece4477c59ca56b926a509a7194b6a6ded5f35e5e84a969996177
|
4
|
+
data.tar.gz: cb92161a7bc21e9e12768a9a9ceab363c18a96c8e7a63315b460c401fa9a3bda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b4adfc66712ed06eb279b5fb046ec6d572737d2f8fbfecc5ea9648ace4da6d00eefc8ea1b6cdddc6e9d72be8aa7f88e6ce102c2ac6672d00f8caea551140d4c
|
7
|
+
data.tar.gz: 1bdf39004d168be274b73b054a824fe169a933b91a7b3b2b51e0702f6614273bbf82b952069233ac6689f8f08d265d9afb590677d743bc6bce9b179f23161998
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fluent-plugin-filter-logs (1.0
|
4
|
+
fluent-plugin-filter-logs (1.1.0)
|
5
5
|
fluentd (>= 0.14.10, < 2)
|
6
6
|
logfmt (~> 0.0.9)
|
7
7
|
|
@@ -11,7 +11,7 @@ GEM
|
|
11
11
|
byebug (11.1.1)
|
12
12
|
concurrent-ruby (1.1.6)
|
13
13
|
cool.io (1.6.0)
|
14
|
-
fluentd (1.10.
|
14
|
+
fluentd (1.10.1)
|
15
15
|
cool.io (>= 1.4.5, < 2.0.0)
|
16
16
|
http_parser.rb (>= 0.5.1, < 0.7.0)
|
17
17
|
msgpack (>= 1.3.1, < 2.0.0)
|
@@ -32,7 +32,7 @@ GEM
|
|
32
32
|
strptime (0.2.3)
|
33
33
|
test-unit (3.2.9)
|
34
34
|
power_assert
|
35
|
-
tzinfo (2.0.
|
35
|
+
tzinfo (2.0.2)
|
36
36
|
concurrent-ruby (~> 1.0)
|
37
37
|
tzinfo-data (1.2019.3)
|
38
38
|
tzinfo (>= 1.0.0)
|
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'fluent-plugin-filter-logs'
|
8
|
-
spec.version = '1.0
|
8
|
+
spec.version = '1.1.0'
|
9
9
|
spec.authors = ['Camille Meulien']
|
10
10
|
spec.email = ['cmeulien@heliostech.fr']
|
11
11
|
|
@@ -25,43 +25,24 @@ module Fluent
|
|
25
25
|
class LogsFilter < Filter
|
26
26
|
Fluent::Plugin.register_filter('logs', self)
|
27
27
|
REGEXPS_LOGS = [
|
28
|
-
[/^(?<upstream_ip>\S+) - - \[
|
29
|
-
[/^\[[^\]]+\] (?<upstream_ip>\S+) - [^ ]+ \[
|
30
|
-
[
|
31
|
-
[/^.. \[
|
32
|
-
[
|
28
|
+
[/^(?<upstream_ip>\S+) - - \[\S+ \+\d{4}\] "(?<message>\S+ \S+ [^"]+)" (?<status_code>\d{3}) (?<content_size>\d+|-) "(?<referer>.*?)" "(?<user_agent>[^"]+)" "(?<user_ip>[^"]+)"$/],
|
29
|
+
[/^\[[^\]]+\] (?<upstream_ip>\S+) - [^ ]+ \[[^\]]+\] "(?<message>\S+ \S+ [^"]+)" (?<status_code>\d{3}) (?<content_size>\d+|-) "(?<referer>.*?)" "(?<user_agent>[^"]+)"/],
|
30
|
+
[/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}\S+ \[(?<level>[^\]]+)\] (?<message>.*)/],
|
31
|
+
[/^.. \[[^\]]+?( \#\d+)?\] +(?<level>\S+) -- : (?<message>.*)$/],
|
32
|
+
[/^(?<level>[DINWECA])\d{4} \d{2}:\d{2}:\d{2}\.\d+ +(?<message>.*)$/],
|
33
|
+
[%r{^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} UTC (?<message>(?:\S+ ){1,2}#\d+ (?<level>\S+) import (?<peers>\d+)/(?<peers_max>\d+) peers? .*)$},
|
33
34
|
lambda do |r|
|
34
35
|
ratio = r['peers'].to_f / r['peers_max'].to_f
|
35
36
|
l = ratio <= 0.1 ? 'ERROR' : ratio <= 0.2 ? 'WARN' : 'INFO'
|
36
37
|
return { 'level' => l }
|
37
38
|
end],
|
38
|
-
[
|
39
|
+
[/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} UTC (?<message>(?:\S+ ){1,2}#\d+ (?<level>\S+) .*)$/],
|
39
40
|
[/^ranger_\S+: \d+$/, { 'level' => 'INFO' }]
|
40
41
|
].freeze
|
41
42
|
|
42
|
-
REGEXPS_DATES = [
|
43
|
-
[/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}/, '%FT%T.%L'],
|
44
|
-
[/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/, '%FT%T.%L%z'],
|
45
|
-
[/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/, '%FT%T%z'],
|
46
|
-
[/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}/, '%F %T.%L'],
|
47
|
-
[/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/, '%F %T'],
|
48
|
-
[%r{\d{2}/[a-zA-Z]+/\d{4}:\d{2}:\d{2}:\d{2}}, '%d/%b/%Y:%H:%M:%S %z']
|
49
|
-
].freeze
|
50
|
-
|
51
|
-
def ow_parse_time(str)
|
52
|
-
return nil if str.nil?
|
53
|
-
|
54
|
-
REGEXPS_DATES.each do |pattern, format|
|
55
|
-
if str.match(pattern)
|
56
|
-
return DateTime.strptime(str, format).to_time.to_i
|
57
|
-
end
|
58
|
-
end
|
59
|
-
DateTime.strptime(str).to_time.to_i
|
60
|
-
rescue ArgumentError => e
|
61
|
-
log.warn "#{e}, time str: #{str}"
|
62
|
-
end
|
63
|
-
|
64
43
|
def ow_parse_logs(text)
|
44
|
+
return {} unless text
|
45
|
+
|
65
46
|
if text[0] == '{'
|
66
47
|
begin
|
67
48
|
return JSON.parse(text)
|
@@ -96,9 +77,17 @@ module Fluent
|
|
96
77
|
|
97
78
|
FORMATTERS = [
|
98
79
|
['level', lambda do |value|
|
99
|
-
|
100
|
-
return '
|
101
|
-
|
80
|
+
case value
|
81
|
+
when /^warning$/i then return 'WARN'
|
82
|
+
when /^note$/i then return 'INFO'
|
83
|
+
when 'D' then return 'DEBUG'
|
84
|
+
when 'I' then return 'INFO'
|
85
|
+
when 'N' then return 'NOTICE'
|
86
|
+
when 'W' then return 'WARN'
|
87
|
+
when 'E' then return 'ERROR'
|
88
|
+
when 'C' then return 'CRITICAL'
|
89
|
+
when 'A' then return 'ALERT'
|
90
|
+
end
|
102
91
|
value.upcase
|
103
92
|
end]
|
104
93
|
].freeze
|
@@ -107,6 +96,16 @@ module Fluent
|
|
107
96
|
text = record['log']
|
108
97
|
record.delete('log')
|
109
98
|
|
99
|
+
if record['data']
|
100
|
+
record['status_code'] = record['data']['status']
|
101
|
+
record['level'] = 'DEBUG'
|
102
|
+
record['message'] = JSON.dump(record.delete('data'))
|
103
|
+
end
|
104
|
+
|
105
|
+
if record['status_code']
|
106
|
+
record['status_code'] = record['status_code'].to_i
|
107
|
+
end
|
108
|
+
|
110
109
|
RENAME_MAP.each do |src, dst|
|
111
110
|
if record[src] && record[dst].nil?
|
112
111
|
record[dst] = record[src]
|
@@ -124,22 +123,8 @@ module Fluent
|
|
124
123
|
|
125
124
|
def filter(_tag, _time, record)
|
126
125
|
log.trace { "filter_logs: (#{record.class}) #{record.inspect}" }
|
127
|
-
unless record['log']
|
128
|
-
if record['data']
|
129
|
-
record['level'] = 'DEBUG'
|
130
|
-
record['message'] = JSON.dump(record.delete('data'))
|
131
|
-
end
|
132
|
-
return record
|
133
|
-
end
|
134
|
-
|
135
126
|
record = record.merge(ow_parse_logs(record['log']))
|
136
|
-
|
137
|
-
|
138
|
-
if record['time']
|
139
|
-
record['timestamp'] = ow_parse_time(record['time'])
|
140
|
-
record.delete('time')
|
141
|
-
end
|
142
|
-
record
|
127
|
+
ow_post_process(record)
|
143
128
|
end
|
144
129
|
end
|
145
130
|
end
|
@@ -33,369 +33,413 @@ class LogsFilterTest < Test::Unit::TestCase
|
|
33
33
|
assert_equal(expected, filter(messages))
|
34
34
|
end
|
35
35
|
|
36
|
-
test 'basic fmtlog parsing' do
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'json fmt logs' do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
test 'json apache logs (nginx example)' do
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
36
|
+
# test 'basic fmtlog parsing' do
|
37
|
+
# messages = [
|
38
|
+
# { 'message' => 'time="2018-01-01 00:00:00" aaa=111 bbb=222' }
|
39
|
+
# ]
|
40
|
+
# expected = [
|
41
|
+
# { 'message' => 'time="2018-01-01 00:00:00" aaa=111 bbb=222' }
|
42
|
+
# ]
|
43
|
+
# assert_equal(expected, filter(messages))
|
44
|
+
# end
|
45
|
+
|
46
|
+
# test 'json fmt logs' do
|
47
|
+
# text = '{"container_id":"2caa236b7c","container_name":"/traefik-lb_traefik_1","source":"stdout","log":"time=\"2020-03-31T08:46:44Z\" level=debug msg=\"Filtering disabled container\" providerName=docker container=deposit-collection-edge-11facecb13"}'
|
48
|
+
# messages = [
|
49
|
+
# JSON.parse(text)
|
50
|
+
# ]
|
51
|
+
# expected = [
|
52
|
+
# {
|
53
|
+
# 'container_id' => '2caa236b7c',
|
54
|
+
# 'container_name' => '/traefik-lb_traefik_1',
|
55
|
+
# 'source' => 'stdout',
|
56
|
+
# 'level' => 'DEBUG',
|
57
|
+
# 'message' => 'Filtering disabled container',
|
58
|
+
# 'providerName' => 'docker',
|
59
|
+
# 'container' => 'deposit-collection-edge-11facecb13',
|
60
|
+
# 'time' => '2020-03-31T08:46:44Z'
|
61
|
+
# }
|
62
|
+
# ]
|
63
|
+
# assert_equal(expected, filter(messages))
|
64
|
+
# end
|
65
|
+
|
66
|
+
# test 'json apache logs (nginx example)' do
|
67
|
+
# text = '{"container_name":"/demo_frontend_1","source":"stdout","log":"192.168.80.32 - - [27/Mar/2020:19:26:18 +0000] \"GET /static/media/search.f6cf3254.svg HTTP/1.1\" 200 329 \"https://demo.openware.work/trading/copyright/batusdt\" \"Mozilla/5.0 (Linux; Android 8.0.0; SAMSUNG SM-J330FN/J330FNXXS3BSE1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/11.1 Chrome/75.0.3770.143 Mobile Safari/537.36\" \"123.456.789.0\"","container_id":"1888b6a06ef7"}'
|
68
|
+
# messages = [
|
69
|
+
# JSON.parse(text)
|
70
|
+
# ]
|
71
|
+
# expected = [
|
72
|
+
# {
|
73
|
+
# 'container_id' => '1888b6a06ef7',
|
74
|
+
# 'container_name' => '/demo_frontend_1',
|
75
|
+
# 'content_size' => '329',
|
76
|
+
# 'referer' => 'https://demo.openware.work/trading/copyright/batusdt',
|
77
|
+
# 'message' => 'GET /static/media/search.f6cf3254.svg HTTP/1.1',
|
78
|
+
# 'source' => 'stdout',
|
79
|
+
# 'status_code' => 200,
|
80
|
+
# 'upstream_ip' => '192.168.80.32',
|
81
|
+
# 'user_agent' => 'Mozilla/5.0 (Linux; Android 8.0.0; SAMSUNG SM-J330FN/J330FNXXS3BSE1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/11.1 Chrome/75.0.3770.143 Mobile Safari/537.36',
|
82
|
+
# 'user_ip' => '123.456.789.0'
|
83
|
+
# }
|
84
|
+
# ]
|
85
|
+
# assert_equal(expected, filter(messages))
|
86
|
+
# end
|
87
|
+
|
88
|
+
# test 'json apache logs (influx example)' do
|
89
|
+
# text = '{"source":"stderr","log":"[httpd] 192.168.128.5 - root [31/Mar/2020:08:26:58 +0000] \"GET /query?db=peatio_production&epoch=s&p=%5BREDACTED%5D&precision=s&q=SELECT+%2A+FROM+candles_3d+WHERE+market%3D%27ethusd%27+ORDER+BY+desc+LIMIT+1 HTTP/1.1\" 200 181 \"-\" \"Ruby\" 6371fccd-7329-11ea-aef5-0242c0a8800b 384","container_id":"c0f3b3778","container_name":"/dev01_influxdb_1"}'
|
90
|
+
# messages = [
|
91
|
+
# JSON.parse(text)
|
92
|
+
# ]
|
93
|
+
# expected = [
|
94
|
+
# {
|
95
|
+
# 'container_id' => 'c0f3b3778',
|
96
|
+
# 'container_name' => '/dev01_influxdb_1',
|
97
|
+
# 'content_size' => '181',
|
98
|
+
# 'referer' => '-',
|
99
|
+
# 'message' => 'GET /query?db=peatio_production&epoch=s&p=%5BREDACTED%5D&precision=s&q=SELECT+%2A+FROM+candles_3d+WHERE+market%3D%27ethusd%27+ORDER+BY+desc+LIMIT+1 HTTP/1.1',
|
100
|
+
# 'source' => 'stderr',
|
101
|
+
# 'status_code' => 200,
|
102
|
+
# 'upstream_ip' => '192.168.128.5',
|
103
|
+
# 'user_agent' => 'Ruby'
|
104
|
+
# }
|
105
|
+
# ]
|
106
|
+
# assert_equal(expected, filter(messages))
|
107
|
+
# end
|
108
|
+
|
109
|
+
# test 'json vault logs (with level)' do
|
110
|
+
# text = '{"container_name":"/demo_vault_1","source":"stderr","log":"2020-03-30T09:53:21.323Z [WARNING] no `api_addr` value specified in config or in VAULT_API_ADDR; falling back to detection if possible, but this value should be manually set","container_id":"4f82763814e"}'
|
111
|
+
# messages = [
|
112
|
+
# JSON.parse(text)
|
113
|
+
# ]
|
114
|
+
# expected = [
|
115
|
+
# {
|
116
|
+
# 'container_id' => '4f82763814e',
|
117
|
+
# 'container_name' => '/demo_vault_1',
|
118
|
+
# 'level' => 'WARN',
|
119
|
+
# 'message' => ' no `api_addr` value specified in config or in VAULT_API_ADDR; falling back to detection if possible, but this value should be manually set',
|
120
|
+
# 'source' => 'stderr'
|
121
|
+
# }
|
122
|
+
# ]
|
123
|
+
# assert_equal(expected, filter(messages))
|
124
|
+
# end
|
125
|
+
|
126
|
+
# test 'json vault logs (unformated)' do
|
127
|
+
# text = '{"container_name":"/demo_vault_1","source":"stdout","log":"Version: Vault v1.3.0","container_id":"4f82763814e"}'
|
128
|
+
# messages = [
|
129
|
+
# JSON.parse(text)
|
130
|
+
# ]
|
131
|
+
# expected = [
|
132
|
+
# {
|
133
|
+
# 'container_id' => '4f82763814e',
|
134
|
+
# 'container_name' => '/demo_vault_1',
|
135
|
+
# 'message' => 'Version: Vault v1.3.0',
|
136
|
+
# 'source' => 'stdout'
|
137
|
+
# }
|
138
|
+
# ]
|
139
|
+
# assert_equal(expected, filter(messages))
|
140
|
+
# end
|
141
|
+
|
142
|
+
# test 'json rabbitmq logs' do
|
143
|
+
# text = '{"source":"stdout","log":"2020-03-30 09:54:51.627 [note] <0.734.0> connection <0.734.0> (192.168.128.5:49388 -> 192.168.128.4:5672): user \'guest\' authenticated and granted access to vhost \'/\'","container_id":"40b5e1bde","container_name":"/dev01_rabbitmq_1"}'
|
144
|
+
# messages = [
|
145
|
+
# JSON.parse(text)
|
146
|
+
# ]
|
147
|
+
|
148
|
+
# expected = [
|
149
|
+
# {
|
150
|
+
# 'container_id' => '40b5e1bde',
|
151
|
+
# 'container_name' => '/dev01_rabbitmq_1',
|
152
|
+
# 'message' => '<0.734.0> connection <0.734.0> (192.168.128.5:49388 -> 192.168.128.4:5672): user \'guest\' authenticated and granted access to vhost \'/\'',
|
153
|
+
# 'source' => 'stdout',
|
154
|
+
# 'level' => 'INFO'
|
155
|
+
# }
|
156
|
+
# ]
|
157
|
+
# assert_equal(expected, filter(messages))
|
158
|
+
# end
|
159
|
+
|
160
|
+
# test 'json ruby (json error simple)' do
|
161
|
+
# text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"{\"level\":\"ERROR\",\"time\":\"2020-03-31 21:54:05\",\"message\":\"#<Peatio::Blockchain::ClientError: Failed to open TCP connection to parity:8545 (getaddrinfo: Name or service not known)>\"}"}'
|
162
|
+
# messages = [
|
163
|
+
# JSON.parse(text)
|
164
|
+
# ]
|
165
|
+
|
166
|
+
# expected = [
|
167
|
+
# {
|
168
|
+
# 'container_id' => '7d3ac22',
|
169
|
+
# 'container_name' => '/dev01_blockchain_1',
|
170
|
+
# 'message' => '#<Peatio::Blockchain::ClientError: Failed to open TCP connection to parity:8545 (getaddrinfo: Name or service not known)>',
|
171
|
+
# 'source' => 'stderr',
|
172
|
+
# 'level' => 'ERROR',
|
173
|
+
# 'time' => '2020-03-31 21:54:05'
|
174
|
+
# }
|
175
|
+
# ]
|
176
|
+
# assert_equal(expected, filter(messages))
|
177
|
+
# end
|
178
|
+
|
179
|
+
# test 'json ruby (json error 2)' do
|
180
|
+
# text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"{\"level\":\"ERROR\",\"time\":\"2020-03-31 21:55:56\",\"message\":\"/home/app/lib/peatio/ethereum/blockchain.rb:60:in `rescue in latest_block_number\'\\\\n/home/app/lib/peatio/ethereum/blockchain.rb:57:in `latest_block_number\'\\\\n/home/app/app/services/blockchain_service.rb:16:in `latest_block_number\'\\\\n/home/app/app/workers/daemons/blockchain.rb:22:in `process\'\\\\n/home/app/app/workers/daemons/blockchain.rb:9:in `block (3 levels) in run\'\"}"}'
|
181
|
+
# messages = [
|
182
|
+
# JSON.parse(text)
|
183
|
+
# ]
|
184
|
+
|
185
|
+
# expected = [
|
186
|
+
# {
|
187
|
+
# 'container_id' => '7d3ac22',
|
188
|
+
# 'container_name' => '/dev01_blockchain_1',
|
189
|
+
# 'message' =>
|
190
|
+
# "/home/app/lib/peatio/ethereum/blockchain.rb:60:in `rescue in latest_block_number'\n" \
|
191
|
+
# "/home/app/lib/peatio/ethereum/blockchain.rb:57:in `latest_block_number'\n" \
|
192
|
+
# "/home/app/app/services/blockchain_service.rb:16:in `latest_block_number'\n" \
|
193
|
+
# "/home/app/app/workers/daemons/blockchain.rb:22:in `process'\n" \
|
194
|
+
# "/home/app/app/workers/daemons/blockchain.rb:9:in `block (3 levels) in run'",
|
195
|
+
# 'source' => 'stderr',
|
196
|
+
# 'level' => 'ERROR',
|
197
|
+
# 'time' => '2020-03-31 21:55:56'
|
198
|
+
# }
|
199
|
+
# ]
|
200
|
+
# assert_equal(expected, filter(messages))
|
201
|
+
# end
|
202
|
+
|
203
|
+
# test 'json ruby (logger example debug)' do
|
204
|
+
# text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"D, [2020-04-01T13:04:30.445223 #1] DEBUG -- : received websocket message: [156,\\"te\\",[431756335,1585746269293,0.6,131.83]]"}'
|
205
|
+
# messages = [
|
206
|
+
# JSON.parse(text)
|
207
|
+
# ]
|
208
|
+
|
209
|
+
# expected = [
|
210
|
+
# {
|
211
|
+
# 'container_id' => '7d3ac22',
|
212
|
+
# 'container_name' => '/dev01_blockchain_1',
|
213
|
+
# 'message' => 'received websocket message: [156,"te",[431756335,1585746269293,0.6,131.83]]',
|
214
|
+
# 'source' => 'stderr',
|
215
|
+
# 'level' => 'DEBUG'
|
216
|
+
# }
|
217
|
+
# ]
|
218
|
+
# assert_equal(expected, filter(messages))
|
219
|
+
# end
|
220
|
+
|
221
|
+
# test 'json ruby (logger example info 1)' do
|
222
|
+
# text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"I, [2020-04-01T13:04:30.471779 #1] INFO -- : Publishing trade event: {\\"tid\\"=>431756335, \\"amount\\"=>0.6e0, \\"price\\"=>131.83, \\"date\\"=>1585746269, \\"taker_type\\"=>\\"buy\\"\\}"}'
|
223
|
+
# messages = [
|
224
|
+
# JSON.parse(text)
|
225
|
+
# ]
|
226
|
+
|
227
|
+
# expected = [
|
228
|
+
# {
|
229
|
+
# 'container_id' => '7d3ac22',
|
230
|
+
# 'container_name' => '/dev01_blockchain_1',
|
231
|
+
# 'message' => 'Publishing trade event: {"tid"=>431756335, "amount"=>0.6e0, "price"=>131.83, "date"=>1585746269, "taker_type"=>"buy"}',
|
232
|
+
# 'source' => 'stderr',
|
233
|
+
# 'level' => 'INFO'
|
234
|
+
# }
|
235
|
+
# ]
|
236
|
+
# assert_equal(expected, filter(messages))
|
237
|
+
# end
|
238
|
+
|
239
|
+
# test 'json ruby (logger example info 2)' do
|
240
|
+
# text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"I, [2020-04-01T18:47:00.480183 #1] INFO -- : [3ce041fb-32f9-462b-950b-34e1ba4904f7] Completed 200 OK in 7ms (Views: 5.6ms | Allocations: 6356)"}'
|
241
|
+
# messages = [
|
242
|
+
# JSON.parse(text)
|
243
|
+
# ]
|
244
|
+
|
245
|
+
# expected = [
|
246
|
+
# {
|
247
|
+
# 'container_id' => '7d3ac22',
|
248
|
+
# 'container_name' => '/dev01_blockchain_1',
|
249
|
+
# 'message' => '[3ce041fb-32f9-462b-950b-34e1ba4904f7] Completed 200 OK in 7ms (Views: 5.6ms | Allocations: 6356)',
|
250
|
+
# 'source' => 'stderr',
|
251
|
+
# 'level' => 'INFO'
|
252
|
+
# }
|
253
|
+
# ]
|
254
|
+
# assert_equal(expected, filter(messages))
|
255
|
+
# end
|
256
|
+
|
257
|
+
# test 'json parity (block imported)' do
|
258
|
+
# text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC Verifier #7 INFO import Imported #17687508 0xf356…d999 (0 txs, 0.00 Mgas, 1 ms, 0.58 KiB) + another 1 block(s) containing 0 tx(s)"}'
|
259
|
+
# messages = [
|
260
|
+
# JSON.parse(text)
|
261
|
+
# ]
|
262
|
+
|
263
|
+
# expected = [
|
264
|
+
# {
|
265
|
+
# 'container_id' => '7d3ac22',
|
266
|
+
# 'container_name' => '/dev01_parity_1',
|
267
|
+
# 'message' => 'Verifier #7 INFO import Imported #17687508 0xf356…d999 (0 txs, 0.00 Mgas, 1 ms, 0.58 KiB) + another 1 block(s) containing 0 tx(s)',
|
268
|
+
# 'source' => 'stderr',
|
269
|
+
# 'level' => 'INFO'
|
270
|
+
# }
|
271
|
+
# ]
|
272
|
+
# assert_equal(expected, filter(messages))
|
273
|
+
# end
|
274
|
+
|
275
|
+
# test 'json parity (peer report ok)' do
|
276
|
+
# text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC IO Worker #0 INFO import 19/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs"}'
|
277
|
+
# messages = [
|
278
|
+
# JSON.parse(text)
|
279
|
+
# ]
|
280
|
+
|
281
|
+
# expected = [
|
282
|
+
# {
|
283
|
+
# 'container_id' => '7d3ac22',
|
284
|
+
# 'container_name' => '/dev01_parity_1',
|
285
|
+
# 'message' => 'IO Worker #0 INFO import 19/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs',
|
286
|
+
# 'peers' => '19',
|
287
|
+
# 'peers_max' => '50',
|
288
|
+
# 'source' => 'stderr',
|
289
|
+
# 'level' => 'INFO'
|
290
|
+
# }
|
291
|
+
# ]
|
292
|
+
# assert_equal(expected, filter(messages))
|
293
|
+
# end
|
294
|
+
|
295
|
+
# test 'json parity (peer report warn)' do
|
296
|
+
# text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC IO Worker #0 INFO import 10/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs"}'
|
297
|
+
# messages = [
|
298
|
+
# JSON.parse(text)
|
299
|
+
# ]
|
300
|
+
|
301
|
+
# expected = [
|
302
|
+
# {
|
303
|
+
# 'container_id' => '7d3ac22',
|
304
|
+
# 'container_name' => '/dev01_parity_1',
|
305
|
+
# 'message' => 'IO Worker #0 INFO import 10/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs',
|
306
|
+
# 'peers' => '10',
|
307
|
+
# 'peers_max' => '50',
|
308
|
+
# 'source' => 'stderr',
|
309
|
+
# 'level' => 'WARN'
|
310
|
+
# }
|
311
|
+
# ]
|
312
|
+
# assert_equal(expected, filter(messages))
|
313
|
+
# end
|
314
|
+
|
315
|
+
# test 'json parity (peer report error)' do
|
316
|
+
# text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC IO Worker #0 INFO import 5/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs"}'
|
317
|
+
# messages = [
|
318
|
+
# JSON.parse(text)
|
319
|
+
# ]
|
320
|
+
|
321
|
+
# expected = [
|
322
|
+
# {
|
323
|
+
# 'container_id' => '7d3ac22',
|
324
|
+
# 'container_name' => '/dev01_parity_1',
|
325
|
+
# 'message' => 'IO Worker #0 INFO import 5/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs',
|
326
|
+
# 'peers' => '5',
|
327
|
+
# 'peers_max' => '50',
|
328
|
+
# 'source' => 'stderr',
|
329
|
+
# 'level' => 'ERROR'
|
330
|
+
# }
|
331
|
+
# ]
|
332
|
+
# assert_equal(expected, filter(messages))
|
333
|
+
# end
|
334
|
+
|
335
|
+
# test 'json ranger metrics 1' do
|
336
|
+
# text = '{"container_id":"7d3ac22","container_name":"/dev01_ranger_1","source":"stderr","log":"ranger_connections_total{auth=\\"public\\"}: 44"}'
|
337
|
+
# messages = [
|
338
|
+
# JSON.parse(text)
|
339
|
+
# ]
|
340
|
+
|
341
|
+
# expected = [
|
342
|
+
# {
|
343
|
+
# 'container_id' => '7d3ac22',
|
344
|
+
# 'container_name' => '/dev01_ranger_1',
|
345
|
+
# 'message' => 'ranger_connections_total{auth="public"}: 44',
|
346
|
+
# 'source' => 'stderr',
|
347
|
+
# 'level' => 'INFO'
|
348
|
+
# }
|
349
|
+
# ]
|
350
|
+
# assert_equal(expected, filter(messages))
|
351
|
+
# end
|
352
|
+
|
353
|
+
# test 'json ranger metrics 2' do
|
354
|
+
# text = '{"container_id":"7d3ac22","container_name":"/dev01_ranger_1","source":"stderr","log":"ranger_subscriptions_current: 0"}'
|
355
|
+
# messages = [
|
356
|
+
# JSON.parse(text)
|
357
|
+
# ]
|
358
|
+
|
359
|
+
# expected = [
|
360
|
+
# {
|
361
|
+
# 'container_id' => '7d3ac22',
|
362
|
+
# 'container_name' => '/dev01_ranger_1',
|
363
|
+
# 'message' => 'ranger_subscriptions_current: 0',
|
364
|
+
# 'source' => 'stderr',
|
365
|
+
# 'level' => 'INFO'
|
366
|
+
# }
|
367
|
+
# ]
|
368
|
+
# assert_equal(expected, filter(messages))
|
369
|
+
# end
|
370
|
+
|
371
|
+
# test 'container json logs: rails grape debug logs' do
|
372
|
+
# text = '{"container_id":"7d3ac22","container_name":"/demo_nginx-ingress-controller_1","source":"stderr","log":"{\"date\":\"2020-04-07T08:54:04.892+00:00\",\"severity\":\"WARN\",\"data\":{\"status\":200,\"time\":{\"total\":0.49,\"db\":0,\"view\":0.49},\"method\":\"GET\",\"path\":\"/api/v2/identity/ping\",\"params\":{},\"host\":\"10.24.0.4\",\"response\":[{\"ping\":\"pong\"}],\"ip\":\"\",\"ua\":\"kube-probe/1.14+\",\"headers\":{\"Version\":\"HTTP/1.1\",\"Host\":\"10.24.0.4:8080\",\"User-Agent\":\"kube-probe/1.14+\",\"Accept-Encoding\":\"gzip\",\"Connection\":\"close\",\"X-Forwarded-For\":\"\"}}}"}'
|
373
|
+
# messages = [
|
374
|
+
# JSON.parse(text)
|
375
|
+
# ]
|
376
|
+
|
377
|
+
# expected = [
|
378
|
+
# {
|
379
|
+
# 'container_id' => '7d3ac22',
|
380
|
+
# 'container_name' => '/demo_nginx-ingress-controller_1',
|
381
|
+
# 'message' => '{"status":200,"time":{"total":0.49,"db":0,"view":0.49},"method":"GET","path":"/api/v2/identity/ping","params":{},"host":"10.24.0.4","response":[{"ping":"pong"}],"ip":"","ua":"kube-probe/1.14+","headers":{"Version":"HTTP/1.1","Host":"10.24.0.4:8080","User-Agent":"kube-probe/1.14+","Accept-Encoding":"gzip","Connection":"close","X-Forwarded-For":""}}',
|
382
|
+
# 'source' => 'stderr',
|
383
|
+
# 'status_code' => 200,
|
384
|
+
# 'date' => '2020-04-07T08:54:04.892+00:00',
|
385
|
+
# 'severity' => 'WARN',
|
386
|
+
# 'level' => 'DEBUG'
|
387
|
+
# }
|
388
|
+
# ]
|
389
|
+
# assert_equal(expected, filter(messages))
|
390
|
+
# end
|
391
|
+
|
392
|
+
# test 'container json logs: nginx-ingress-controller INFO' do
|
393
|
+
# text = '{"container_id":"7d3ac22","container_name":"/demo_nginx-ingress-controller_1","source":"stderr","log":"I0406 13:28:52.745452 12 store.go:447] secret core-app/demo-openware-com-tls was updated and it is used in ingress annotations. Parsing..."}'
|
394
|
+
# messages = [
|
395
|
+
# JSON.parse(text)
|
396
|
+
# ]
|
397
|
+
|
398
|
+
# expected = [
|
399
|
+
# {
|
400
|
+
# 'container_id' => '7d3ac22',
|
401
|
+
# 'container_name' => '/demo_nginx-ingress-controller_1',
|
402
|
+
# 'message' => '12 store.go:447] secret core-app/demo-openware-com-tls was updated and it is used in ingress annotations. Parsing...',
|
403
|
+
# 'source' => 'stderr',
|
404
|
+
# 'level' => 'INFO'
|
405
|
+
# }
|
406
|
+
# ]
|
407
|
+
# assert_equal(expected, filter(messages))
|
408
|
+
# end
|
409
|
+
|
410
|
+
# test 'container json logs: nginx-ingress-controller WARN' do
|
411
|
+
# text = '{"container_id":"7d3ac22","container_name":"/demo_nginx-ingress-controller_1","source":"stderr","log":"W0406 13:28:52.746053 12 backend_ssl.go:46] Error obtaining X.509 certificate: unexpected error creating SSL Cert: certificate and private key does not have a matching public key: tls: private key does not match public key"}'
|
412
|
+
# messages = [
|
413
|
+
# JSON.parse(text)
|
414
|
+
# ]
|
415
|
+
|
416
|
+
# expected = [
|
417
|
+
# {
|
418
|
+
# 'container_id' => '7d3ac22',
|
419
|
+
# 'container_name' => '/demo_nginx-ingress-controller_1',
|
420
|
+
# 'message' => '12 backend_ssl.go:46] Error obtaining X.509 certificate: unexpected error creating SSL Cert: certificate and private key does not have a matching public key: tls: private key does not match public key',
|
421
|
+
# 'source' => 'stderr',
|
422
|
+
# 'level' => 'WARN'
|
423
|
+
# }
|
424
|
+
# ]
|
425
|
+
# assert_equal(expected, filter(messages))
|
426
|
+
# end
|
427
|
+
|
428
|
+
# test 'container json logs: cert-manager INFO' do
|
429
|
+
# text = '{"container_id":"7d3ac22","container_name":"/cert-manager","source":"stderr","log":"I0407 07:46:06.757038 1 sync.go:445] cert-manager/controller/certificates \"level\"=0 \"msg\"=\"decoding certificate data\" \"related_resource_kind\"=\"CertificateRequest\" \"related_resource_name\"=\"demo-openware-com-tls-391607007\" \"related_resource_namespace\"=\"core-app\" \"resource_kind\"=\"Certificate\" \"resource_name\"=\"demo-openware-com-tls\" \"resource_namespace\"=\"core-app\""}'
|
430
|
+
# messages = [
|
431
|
+
# JSON.parse(text)
|
432
|
+
# ]
|
433
|
+
|
434
|
+
# expected = [
|
435
|
+
# {
|
436
|
+
# 'container_id' => '7d3ac22',
|
437
|
+
# 'container_name' => '/cert-manager',
|
438
|
+
# 'message' => '1 sync.go:445] cert-manager/controller/certificates "level"=0 "msg"="decoding certificate data" "related_resource_kind"="CertificateRequest" "related_resource_name"="demo-openware-com-tls-391607007" "related_resource_namespace"="core-app" "resource_kind"="Certificate" "resource_name"="demo-openware-com-tls" "resource_namespace"="core-app"',
|
439
|
+
# 'source' => 'stderr',
|
440
|
+
# 'level' => 'INFO'
|
441
|
+
# }
|
442
|
+
# ]
|
443
|
+
# assert_equal(expected, filter(messages))
|
444
|
+
# end
|
401
445
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-filter-logs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Camille Meulien
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logfmt
|