Skip to content
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

Remove duplicate patterns JAVACLASS and JAVAFILE #237

Merged
merged 1 commit into from
Nov 19, 2018
Merged
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
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