logstash-filter-grok 4.3.0 → 4.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9d8be42f7b846a0684d25d18ec624a81574b52e394df863afa004d458ecd915
4
- data.tar.gz: 605d0cea73b747d9900bebfc2a99f59d2950300af7ef52ec5b9cb3f556a7d5fd
3
+ metadata.gz: 0d8ab6e291bb1b8412aa14aeba1e555b848ea04473c5e1b16672ef102751f828
4
+ data.tar.gz: db3d113bbb82463cc35036cb0680e91932dbd53dd456cb3a65f5eb79db544fbb
5
5
  SHA512:
6
- metadata.gz: '096791bcc8691300c8e59aa8c6741d499c515b6fc70b3f7e4deea0c23440bce1875d98d7aaad0d6f8d8ab12dc526051e46e2a61b590422d646d7939221ec3fc7'
7
- data.tar.gz: efe3dcc313d22e67986828351b365b9383c5c91d0a4caf8da78bd8c34126e7088d81ce9c672a6dc0758a9c3c4d1e4a2cae53e2df2c79bcd510848b69ecac9945
6
+ metadata.gz: 05d8ebab39fd928e10bd84b6586574fe0583b7a93b8692824ba3bdf0e197969b5c6532eb7d69aa0e703afe0836d17ddd5677fd9dbd09bfcdd955a836f1268ffe
7
+ data.tar.gz: 65bd577d0cc170883fba3ee5ca88f047aec62a03affd4bc63cc23708a660f4f2e8dfa18bdd0bce6cbde613975d20c0c7415e8a97f6eea4dfdbd264ea032c7ed2
data/CHANGELOG.md CHANGED
@@ -1,8 +1,19 @@
1
+ ## 4.4.2
2
+ - Clarify the definition of matches that depend on previous captures [#169](https://github.com/logstash-plugins/logstash-filter-grok/pull/169)
3
+
4
+ ## 4.4.1
5
+ - Added preview of ECS v8 support using existing ECS v1 implementation [#175](https://github.com/logstash-plugins/logstash-filter-grok/pull/175)
6
+
7
+ ## 4.4.0
8
+ - Feat: ECS compatibility support [#162](https://github.com/logstash-plugins/logstash-filter-grok/pull/162)
9
+
10
+ The filter supports using built-in pattern definitions that are fully Elastic Common Schema (ECS) compliant.
11
+
1
12
  ## 4.3.0
2
- - Added: added target support [#156](https://github.com/logstash-plugins/logstash-filter-grok/pull/156)
13
+ - Added: added target support [#156](https://github.com/logstash-plugins/logstash-filter-grok/pull/156)
3
14
 
4
15
  ## 4.2.0
5
- - Added: support for timeout_scope [#153](https://github.com/logstash-plugins/logstash-filter-grok/pull/153)
16
+ - Added: support for timeout_scope [#153](https://github.com/logstash-plugins/logstash-filter-grok/pull/153)
6
17
 
7
18
  ## 4.1.1
8
19
  - Fix formatting for code sample [#148](https://github.com/logstash-plugins/logstash-filter-grok/pull/148)
data/LICENSE CHANGED
@@ -1,13 +1,202 @@
1
- Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
2
1
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
6
5
 
7
- http://www.apache.org/licenses/LICENSE-2.0
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
7
 
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2020 Elastic and contributors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Logstash Plugin
2
2
 
3
- [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-filter-grok.svg)](https://travis-ci.org/logstash-plugins/logstash-filter-grok)
3
+ [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-filter-grok.svg)](https://travis-ci.com/logstash-plugins/logstash-filter-grok)
4
4
 
5
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
6
 
data/docs/index.asciidoc CHANGED
@@ -175,6 +175,21 @@ Another option is to define patterns _inline_ in the filter using `pattern_defin
175
175
  This is mostly for convenience and allows user to define a pattern which can be used just in that
176
176
  filter. This newly defined patterns in `pattern_definitions` will not be available outside of that particular `grok` filter.
177
177
 
178
+ [id="plugins-{type}s-{plugin}-ecs"]
179
+ ==== Migrating to Elastic Common Schema (ECS)
180
+
181
+ To ease migration to the {ecs-ref}[Elastic Common Schema (ECS)], the filter
182
+ plugin offers a new set of ECS-compliant patterns in addition to the existing
183
+ patterns. The new ECS pattern definitions capture event field names that are
184
+ compliant with the schema.
185
+
186
+ The ECS pattern set has all of the pattern definitions from the legacy set, and is
187
+ a drop-in replacement. Use the <<plugins-{type}s-{plugin}-ecs_compatibility>>
188
+ setting to switch modes.
189
+
190
+ New features and enhancements will be added to the ECS-compliant files. The
191
+ legacy patterns may still receive bug fixes which are backwards compatible.
192
+
178
193
 
179
194
  [id="plugins-{type}s-{plugin}-options"]
180
195
  ==== Grok Filter Configuration Options
@@ -185,6 +200,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
185
200
  |=======================================================================
186
201
  |Setting |Input type|Required
187
202
  | <<plugins-{type}s-{plugin}-break_on_match>> |<<boolean,boolean>>|No
203
+ | <<plugins-{type}s-{plugin}-ecs_compatibility>> |<<string,string>>|No
188
204
  | <<plugins-{type}s-{plugin}-keep_empty_captures>> |<<boolean,boolean>>|No
189
205
  | <<plugins-{type}s-{plugin}-match>> |<<hash,hash>>|No
190
206
  | <<plugins-{type}s-{plugin}-named_captures_only>> |<<boolean,boolean>>|No
@@ -213,6 +229,20 @@ Break on first match. The first successful match by grok will result in the
213
229
  filter being finished. If you want grok to try all patterns (maybe you are
214
230
  parsing different things), then set this to false.
215
231
 
232
+ [id="plugins-{type}s-{plugin}-ecs_compatibility"]
233
+ ===== `ecs_compatibility`
234
+
235
+ * Value type is <<string,string>>
236
+ * Supported values are:
237
+ ** `disabled`: the plugin will load legacy (built-in) pattern definitions
238
+ ** `v1`,`v8`: all patterns provided by the plugin will use ECS compliant captures
239
+ * Default value depends on which version of Logstash is running:
240
+ ** When Logstash provides a `pipeline.ecs_compatibility` setting, its value is used as the default
241
+ ** Otherwise, the default value is `disabled`.
242
+
243
+ Controls this plugin's compatibility with the {ecs-ref}[Elastic Common Schema (ECS)].
244
+ The value of this setting affects extracted event field names when a composite pattern (such as `HTTPD_COMMONLOG`) is matched.
245
+
216
246
  [id="plugins-{type}s-{plugin}-keep_empty_captures"]
217
247
  ===== `keep_empty_captures`
218
248
 
@@ -251,6 +281,36 @@ If you need to match multiple patterns against a single field, the value can be
251
281
  }
252
282
  }
253
283
  }
284
+
285
+ To perform matches on multiple fields just use multiple entries in the `match` hash:
286
+
287
+ [source,ruby]
288
+ filter {
289
+ grok {
290
+ match => {
291
+ "speed" => "Speed: %{NUMBER:speed}"
292
+ "duration => "Duration: %{NUMBER:duration}"
293
+ }
294
+ }
295
+ }
296
+
297
+ However, if one pattern depends on a field created by a previous pattern, separate these into two separate grok filters:
298
+
299
+
300
+ [source,ruby]
301
+ filter {
302
+ grok {
303
+ match => {
304
+ "message" => "Hi, the rest of the message is: %{GREEDYDATA:rest}"
305
+ }
306
+ }
307
+ grok {
308
+ match => {
309
+ "rest => "a number %{NUMBER"number}, and a word %{WORD:word}"
310
+ }
311
+ }
312
+ }
313
+
254
314
 
255
315
  [id="plugins-{type}s-{plugin}-named_captures_only"]
256
316
  ===== `named_captures_only`
@@ -283,6 +343,17 @@ overwrite the `message` field with part of the match like so:
283
343
  In this case, a line like `May 29 16:37:11 sadness logger: hello world`
284
344
  will be parsed and `hello world` will overwrite the original message.
285
345
 
346
+ If you are using a field reference in `overwrite`, you must use the field
347
+ reference in the pattern. Example:
348
+ [source,ruby]
349
+ filter {
350
+ grok {
351
+ match => { "somefield" => "%{NUMBER} %{GREEDYDATA:[nested][field][test]}" }
352
+ overwrite => [ "[nested][field][test]" ]
353
+ }
354
+ }
355
+
356
+
286
357
  [id="plugins-{type}s-{plugin}-pattern_definitions"]
287
358
  ===== `pattern_definitions`
288
359
 
@@ -3,8 +3,8 @@
3
3
  require "logstash/namespace"
4
4
  require "logstash/environment"
5
5
  require "logstash/patterns/core"
6
+ require 'logstash/plugin_mixins/ecs_compatibility_support'
6
7
  require "grok-pure" # rubygem 'jls-grok'
7
- require "set"
8
8
  require "timeout"
9
9
 
10
10
  # Parse arbitrary text and structure it.
@@ -144,6 +144,8 @@
144
144
  # filter. This newly defined patterns in `pattern_definitions` will not be available outside of that particular `grok` filter.
145
145
  #
146
146
  class LogStash::Filters::Grok < LogStash::Filters::Base
147
+ include LogStash::PluginMixins::ECSCompatibilitySupport
148
+
147
149
  config_name "grok"
148
150
 
149
151
  # A hash of matches of field => value
@@ -250,22 +252,14 @@
250
252
  # will be parsed and `hello world` will overwrite the original message.
251
253
  config :overwrite, :validate => :array, :default => []
252
254
 
253
- # Register default pattern paths
254
- @@patterns_path ||= Set.new
255
- @@patterns_path += [
256
- LogStash::Patterns::Core.path,
257
- LogStash::Environment.pattern_path("*")
258
- ]
259
-
260
255
  def register
261
256
  # a cache of capture name handler methods.
262
257
  @handlers = {}
263
258
 
264
259
  @patternfiles = []
265
-
266
- # Have @@patterns_path show first. Last-in pattern definitions win; this
267
- # will let folks redefine built-in patterns at runtime.
268
- @patternfiles += patterns_files_from_paths(@@patterns_path.to_a, "*")
260
+ # Have (default) patterns_path show first. Last-in pattern definitions wins
261
+ # this will let folks redefine built-in patterns at runtime
262
+ @patternfiles += patterns_files_from_paths(patterns_path, "*")
269
263
  @patternfiles += patterns_files_from_paths(@patterns_dir, @patterns_files_glob)
270
264
 
271
265
  @patterns = Hash.new { |h,k| h[k] = [] }
@@ -278,11 +272,11 @@
278
272
  patterns = [patterns] if patterns.is_a?(String)
279
273
  @metric_match_fields.gauge(field, patterns.length)
280
274
 
281
- @logger.trace("Grok compile", :field => field, :patterns => patterns)
275
+ @logger.trace? && @logger.trace("Grok compile", :field => field, :patterns => patterns)
282
276
  patterns.each do |pattern|
283
- @logger.debug? and @logger.debug("regexp: #{@type}/#{field}", :pattern => pattern)
277
+ @logger.debug? && @logger.debug("regexp: #{@type}/#{field}", :pattern => pattern)
284
278
  grok = Grok.new
285
- grok.logger = @logger unless @logger.nil?
279
+ grok.logger = @logger
286
280
  add_patterns_from_files(@patternfiles, grok)
287
281
  add_patterns_from_inline_definition(@pattern_definitions, grok)
288
282
  grok.compile(pattern, @named_captures_only)
@@ -301,15 +295,14 @@
301
295
  def filter(event)
302
296
  matched = false
303
297
 
304
- @logger.debug? and @logger.debug("Running grok filter", :event => event)
298
+ @logger.debug? && @logger.debug("Running grok filter", :event => event.to_hash)
305
299
 
306
300
  @patterns.each do |field, groks|
307
301
  if match(groks, field, event)
308
302
  matched = true
309
303
  break if @break_on_match
310
304
  end
311
- #break if done
312
- end # @patterns.each
305
+ end
313
306
 
314
307
  if matched
315
308
  @match_counter.increment(1)
@@ -319,7 +312,7 @@
319
312
  @tag_on_failure.each {|tag| event.tag(tag)}
320
313
  end
321
314
 
322
- @logger.debug? and @logger.debug("Event now: ", :event => event)
315
+ @logger.debug? && @logger.debug("Event now: ", :event => event.to_hash)
323
316
  rescue GrokTimeoutException => e
324
317
  @logger.warn(e.message)
325
318
  metric.increment(:timeouts)
@@ -331,6 +324,27 @@
331
324
 
332
325
  private
333
326
 
327
+ # The default pattern paths, depending on environment.
328
+ def patterns_path
329
+ patterns_path = []
330
+ case ecs_compatibility
331
+ when :disabled
332
+ patterns_path << LogStash::Patterns::Core.path # :legacy
333
+ when :v1
334
+ 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')
338
+ else
339
+ fail(NotImplementedError, "ECS #{ecs_compatibility} is not supported by this plugin.")
340
+ end
341
+ # allow plugin to be instantiated outside the LS environment (in tests)
342
+ if defined? LogStash::Environment.pattern_path
343
+ patterns_path << LogStash::Environment.pattern_path("*")
344
+ end
345
+ patterns_path
346
+ end
347
+
334
348
  def match(groks, field, event)
335
349
  input = event.get(field)
336
350
  if input.is_a?(Array)
@@ -343,7 +357,7 @@
343
357
  match_against_groks(groks, field, input, event)
344
358
  end
345
359
  rescue StandardError => e
346
- @logger.warn("Grok regexp threw exception", :exception => e.message, :backtrace => e.backtrace, :class => e.class.name)
360
+ @logger.warn("Grok regexp threw exception", :message => e.message, :exception => e.class, :backtrace => e.backtrace)
347
361
  return false
348
362
  end
349
363
 
@@ -1,7 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
-
3
2
  s.name = 'logstash-filter-grok'
4
- s.version = '4.3.0'
3
+ s.version = '4.4.2'
5
4
  s.licenses = ['Apache License (2.0)']
6
5
  s.summary = "Parses unstructured event data into fields"
7
6
  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"
@@ -22,10 +21,11 @@ Gem::Specification.new do |s|
22
21
  # Gem dependencies
23
22
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
23
  s.add_runtime_dependency "logstash-core", ">= 5.6.0"
24
+ s.add_runtime_dependency 'logstash-mixin-ecs_compatibility_support', '~> 1.0'
25
25
 
26
26
  s.add_runtime_dependency 'jls-grok', '~> 0.11.3'
27
27
  s.add_runtime_dependency 'stud', '~> 0.0.22'
28
- s.add_runtime_dependency 'logstash-patterns-core'
28
+ s.add_runtime_dependency 'logstash-patterns-core', '>= 4.3.0', '< 5'
29
29
 
30
- s.add_development_dependency 'logstash-devutils', '= 1.3.6'
30
+ s.add_development_dependency 'logstash-devutils'
31
31
  end
@@ -21,13 +21,7 @@ describe LogStash::Filters::Grok do
21
21
 
22
22
  describe "base-line performance", :performance => true do
23
23
 
24
- EXPECTED_MIN_RATE = 15_000 # per second
25
- # NOTE: based on Travis CI (docker) numbers :
26
- # logstash_1_d010d1d29244 | LogStash::Filters::Grok
27
- # logstash_1_d010d1d29244 | base-line performance
28
- # logstash_1_d010d1d29244 | filters/grok parse rate: 14464/sec, elapsed: 20.740866999999998s
29
- # logstash_1_d010d1d29244 | filters/grok parse rate: 29957/sec, elapsed: 10.014199s
30
- # logstash_1_d010d1d29244 | filters/grok parse rate: 32932/sec, elapsed: 9.109601999999999s
24
+ EXPECTED_MIN_RATE = 30_000 # per second - based on Travis CI (docker) numbers
31
25
 
32
26
  let(:config) do
33
27
  { 'match' => { "message" => "%{SYSLOGLINE}" }, 'overwrite' => [ "message" ] }
@@ -87,10 +81,9 @@ describe LogStash::Filters::Grok do
87
81
  puts "filters/grok(timeout => 0) warmed up in #{wout_timeout_duration}"
88
82
  before_sample!
89
83
  no_timeout_durations = Array.new(SAMPLE_COUNT).map do
90
- duration = do_sample_filter(filter_wout_timeout)
91
- puts "filters/grok(timeout => 0) took #{duration}"
92
- duration
84
+ do_sample_filter(filter_wout_timeout)
93
85
  end
86
+ puts "filters/grok(timeout => 0) took #{no_timeout_durations}"
94
87
 
95
88
  expected_duration = avg(no_timeout_durations)
96
89
  expected_duration += (expected_duration / 100) * ACCEPTED_TIMEOUT_DEGRADATION
@@ -100,12 +93,17 @@ describe LogStash::Filters::Grok do
100
93
  with_timeout_duration = do_sample_filter(filter_with_timeout) # warmup
101
94
  puts "filters/grok(timeout_scope => event) warmed up in #{with_timeout_duration}"
102
95
 
103
- before_sample!
104
- expect do
105
- duration = do_sample_filter(filter_with_timeout)
106
- puts "filters/grok(timeout_scope => event) took #{duration}"
107
- duration
108
- end.to perform_under(expected_duration).sample(SAMPLE_COUNT).times
96
+ try(3) do
97
+ before_sample!
98
+ durations = []
99
+ begin
100
+ expect do
101
+ do_sample_filter(filter_with_timeout).tap { |duration| durations << duration }
102
+ end.to perform_under(expected_duration).sample(SAMPLE_COUNT).times
103
+ ensure
104
+ puts "filters/grok(timeout_scope => event) took #{durations}"
105
+ end
106
+ end
109
107
  end
110
108
 
111
109
  @private
@@ -119,10 +117,6 @@ describe LogStash::Filters::Grok do
119
117
  end
120
118
  end
121
119
 
122
- def sample_event(hash)
123
- LogStash::Event.new("message" => SAMPLE_MESSAGE)
124
- end
125
-
126
120
  end
127
121
 
128
122
  @private
@@ -38,6 +38,18 @@ describe LogStash::Filters::Grok do
38
38
  expect( event.get("pid") ).to eql "1713"
39
39
  end
40
40
 
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) }
44
+
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
50
+ end
51
+ end
52
+
41
53
  context 'with target' do
42
54
  let(:config) { { "match" => { "message" => "%{SYSLOGLINE}" }, "target" => "grok" } }
43
55
 
@@ -393,15 +405,17 @@ describe LogStash::Filters::Grok do
393
405
  "message" => [
394
406
  "(.*f){20}", "(.*e){20}", "(.*d){20}", "(.*c){20}", "(.*b){20}",
395
407
  "(.*a){25}", "(.*a){24}", "(.*a){23}", "(.*a){22}", "(.*a){21}",
408
+ "(.*a){25}", "(.*a){24}", "(.*a){23}", "(.*a){22}", "(.*a){21}",
409
+ "(.*a){25}", "(.*a){24}", "(.*a){23}", "(.*a){22}", "(.*a){21}",
396
410
  "(.*a){20}"
397
411
  ]
398
412
  },
399
- 'timeout_millis' => 500,
413
+ 'timeout_millis' => 750,
400
414
  'timeout_scope' => 'pattern'
401
415
  }
402
416
  }
403
417
 
404
- sample( 'b' * 10 + 'c' * 10 + 'd' * 10 + 'e' * 10 + ' ' + 'a' * 20 ) do
418
+ sample( 'b' * 15 + 'c' * 15 + 'd' * 15 + 'e' * 15 + ' ' + 'a' * 20 ) do
405
419
  expect( event.get("tags") ).to be nil
406
420
  end
407
421
  end
@@ -413,15 +427,17 @@ describe LogStash::Filters::Grok do
413
427
  "message" => [
414
428
  "(.*f){20}", "(.*e){20}", "(.*d){20}", "(.*c){20}", "(.*b){20}",
415
429
  "(.*a){25}", "(.*a){24}", "(.*a){23}", "(.*a){22}", "(.*a){21}",
430
+ "(.*a){25}", "(.*a){24}", "(.*a){23}", "(.*a){22}", "(.*a){21}",
431
+ "(.*a){25}", "(.*a){24}", "(.*a){23}", "(.*a){22}", "(.*a){21}",
416
432
  "(.*a){20}"
417
433
  ]
418
434
  },
419
- 'timeout_millis' => 500,
435
+ 'timeout_millis' => 750,
420
436
  'timeout_scope' => 'event'
421
437
  }
422
438
  }
423
439
 
424
- sample( 'b' * 10 + 'c' * 10 + 'd' * 10 + 'e' * 10 + ' ' + 'a' * 20 ) do
440
+ sample( 'b' * 15 + 'c' * 15 + 'd' * 15 + 'e' * 15 + ' ' + 'a' * 20 ) do
425
441
  expect( event.get("tags") ).to include("_groktimeout")
426
442
  expect( event.get("tags") ).not_to include("_grokparsefailure")
427
443
  end
@@ -687,7 +703,7 @@ describe LogStash::Filters::Grok do
687
703
  expect( LogStash::Json.dump(event.get('username')) ).to eql "\"testuser\""
688
704
 
689
705
  expect( event.to_json ).to match %r|"src_ip":"1.1.1.1"|
690
- 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)}"|
691
707
  expect( event.to_json ).to match %r|"port":"22"|
692
708
  expect( event.to_json ).to match %r|"@version":"1"|
693
709
  expect( event.to_json ).to match %r|"username"|i
@@ -755,6 +771,26 @@ describe LogStash::Filters::Grok do
755
771
  end
756
772
  end
757
773
 
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
+
758
794
  describe LogStash::Filters::Grok do
759
795
  describe "(LEGACY)" do
760
796
  describe "patterns in the 'patterns/' dir override core patterns" do
@@ -774,7 +810,7 @@ describe LogStash::Filters::Grok do
774
810
  end
775
811
 
776
812
  sample("message" => 'hello') do
777
- insist { subject.get("tags") } == ["_grokparsefailure"]
813
+ expect(subject.get("tags")).to eql ["_grokparsefailure"]
778
814
  end
779
815
 
780
816
  after do
@@ -804,7 +840,7 @@ describe LogStash::Filters::Grok do
804
840
  end
805
841
 
806
842
  sample("message" => '0') do
807
- insist { subject.get("tags") } == nil
843
+ expect(subject.get("tags")).to be nil
808
844
  end
809
845
 
810
846
  after do
@@ -833,7 +869,7 @@ describe LogStash::Filters::Grok do
833
869
  end
834
870
 
835
871
  sample("message" => '0') do
836
- insist { subject.get("tags") } == nil
872
+ expect(subject.get("tags")).to be nil
837
873
  end
838
874
 
839
875
  after do
@@ -859,7 +895,7 @@ describe LogStash::Filters::Grok do
859
895
  end
860
896
 
861
897
  sample("message" => '0') do
862
- insist { subject.get("tags") } == nil
898
+ expect(subject.get("tags")).to be nil
863
899
  end
864
900
 
865
901
  after do
@@ -879,17 +915,17 @@ describe LogStash::Filters::Grok do
879
915
  CONFIG
880
916
 
881
917
  sample "treebranch" do
882
- insist { subject.get("name2") } == "branch"
918
+ expect(subject.get("name2")).to eql "branch"
883
919
  end
884
920
 
885
921
  sample "bushbeard" do
886
- insist { subject.get("name1") } == "bush"
922
+ expect(subject.get("name1")).to eql "bush"
887
923
  end
888
924
 
889
925
  sample "treebeard" do
890
- insist { subject.get("name1") } == "tree"
891
- insist { subject.get("name2") } == "beard"
926
+ expect(subject.get("name1")).to eql "tree"
927
+ expect(subject.get("name2")).to eql "beard"
892
928
  end
893
929
  end
894
930
  end
895
- end
931
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-grok
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-21 00:00:00.000000000 Z
11
+ date: 2022-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: 5.6.0
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.0'
53
+ name: logstash-mixin-ecs_compatibility_support
54
+ prerelease: false
55
+ type: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  requirement: !ruby/object:Gem::Requirement
49
63
  requirements:
@@ -77,7 +91,10 @@ dependencies:
77
91
  requirements:
78
92
  - - ">="
79
93
  - !ruby/object:Gem::Version
80
- version: '0'
94
+ version: 4.3.0
95
+ - - "<"
96
+ - !ruby/object:Gem::Version
97
+ version: '5'
81
98
  name: logstash-patterns-core
82
99
  prerelease: false
83
100
  type: :runtime
@@ -85,21 +102,24 @@ dependencies:
85
102
  requirements:
86
103
  - - ">="
87
104
  - !ruby/object:Gem::Version
88
- version: '0'
105
+ version: 4.3.0
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: '5'
89
109
  - !ruby/object:Gem::Dependency
90
110
  requirement: !ruby/object:Gem::Requirement
91
111
  requirements:
92
- - - '='
112
+ - - ">="
93
113
  - !ruby/object:Gem::Version
94
- version: 1.3.6
114
+ version: '0'
95
115
  name: logstash-devutils
96
116
  prerelease: false
97
117
  type: :development
98
118
  version_requirements: !ruby/object:Gem::Requirement
99
119
  requirements:
100
- - - '='
120
+ - - ">="
101
121
  - !ruby/object:Gem::Version
102
- version: 1.3.6
122
+ version: '0'
103
123
  description: This gem is a Logstash plugin required to be installed on top of the
104
124
  Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
105
125
  gem is not a stand-alone program
@@ -141,8 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
161
  - !ruby/object:Gem::Version
142
162
  version: '0'
143
163
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.6.13
164
+ rubygems_version: 3.1.6
146
165
  signing_key:
147
166
  specification_version: 4
148
167
  summary: Parses unstructured event data into fields