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

tag _cefparsefailure on parse failure #26

Merged
merged 2 commits into from
Nov 17, 2016
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.1.0
- add _cefparsefailure tag on failed decode

## 3.0.0
- breaking: Updated plugin to use new Java Event APIs

Expand Down
6 changes: 6 additions & 0 deletions lib/logstash/codecs/cef.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# Implementation of a Logstash codec for the ArcSight Common Event Format (CEF)
# Based on Revision 20 of Implementing ArcSight CEF, dated from June 05, 2013
# https://protect724.hp.com/servlet/JiveServlet/downloadBody/1072-102-6-4697/CommonEventFormat.pdf
#
# If this codec receives a payload from an input that is not a valid CEF message, then it will
# produce an event with the payload as the 'message' field and a '_cefparsefailure' tag.
class LogStash::Codecs::CEF < LogStash::Codecs::Base
config_name "cef"

Expand Down Expand Up @@ -114,6 +117,9 @@ def decode(data)
end

yield event
rescue => e
@logger.error("Failed to decode CEF payload. Generating failure event with payload in message field.", :error => e.message, :backtrace => e.backtrace, :data => data)
yield LogStash::Event.new("message" => data, "tags" => ["_cefparsefailure"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

logstash-filter-json allows to configure the tag for the failure case: https://github.com/logstash-plugins/logstash-filter-json/blob/master/lib/logstash/filters/json.rb#L60
should we provide similar behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

they most used one (codec json) doesn't allow it, so I'm not that concerned, maybe we can have this as is and eventually add it if needed?

end

public
Expand Down
2 changes: 1 addition & 1 deletion logstash-codec-cef.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-codec-cef'
s.version = '3.0.0'
s.version = '3.1.0'
s.platform = 'java'
s.licenses = ['Apache License (2.0)']
s.summary = "CEF codec to parse and encode CEF formated logs"
Expand Down
11 changes: 10 additions & 1 deletion spec/codecs/cef_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,16 @@ def validate(e)
subject.decode(syslog) do |e|
validate(e)
insist { e.get('syslog') } == 'Syslogdate Sysloghost'
end
end
end

context "when payload is not in CEF" do
let (:message) { "potatoes" }
it "Should detect headers before CEF starts" do
subject.decode(message) do |e|
insist { e.get('tags') } == ['_cefparsefailure']
end
end
end
end

Expand Down