Skip to content

Commit bcc8783

Browse files
authored
Merge pull request #175 from yaauie/ecs-v8-preview
ecs: add v8 preview using v1 implementation
2 parents b52929b + fe022ce commit bcc8783

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.4.1
2+
- Added preview of ECS v8 support using existing ECS v1 implementation [#175](https://github.com/logstash-plugins/logstash-filter-grok/pull/175)
3+
14
## 4.4.0
25
- Feat: ECS compatibility support [#162](https://github.com/logstash-plugins/logstash-filter-grok/pull/162)
36

docs/index.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ parsing different things), then set this to false.
235235
* Value type is <<string,string>>
236236
* Supported values are:
237237
** `disabled`: the plugin will load legacy (built-in) pattern definitions
238-
** `v1`: all patterns provided by the plugin will use ECS compliant captures
238+
** `v1`,`v8`: all patterns provided by the plugin will use ECS compliant captures
239239
* Default value depends on which version of Logstash is running:
240240
** When Logstash provides a `pipeline.ecs_compatibility` setting, its value is used as the default
241241
** Otherwise, the default value is `disabled`.

lib/logstash/filters/grok.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@ def patterns_path
332332
patterns_path << LogStash::Patterns::Core.path # :legacy
333333
when :v1
334334
patterns_path << LogStash::Patterns::Core.path('ecs-v1')
335+
when :v8
336+
@logger.warn("ECS v8 support is a preview of the unreleased ECS v8, and uses the v1 patterns. When Version 8 of the Elastic Common Schema becomes available, this plugin will need to be updated")
337+
patterns_path << LogStash::Patterns::Core.path('ecs-v1')
335338
else
336339
fail(NotImplementedError, "ECS #{ecs_compatibility} is not supported by this plugin.")
337340
end

logstash-filter-grok.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-filter-grok'
3-
s.version = '4.4.0'
3+
s.version = '4.4.1'
44
s.licenses = ['Apache License (2.0)']
55
s.summary = "Parses unstructured event data into fields"
66
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"

spec/filters/grok_spec.rb

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ def self.sample(message, &block)
3838
expect( event.get("pid") ).to eql "1713"
3939
end
4040

41-
context 'in ecs mode' do
42-
let(:config) { super().merge('ecs_compatibility' => 'v1') }
41+
%w(v1 v8).each do |ecs_mode|
42+
context "in ecs mode #{ecs_mode}" do
43+
let(:config) { super().merge('ecs_compatibility' => ecs_mode) }
4344

44-
it "matches pattern" do
45-
expect( event.get("host") ).to eql "hostname"=>"evita"
46-
expect( event.get("process") ).to eql "name"=>"postfix/smtpd", "pid"=>1713
47-
expect( event.get("message") ).to eql "connect from camomile.cloud9.net[168.100.1.3]"
45+
it "matches pattern" do
46+
expect( event.get("host") ).to eql "hostname"=>"evita"
47+
expect( event.get("process") ).to eql "name"=>"postfix/smtpd", "pid"=>1713
48+
expect( event.get("message") ).to eql "connect from camomile.cloud9.net[168.100.1.3]"
49+
end
4850
end
4951
end
5052

@@ -701,7 +703,7 @@ def self.sample(message, &block)
701703
expect( LogStash::Json.dump(event.get('username')) ).to eql "\"testuser\""
702704

703705
expect( event.to_json ).to match %r|"src_ip":"1.1.1.1"|
704-
expect( event.to_json ).to match %r|"@timestamp":"20\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\dZ"|
706+
expect( event.to_json ).to match %r|"@timestamp":"#{Regexp.escape(event.get('@timestamp').to_s)}"|
705707
expect( event.to_json ).to match %r|"port":"22"|
706708
expect( event.to_json ).to match %r|"@version":"1"|
707709
expect( event.to_json ).to match %r|"username"|i
@@ -769,6 +771,26 @@ def self.sample(message, &block)
769771
end
770772
end
771773

774+
describe LogStash::Filters::Grok do
775+
776+
subject(:grok_filter) { described_class.new(config) }
777+
let(:config) { {} }
778+
779+
context 'when initialized with `ecs_compatibility => v8`' do
780+
let(:config) { super().merge("ecs_compatibility" => "v8", "match" => ["message", "%{SYSLOGLINE}"]) }
781+
context '#register' do
782+
let(:logger_stub) { double('Logger').as_null_object }
783+
before(:each) { allow_any_instance_of(described_class).to receive(:logger).and_return(logger_stub)}
784+
785+
it 'logs a helpful warning about the unreleased v8' do
786+
grok_filter.register
787+
788+
expect(logger_stub).to have_received(:warn).with(a_string_including "preview of the unreleased ECS v8")
789+
end
790+
end
791+
end
792+
end
793+
772794
describe LogStash::Filters::Grok do
773795
describe "(LEGACY)" do
774796
describe "patterns in the 'patterns/' dir override core patterns" do

0 commit comments

Comments
 (0)