logstash-filter-kv 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd187e13f268bccf3d773032be91182db9539218
4
- data.tar.gz: 3869c2cd4527da8298067f4558d809b7c034e87d
3
+ metadata.gz: 010ddb862a2bcdf8e8a0eb272b1b6edbb9710169
4
+ data.tar.gz: bfa43c0dcf9e9978f1fb8cc71cc6712f16c0c503
5
5
  SHA512:
6
- metadata.gz: f6d25cd2beb66fad753125e9f0f49806dbf908771ab7ef1ec73584feb5538b36857cec4ba5e6f75df30aecab87d5ee2b573d6c60b9b22096a3cc27484859e42f
7
- data.tar.gz: 905f6b2f0fc3ab89dfe95a3cfbd2b5e76a7f50835e0722eea69e94b4e01b387386252dacb76200c512d2390d1579647d6863c8138f5e2ee43d3bbb1cd9112552
6
+ metadata.gz: 6da0c526856467869d33fa7878840af0d41543c27918c053cec520714d1b24dd141a1ccc01c8eb8d413b1a7c22e9754ba6854c38fc46f931570bc35db54ba342
7
+ data.tar.gz: 01a782a29a6a9310eb0f70a1ff0c980c131e5a80cb8a3796ffd563cef169d35dc8f58cc1216f5156acd2959a0afddbd650257a24e863a1a7fc51f91448104224
data/Gemfile CHANGED
@@ -1,4 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in logstash-mass_effect.gemspec
4
3
  gemspec
4
+
5
+ logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash"
6
+ use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1"
7
+
8
+ if Dir.exist?(logstash_path) && use_logstash_source
9
+ gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
10
+ gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
11
+ end
@@ -0,0 +1,409 @@
1
+ :plugin: kv
2
+ :type: filter
3
+
4
+ ///////////////////////////////////////////
5
+ START - GENERATED VARIABLES, DO NOT EDIT!
6
+ ///////////////////////////////////////////
7
+ :version: %VERSION%
8
+ :release_date: %RELEASE_DATE%
9
+ :changelog_url: %CHANGELOG_URL%
10
+ :include_path: ../../../../logstash/docs/include
11
+ ///////////////////////////////////////////
12
+ END - GENERATED VARIABLES, DO NOT EDIT!
13
+ ///////////////////////////////////////////
14
+
15
+ [id="plugins-{type}-{plugin}"]
16
+
17
+ === Kv filter plugin
18
+
19
+ include::{include_path}/plugin_header.asciidoc[]
20
+
21
+ ==== Description
22
+
23
+ This filter helps automatically parse messages (or specific event fields)
24
+ which are of the `foo=bar` variety.
25
+
26
+ For example, if you have a log message which contains `ip=1.2.3.4
27
+ error=REFUSED`, you can parse those automatically by configuring:
28
+ [source,ruby]
29
+ filter {
30
+ kv { }
31
+ }
32
+
33
+ The above will result in a message of `ip=1.2.3.4 error=REFUSED` having
34
+ the fields:
35
+
36
+ * `ip: 1.2.3.4`
37
+ * `error: REFUSED`
38
+
39
+ This is great for postfix, iptables, and other types of logs that
40
+ tend towards `key=value` syntax.
41
+
42
+ You can configure any arbitrary strings to split your data on,
43
+ in case your data is not structured using `=` signs and whitespace.
44
+ For example, this filter can also be used to parse query parameters like
45
+ `foo=bar&baz=fizz` by setting the `field_split` parameter to `&`.
46
+
47
+ [id="plugins-{type}s-{plugin}-options"]
48
+ ==== Kv Filter Configuration Options
49
+
50
+ This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
51
+
52
+ [cols="<,<,<",options="header",]
53
+ |=======================================================================
54
+ |Setting |Input type|Required
55
+ | <<plugins-{type}s-{plugin}-allow_duplicate_values>> |<<boolean,boolean>>|No
56
+ | <<plugins-{type}s-{plugin}-default_keys>> |<<hash,hash>>|No
57
+ | <<plugins-{type}s-{plugin}-exclude_keys>> |<<array,array>>|No
58
+ | <<plugins-{type}s-{plugin}-field_split>> |<<string,string>>|No
59
+ | <<plugins-{type}s-{plugin}-include_brackets>> |<<boolean,boolean>>|No
60
+ | <<plugins-{type}s-{plugin}-include_keys>> |<<array,array>>|No
61
+ | <<plugins-{type}s-{plugin}-prefix>> |<<string,string>>|No
62
+ | <<plugins-{type}s-{plugin}-recursive>> |<<boolean,boolean>>|No
63
+ | <<plugins-{type}s-{plugin}-remove_char_key>> |<<string,string>>|No
64
+ | <<plugins-{type}s-{plugin}-remove_char_value>> |<<string,string>>|No
65
+ | <<plugins-{type}s-{plugin}-source>> |<<string,string>>|No
66
+ | <<plugins-{type}s-{plugin}-target>> |<<string,string>>|No
67
+ | <<plugins-{type}s-{plugin}-transform_key>> |<<string,string>>, one of `["lowercase", "uppercase", "capitalize"]`|No
68
+ | <<plugins-{type}s-{plugin}-transform_value>> |<<string,string>>, one of `["lowercase", "uppercase", "capitalize"]`|No
69
+ | <<plugins-{type}s-{plugin}-trim_key>> |<<string,string>>|No
70
+ | <<plugins-{type}s-{plugin}-trim_value>> |<<string,string>>|No
71
+ | <<plugins-{type}s-{plugin}-value_split>> |<<string,string>>|No
72
+ |=======================================================================
73
+
74
+ Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
75
+ filter plugins.
76
+
77
+ &nbsp;
78
+
79
+ [id="plugins-{type}s-{plugin}-allow_duplicate_values"]
80
+ ===== `allow_duplicate_values`
81
+
82
+ * Value type is <<boolean,boolean>>
83
+ * Default value is `true`
84
+
85
+ A bool option for removing duplicate key/value pairs. When set to false, only
86
+ one unique key/value pair will be preserved.
87
+
88
+ For example, consider a source like `from=me from=me`. `[from]` will map to
89
+ an Array with two elements: `["me", "me"]`. To only keep unique key/value pairs,
90
+ you could use this configuration:
91
+ [source,ruby]
92
+ filter {
93
+ kv {
94
+ allow_duplicate_values => false
95
+ }
96
+ }
97
+
98
+ [id="plugins-{type}s-{plugin}-default_keys"]
99
+ ===== `default_keys`
100
+
101
+ * Value type is <<hash,hash>>
102
+ * Default value is `{}`
103
+
104
+ A hash specifying the default keys and their values which should be added to the event
105
+ in case these keys do not exist in the source field being parsed.
106
+ [source,ruby]
107
+ filter {
108
+ kv {
109
+ default_keys => [ "from", "logstash@example.com",
110
+ "to", "default@dev.null" ]
111
+ }
112
+ }
113
+
114
+ [id="plugins-{type}s-{plugin}-exclude_keys"]
115
+ ===== `exclude_keys`
116
+
117
+ * Value type is <<array,array>>
118
+ * Default value is `[]`
119
+
120
+ An array specifying the parsed keys which should not be added to the event.
121
+ By default no keys will be excluded.
122
+
123
+ For example, consider a source like `Hey, from=<abc>, to=def foo=bar`.
124
+ To exclude `from` and `to`, but retain the `foo` key, you could use this configuration:
125
+ [source,ruby]
126
+ filter {
127
+ kv {
128
+ exclude_keys => [ "from", "to" ]
129
+ }
130
+ }
131
+
132
+ [id="plugins-{type}s-{plugin}-field_split"]
133
+ ===== `field_split`
134
+
135
+ * Value type is <<string,string>>
136
+ * Default value is `" "`
137
+
138
+ A string of characters to use as delimiters for parsing out key-value pairs.
139
+
140
+ These characters form a regex character class and thus you must escape special regex
141
+ characters like `[` or `]` using `\`.
142
+
143
+ #### Example with URL Query Strings
144
+
145
+ For example, to split out the args from a url query string such as
146
+ `?pin=12345~0&d=123&e=foo@bar.com&oq=bobo&ss=12345`:
147
+ [source,ruby]
148
+ filter {
149
+ kv {
150
+ field_split => "&?"
151
+ }
152
+ }
153
+
154
+ The above splits on both `&` and `?` characters, giving you the following
155
+ fields:
156
+
157
+ * `pin: 12345~0`
158
+ * `d: 123`
159
+ * `e: foo@bar.com`
160
+ * `oq: bobo`
161
+ * `ss: 12345`
162
+
163
+ [id="plugins-{type}s-{plugin}-include_brackets"]
164
+ ===== `include_brackets`
165
+
166
+ * Value type is <<boolean,boolean>>
167
+ * Default value is `true`
168
+
169
+ A boolean specifying whether to treat square brackets, angle brackets,
170
+ and parentheses as value "wrappers" that should be removed from the value.
171
+ [source,ruby]
172
+ filter {
173
+ kv {
174
+ include_brackets => true
175
+ }
176
+ }
177
+
178
+ For example, the result of this line:
179
+ `bracketsone=(hello world) bracketstwo=[hello world] bracketsthree=<hello world>`
180
+
181
+ will be:
182
+
183
+ * bracketsone: hello world
184
+ * bracketstwo: hello world
185
+ * bracketsthree: hello world
186
+
187
+ instead of:
188
+
189
+ * bracketsone: (hello
190
+ * bracketstwo: [hello
191
+ * bracketsthree: <hello
192
+
193
+
194
+ [id="plugins-{type}s-{plugin}-include_keys"]
195
+ ===== `include_keys`
196
+
197
+ * Value type is <<array,array>>
198
+ * Default value is `[]`
199
+
200
+ An array specifying the parsed keys which should be added to the event.
201
+ By default all keys will be added.
202
+
203
+ For example, consider a source like `Hey, from=<abc>, to=def foo=bar`.
204
+ To include `from` and `to`, but exclude the `foo` key, you could use this configuration:
205
+ [source,ruby]
206
+ filter {
207
+ kv {
208
+ include_keys => [ "from", "to" ]
209
+ }
210
+ }
211
+
212
+ [id="plugins-{type}s-{plugin}-prefix"]
213
+ ===== `prefix`
214
+
215
+ * Value type is <<string,string>>
216
+ * Default value is `""`
217
+
218
+ A string to prepend to all of the extracted keys.
219
+
220
+ For example, to prepend arg_ to all keys:
221
+ [source,ruby]
222
+ filter { kv { prefix => "arg_" } }
223
+
224
+ [id="plugins-{type}s-{plugin}-recursive"]
225
+ ===== `recursive`
226
+
227
+ * Value type is <<boolean,boolean>>
228
+ * Default value is `false`
229
+
230
+ A boolean specifying whether to drill down into values
231
+ and recursively get more key-value pairs from it.
232
+ The extra key-value pairs will be stored as subkeys of the root key.
233
+
234
+ Default is not to recursive values.
235
+ [source,ruby]
236
+ filter {
237
+ kv {
238
+ recursive => "true"
239
+ }
240
+ }
241
+
242
+
243
+ [id="plugins-{type}s-{plugin}-remove_char_key"]
244
+ ===== `remove_char_key`
245
+
246
+ * Value type is <<string,string>>
247
+ * There is no default value for this setting.
248
+
249
+ A string of characters to remove from the key.
250
+
251
+ These characters form a regex character class and thus you must escape special regex
252
+ characters like `[` or `]` using `\`.
253
+
254
+ Contrary to trim option, all characters are removed from the key, whatever their position.
255
+
256
+ For example, to remove `<` `>` `[` `]` and `,` characters from keys:
257
+ [source,ruby]
258
+ filter {
259
+ kv {
260
+ remove_char_key => "<>\[\],"
261
+ }
262
+ }
263
+
264
+ [id="plugins-{type}s-{plugin}-remove_char_value"]
265
+ ===== `remove_char_value`
266
+
267
+ * Value type is <<string,string>>
268
+ * There is no default value for this setting.
269
+
270
+ A string of characters to remove from the value.
271
+
272
+ These characters form a regex character class and thus you must escape special regex
273
+ characters like `[` or `]` using `\`.
274
+
275
+ Contrary to trim option, all characters are removed from the value, whatever their position.
276
+
277
+ For example, to remove `<`, `>`, `[`, `]` and `,` characters from values:
278
+ [source,ruby]
279
+ filter {
280
+ kv {
281
+ remove_char_value => "<>\[\],"
282
+ }
283
+ }
284
+
285
+ [id="plugins-{type}s-{plugin}-source"]
286
+ ===== `source`
287
+
288
+ * Value type is <<string,string>>
289
+ * Default value is `"message"`
290
+
291
+ The field to perform `key=value` searching on
292
+
293
+ For example, to process the `not_the_message` field:
294
+ [source,ruby]
295
+ filter { kv { source => "not_the_message" } }
296
+
297
+ [id="plugins-{type}s-{plugin}-target"]
298
+ ===== `target`
299
+
300
+ * Value type is <<string,string>>
301
+ * There is no default value for this setting.
302
+
303
+ The name of the container to put all of the key-value pairs into.
304
+
305
+ If this setting is omitted, fields will be written to the root of the
306
+ event, as individual fields.
307
+
308
+ For example, to place all keys into the event field kv:
309
+ [source,ruby]
310
+ filter { kv { target => "kv" } }
311
+
312
+ [id="plugins-{type}s-{plugin}-transform_key"]
313
+ ===== `transform_key`
314
+
315
+ * Value can be any of: `lowercase`, `uppercase`, `capitalize`
316
+ * There is no default value for this setting.
317
+
318
+ Transform keys to lower case, upper case or capitals.
319
+
320
+ For example, to lowercase all keys:
321
+ [source,ruby]
322
+ filter {
323
+ kv {
324
+ transform_key => "lowercase"
325
+ }
326
+ }
327
+
328
+ [id="plugins-{type}s-{plugin}-transform_value"]
329
+ ===== `transform_value`
330
+
331
+ * Value can be any of: `lowercase`, `uppercase`, `capitalize`
332
+ * There is no default value for this setting.
333
+
334
+ Transform values to lower case, upper case or capitals.
335
+
336
+ For example, to capitalize all values:
337
+ [source,ruby]
338
+ filter {
339
+ kv {
340
+ transform_value => "capitalize"
341
+ }
342
+ }
343
+
344
+ [id="plugins-{type}s-{plugin}-trim_key"]
345
+ ===== `trim_key`
346
+
347
+ * Value type is <<string,string>>
348
+ * There is no default value for this setting.
349
+
350
+ A string of characters to trim from the key. This is useful if your
351
+ keys are wrapped in brackets or start with space.
352
+
353
+ These characters form a regex character class and thus you must escape special regex
354
+ characters like `[` or `]` using `\`.
355
+
356
+ Only leading and trailing characters are trimed from the key.
357
+
358
+ For example, to trim `<` `>` `[` `]` and `,` characters from keys:
359
+ [source,ruby]
360
+ filter {
361
+ kv {
362
+ trim_key => "<>\[\],"
363
+ }
364
+ }
365
+
366
+ [id="plugins-{type}s-{plugin}-trim_value"]
367
+ ===== `trim_value`
368
+
369
+ * Value type is <<string,string>>
370
+ * There is no default value for this setting.
371
+
372
+ Constants used for transform check
373
+ A string of characters to trim from the value. This is useful if your
374
+ values are wrapped in brackets or are terminated with commas (like postfix
375
+ logs).
376
+
377
+ These characters form a regex character class and thus you must escape special regex
378
+ characters like `[` or `]` using `\`.
379
+
380
+ Only leading and trailing characters are trimed from the value.
381
+
382
+ For example, to trim `<`, `>`, `[`, `]` and `,` characters from values:
383
+ [source,ruby]
384
+ filter {
385
+ kv {
386
+ trim_value => "<>\[\],"
387
+ }
388
+ }
389
+
390
+ [id="plugins-{type}s-{plugin}-value_split"]
391
+ ===== `value_split`
392
+
393
+ * Value type is <<string,string>>
394
+ * Default value is `"="`
395
+
396
+ A non-empty string of characters to use as delimiters for identifying key-value relations.
397
+
398
+ These characters form a regex character class and thus you must escape special regex
399
+ characters like `[` or `]` using `\`.
400
+
401
+ For example, to identify key-values such as
402
+ `key1:value1 key2:value2`:
403
+ [source,ruby]
404
+ filter { kv { value_split => ":" } }
405
+
406
+
407
+
408
+ [id="plugins-{type}s-{plugin}-common-options"]
409
+ include::{include_path}/{type}.asciidoc[]
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-kv'
4
- s.version = '4.0.0'
4
+ s.version = '4.0.1'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "This filter helps automatically parse messages (or specific event fields) which are of the 'foo=bar' variety."
7
7
  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"
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.require_paths = ["lib"]
12
12
 
13
13
  # Files
14
- s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"]
15
15
 
16
16
  # Tests
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -669,7 +669,16 @@ describe LogStash::Filters::KV do
669
669
  plugin
670
670
  end
671
671
 
672
- let(:message) { "AccountStatus: 4\r\nAdditionalInformation\r\n\r\nCode: \r\nHttpStatusCode: \r\nIsSuccess: True\r\nMessage: \r\n" }
672
+ let(:f1) { "AccountStatus" }
673
+ let(:v1) { "4" }
674
+ let(:f2) { "AdditionalInformation" }
675
+ let(:f3) { "Code" }
676
+ let(:f4) { "HttpStatusCode" }
677
+ let(:f5) { "IsSuccess" }
678
+ let(:v5) { "True" }
679
+ let(:f6) { "Message" }
680
+
681
+ let(:message) { "#{f1}: #{v1}\r\n#{f2}\r\n\r\n#{f3}: \r\n#{f4}: \r\n#{f5}: #{v5}\r\n#{f6}: \r\n" }
673
682
  let(:data) { {"message" => message} }
674
683
  let(:event) { LogStash::Event.new(data) }
675
684
  let(:options) {
@@ -683,10 +692,12 @@ describe LogStash::Filters::KV do
683
692
  context "key and splitters with no value" do
684
693
  it "should ignore the incomplete key/value pairs" do
685
694
  subject.filter(event)
686
- expect(event.get("AccountStatus")).to eq("4")
687
- expect(event.get("IsSuccess")).to eq("True")
688
- expect(event.to_hash.keys.sort).to eq(
689
- ["@timestamp", "@version", "AccountStatus", "IsSuccess", "message", "tags"])
695
+ expect(event.get(f1)).to eq(v1)
696
+ expect(event.get(f5)).to eq(v5)
697
+ expect(event.include?(f2)).to be false
698
+ expect(event.include?(f3)).to be false
699
+ expect(event.include?(f4)).to be false
700
+ expect(event.include?(f6)).to be false
690
701
  end
691
702
  end
692
703
  end
@@ -715,8 +726,6 @@ describe LogStash::Filters::KV do
715
726
  subject.filter(event)
716
727
  expect(event.get("key1")).to eq("value1 with spaces")
717
728
  expect(event.get("key2 with spaces")).to eq("value2")
718
- expect(event.to_hash.keys.sort).to eq(
719
- ["@timestamp", "@version", "key1", "key2 with spaces", "message", "tags"])
720
729
  end
721
730
  end
722
731
  end
@@ -745,8 +754,6 @@ describe LogStash::Filters::KV do
745
754
  subject.filter(event)
746
755
  expect(event.get("key1")).to eq("value1withspaces")
747
756
  expect(event.get("key2withspaces")).to eq("value2")
748
- expect(event.to_hash.keys.sort).to eq(
749
- ["@timestamp", "@version", "key1", "key2withspaces", "message", "tags"])
750
757
  end
751
758
  end
752
759
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-kv
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-06 00:00:00.000000000 Z
11
+ date: 2017-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -56,6 +56,7 @@ files:
56
56
  - LICENSE
57
57
  - NOTICE.TXT
58
58
  - README.md
59
+ - docs/index.asciidoc
59
60
  - lib/logstash/filters/kv.rb
60
61
  - logstash-filter-kv.gemspec
61
62
  - spec/filters/kv_spec.rb