Skip to content

Commit d4cd709

Browse files
authored
Merge pull request #67 from fluent/fix-regexp-for-grok
Fix regular expression to parse grok
2 parents 09d9a07 + 8087dbf commit d4cd709

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/fluent/plugin/grok.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class GrokPatternNotFoundError < StandardError
1313
(?<pattern>[A-z0-9]+)
1414
(?::(?<subname>[@\[\]A-z0-9_:.-]+?)
1515
(?::(?<type>(?:string|bool|integer|float|
16-
time(?::.+)?|
16+
time(?::.+?)?|
1717
array(?::.)?)))?)?
1818
)
1919
\}/x

test/test_grok_parser.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,21 @@ class GrokParserTest < ::Test::Unit::TestCase
359359
assert_equal(event_time("28/Feb/2013:12:00:00 +0900", format: "%d/%b/%Y:%H:%M:%S %z"), time)
360360
end
361361
end
362+
363+
test "leading time type with following other type" do
364+
d = create_driver(%[
365+
<grok>
366+
pattern \\[%{HTTPDATE:log_timestamp:time:%d/%b/%Y:%H:%M:%S %z}\\] %{GREEDYDATA:message}
367+
</grok>
368+
])
369+
expected_record = {
370+
"log_timestamp" => event_time("03/Feb/2019:06:47:21 +0530", format: "%d/%b/%Y:%H:%M:%S %z"),
371+
"message" => "Python-urllib/2.7"
372+
}
373+
d.instance.parse('[03/Feb/2019:06:47:21 +0530] Python-urllib/2.7') do |time, record|
374+
assert_equal(expected_record, record)
375+
end
376+
end
362377
end
363378

364379
private

0 commit comments

Comments
 (0)