Skip to content

MONTHDAY must not require a leading zero for day-of-month < 10 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions logstash-patterns-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'logstash', '>= 1.4.0', '< 2.0.0'

s.add_development_dependency 'logstash-devutils'
s.add_development_dependency 'logstash-filter-grok'
end

2 changes: 1 addition & 1 deletion patterns/grok-patterns
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ URI %{URIPROTO}://(?:%{USER}(?::[^@]*)?@)?(?:%{URIHOST})?(?:%{URIPATHPARAM})?
MONTH \b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b
MONTHNUM (?:0?[1-9]|1[0-2])
MONTHNUM2 (?:0[1-9]|1[0-2])
MONTHDAY (?:(?:0[1-9])|(?:[12][0-9])|(?:3[01])|[1-9])
MONTHDAY (?:(?:(0|\s)?[1-9])|(?:[12][0-9])|(?:3[01])|[1-9])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So. of if you breakdown the original regexp by brancheS:

  • (?:0[1-9])
  • (?:[12][0-9])
  • (?:3[01])
  • [1-9]

This should already match single-digit month numbers.

Further, this patch makes a space part of the MONTHDAY match, which is not, in my opinion, the correct behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should already match single-digit month numbers.

Specifically, when I read this original regexp, I believe it would match single-digit numbers. If it doesn't, this is obivously a bug as you have reported, but I want to make sure we fix the bug which is located at the end of the old regexp, not the beginning.
Hmm...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I agree that the whitespace match probably should not be part of the MONTHDAY match.

On a side note, I think that the original:

(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01])|[1-9])

is equivalent to the following:

(?:(?:0?[1-9])|(?:[12][0-9])|(?:3[01]))

I don't know if the shorter one is an improvement though.


# Days: Monday, Tue, Thu, etc...
DAY (?:Mon(?:day)?|Tue(?:sday)?|Wed(?:nesday)?|Thu(?:rsday)?|Fri(?:day)?|Sat(?:urday)?|Sun(?:day)?)
Expand Down
41 changes: 41 additions & 0 deletions spec/patterns/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,45 @@
require 'logstash/patterns/core'

describe LogStash::Patterns::Core do
describe "rfc822 dates" do
config <<-CONFIG
filter {
grok {
match => {
"message" => [
"%{DATESTAMP_RFC2822}",
"%{MONTH} %{MONTHDAY} %{HOUR}:%{MINUTE}:%{SECOND}"
]
}
named_captures_only => false
}
}
CONFIG

sample "Mon, 12 May 2014 17:00:32 -0500" do
insist { subject["DATESTAMP_RFC2822"] } == "Mon, 12 May 2014 17:00:32 -0500"
insist { subject["MONTHDAY"] } == "12"
end

# As occurs in a syslog/maillog message such as:
# lmtpunix[$pid]: dupelim: eliminated duplicate message to domain!user.john <message-id> date Mon, 5 May 2014 17:00:32 -0500 (delivery)
sample "Mon, 5 May 2014 17:00:32 -0500" do
insist { subject["DATESTAMP_RFC2822"] } == "Mon, 5 May 2014 17:00:32 -0500"
insist { subject["MONTHDAY"] } == "5"
end

# As might occur in a syslog/maillog message such as:
# postfix/anvil[$pid]: statistics: max cache size 28 at May 6 00:02:47
# Note: The match will have a space, but this does not prevent conversion to integer.
sample "May 6 00:02:47" do
insist { subject["MONTHDAY"] } == " 6"
end

# With a 0 prefix
sample "May 06 00:02:47" do
insist { subject["MONTHDAY"] } == "06"
end

end

end