Skip to content

Commit

Permalink
Remove duplicate patterns JAVACLASS and JAVAFILE
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvd committed Nov 19, 2018
1 parent 4ba9bf5 commit 0204239
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 0 additions & 2 deletions patterns/java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ JAVAMETHOD (?:(<(?:cl)?init>)|[a-zA-Z$_][a-zA-Z$_0-9]*)
JAVASTACKTRACEPART %{SPACE}at %{JAVACLASS:class}\.%{JAVAMETHOD:method}\(%{JAVAFILE:file}(?::%{NUMBER:line})?\)
# Java Logs
JAVATHREAD (?:[A-Z]{2}-Processor[\d]+)
JAVACLASS (?:[a-zA-Z0-9-]+\.)+[A-Za-z0-9$]+
JAVAFILE (?:[A-Za-z0-9_.-]+)
JAVALOGMESSAGE (.*)
# MMM dd, yyyy HH:mm:ss eg: Jan 9, 2014 7:13:13 AM
CATALINA_DATESTAMP %{MONTH} %{MONTHDAY}, 20%{YEAR} %{HOUR}:?%{MINUTE}(?::?%{SECOND}) (?:AM|PM)
Expand Down
18 changes: 18 additions & 0 deletions spec/patterns/java_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# encoding: utf-8
require "spec_helper"
require "logstash/patterns/core"

describe "JAVA" do
describe "JAVACLASS" do
let(:example) { 'hudson.node_monitors.AbstractAsyncNodeMonitorDescriptor' }
it "matches a java class with underscores" do
expect(grok_match(subject, example, true)['tags']).to be_nil
end
end
describe "JAVAFILE" do
let(:example) { 'Native Method' }
it "matches a java file name with spaces" do
expect(grok_match(subject, example, true)['tags']).to be_nil
end
end
end
12 changes: 8 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ def pattern_path(path)
require "logstash/filters/grok"

module GrokHelpers
def grok_match(label, message)
grok = build_grok(label)
def grok_match(label, message, exact_match = false)
grok = build_grok(label, exact_match)
event = build_event(message)
grok.filter(event)
event.to_hash
end

def build_grok(label)
grok = LogStash::Filters::Grok.new("match" => ["message", "%{#{label}}"])
def build_grok(label, exact_match = false)
if exact_match
grok = LogStash::Filters::Grok.new("match" => ["message", "^%{#{label}}$"])
else
grok = LogStash::Filters::Grok.new("match" => ["message", "%{#{label}}"])
end
grok.register
grok
end
Expand Down

0 comments on commit 0204239

Please sign in to comment.