Skip to content

Commit 18f99ff

Browse files
committed
Handle ECS v1 fields as dot notated fileds
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 84e8976 commit 18f99ff

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

lib/fluent/plugin/grok.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,15 @@ def expand_pattern(pattern)
134134
curr_pattern = @pattern_map[m["pattern"]]
135135
raise GrokPatternNotFoundError, "grok pattern not found: #{pattern}" unless curr_pattern
136136
if m["subname"]
137-
replacement_pattern = "(?<#{m["subname"]}>#{curr_pattern})"
138-
type_map[m["subname"]] = m["type"] || "string"
137+
ecs = /(?<ecs-key>(^\[.*\]$))/.match(m["subname"])
138+
subname = if ecs
139+
# remove starting "[" and trailing "]" on matched data
140+
ecs["ecs-key"][1..-2].split("][").join('.')
141+
else
142+
m["subname"]
143+
end
144+
replacement_pattern = "(?<#{subname}>#{curr_pattern})"
145+
type_map[subname] = m["type"] || "string"
139146
else
140147
replacement_pattern = "(?:#{curr_pattern})"
141148
end

test/test_grok_parser.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ class GrokParserTest < ::Test::Unit::TestCase
7979
internal_test_grok_pattern("%{HTTPD_COMBINEDLOG}", '127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777 "-" "Opera/12.0"',
8080
str2time("28/Feb/2013:12:00:00 +0900", "%d/%b/%Y:%H:%M:%S %z"),
8181
{
82-
"[apache][access][user][identity]" => "192.168.0.1",
83-
"[http][request][method]" => "GET",
84-
"[http][response][body][bytes]" => 777,
85-
"[http][response][status_code]" => 200,
86-
"[http][version]" => "1.1",
87-
"[source][address]" => "127.0.0.1",
88-
"[url][original]" => "/",
89-
"[user_agent][original]" => "Opera/12.0",
82+
"apache.access.user.identity" => "192.168.0.1",
83+
"http.request.method" => "GET",
84+
"http.response.body.bytes" => 777,
85+
"http.response.status_code" => 200,
86+
"http.version" => "1.1",
87+
"source.address" => "127.0.0.1",
88+
"url.original" => "/",
89+
"user_agent.original" => "Opera/12.0",
9090
},
9191
"time_key" => "timestamp",
9292
"time_format" => "%d/%b/%Y:%H:%M:%S %z",
@@ -394,14 +394,14 @@ class GrokParserTest < ::Test::Unit::TestCase
394394
</grok>
395395
])
396396
expected_record = {
397-
"[apache][access][user][identity]" => "192.168.0.1",
398-
"[http][request][method]" => "GET",
399-
"[http][response][body][bytes]" => 777,
400-
"[http][response][status_code]" => 200,
401-
"[http][version]" => "1.1",
402-
"[source][address]" => "127.0.0.1",
403-
"[url][original]" => "/",
404-
"[user_agent][original]" => "Opera/12.0"
397+
"apache.access.user.identity" => "192.168.0.1",
398+
"http.request.method" => "GET",
399+
"http.response.body.bytes" => 777,
400+
"http.response.status_code" => 200,
401+
"http.version" => "1.1",
402+
"source.address" => "127.0.0.1",
403+
"url.original" => "/",
404+
"user_agent.original" => "Opera/12.0"
405405
}
406406
d.instance.parse('127.0.0.1 192.168.0.1 - [28/Feb/2013:12:00:00 +0900] "GET / HTTP/1.1" 200 777 "-" "Opera/12.0"') do |time, record|
407407
assert_equal(expected_record, record)

0 commit comments

Comments
 (0)