logstash-filter-kv 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/lib/logstash/filters/kv.rb +40 -0
- data/logstash-filter-kv.gemspec +1 -1
- data/spec/filters/kv_spec.rb +60 -0
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5b62e210c5764ad9af5185a3a18806a811dee71
|
4
|
+
data.tar.gz: 638c1ce5512591a29bf4b501d727fd36e42f5c80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37fa6c205f3151745222a53dd25e3083ae8fc048008f45a2f6300e3402c61953d7b4c798353697486da5964afe48d77828cd869872e20c02fc8c7f1dc7648de3
|
7
|
+
data.tar.gz: 847df25bdce86f4f22fa1f8e716f88cd7d7bce4fa0a698f2752a4f96d161a63d3f6196abf11bd18a2bb9dc71593592f1bc9f4906d89664f8d6bf54e736d6a1f6
|
data/CHANGELOG.md
CHANGED
data/lib/logstash/filters/kv.rb
CHANGED
@@ -29,6 +29,11 @@ require "logstash/namespace"
|
|
29
29
|
class LogStash::Filters::KV < LogStash::Filters::Base
|
30
30
|
config_name "kv"
|
31
31
|
|
32
|
+
# Constants used for transform check
|
33
|
+
TRANSFORM_LOWERCASE_KEY = "lowercase"
|
34
|
+
TRANSFORM_UPPERCASE_KEY = "uppercase"
|
35
|
+
TRANSFORM_CAPITALIZE_KEY = "capitalize"
|
36
|
+
|
32
37
|
# A string of characters to trim from the value. This is useful if your
|
33
38
|
# values are wrapped in brackets or are terminated with commas (like postfix
|
34
39
|
# logs).
|
@@ -60,6 +65,28 @@ class LogStash::Filters::KV < LogStash::Filters::Base
|
|
60
65
|
# }
|
61
66
|
config :trimkey, :validate => :string
|
62
67
|
|
68
|
+
# Transform values to lower case, upper case or capitals.
|
69
|
+
#
|
70
|
+
# For example, to capitalize all values:
|
71
|
+
# [source,ruby]
|
72
|
+
# filter {
|
73
|
+
# kv {
|
74
|
+
# transform_value => "capitalize"
|
75
|
+
# }
|
76
|
+
# }
|
77
|
+
config :transform_value, :validate => [TRANSFORM_LOWERCASE_KEY, TRANSFORM_UPPERCASE_KEY, TRANSFORM_CAPITALIZE_KEY]
|
78
|
+
|
79
|
+
# Transform keys to lower case, upper case or capitals.
|
80
|
+
#
|
81
|
+
# For example, to lowercase all keys:
|
82
|
+
# [source,ruby]
|
83
|
+
# filter {
|
84
|
+
# kv {
|
85
|
+
# transform_key => "lowercase"
|
86
|
+
# }
|
87
|
+
# }
|
88
|
+
config :transform_key, :validate => [TRANSFORM_LOWERCASE_KEY, TRANSFORM_UPPERCASE_KEY, TRANSFORM_CAPITALIZE_KEY]
|
89
|
+
|
63
90
|
# A string of characters to use as delimiters for parsing out key-value pairs.
|
64
91
|
#
|
65
92
|
# These characters form a regex character class and thus you must escape special regex
|
@@ -269,6 +296,17 @@ class LogStash::Filters::KV < LogStash::Filters::Base
|
|
269
296
|
s =~ @value_split_re
|
270
297
|
end
|
271
298
|
|
299
|
+
def transform(text, method)
|
300
|
+
case method
|
301
|
+
when TRANSFORM_LOWERCASE_KEY
|
302
|
+
return text.downcase
|
303
|
+
when TRANSFORM_UPPERCASE_KEY
|
304
|
+
return text.upcase
|
305
|
+
when TRANSFORM_CAPITALIZE_KEY
|
306
|
+
return text.capitalize
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
272
310
|
def parse(text, event, kv_keys)
|
273
311
|
# short circuit parsing if the text does not contain the @value_split
|
274
312
|
return kv_keys unless has_value_splitter?(text)
|
@@ -280,6 +318,7 @@ class LogStash::Filters::KV < LogStash::Filters::Base
|
|
280
318
|
text.scan(@scan_re) do |key, v1, v2, v3, v4, v5, v6|
|
281
319
|
value = v1 || v2 || v3 || v4 || v5 || v6
|
282
320
|
key = @trimkey ? key.gsub(@trimkey_re, "") : key
|
321
|
+
key = @transform_key ? transform(key, @transform_key) : key
|
283
322
|
|
284
323
|
# Bail out as per the values of include_keys and exclude_keys
|
285
324
|
next if not include_keys.empty? and not include_keys.include?(key)
|
@@ -289,6 +328,7 @@ class LogStash::Filters::KV < LogStash::Filters::Base
|
|
289
328
|
key = event.sprintf(@prefix) + key
|
290
329
|
|
291
330
|
value = @trim ? value.gsub(@trim_re, "") : value
|
331
|
+
value = @transform_value ? transform(value, @transform_value) : value
|
292
332
|
|
293
333
|
# Bail out if inserting duplicate value in key mapping when unique_values
|
294
334
|
# option is set to true.
|
data/logstash-filter-kv.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-kv'
|
4
|
-
s.version = '3.0
|
4
|
+
s.version = '3.1.0'
|
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"
|
data/spec/filters/kv_spec.rb
CHANGED
@@ -26,6 +26,66 @@ describe LogStash::Filters::KV do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
describe "test transforming keys to uppercase and values to lowercase" do
|
30
|
+
config <<-CONFIG
|
31
|
+
filter {
|
32
|
+
kv {
|
33
|
+
transform_key => "uppercase"
|
34
|
+
transform_value => "lowercase"
|
35
|
+
}
|
36
|
+
}
|
37
|
+
CONFIG
|
38
|
+
|
39
|
+
sample "hello = world Foo =Bar BAZ= FIZZ doublequoteD = \"hellO worlD\" Singlequoted= 'Hello World' brAckets =(hello World)" do
|
40
|
+
insist { subject.get("HELLO") } == "world"
|
41
|
+
insist { subject.get("FOO") } == "bar"
|
42
|
+
insist { subject.get("BAZ") } == "fizz"
|
43
|
+
insist { subject.get("DOUBLEQUOTED") } == "hello world"
|
44
|
+
insist { subject.get("SINGLEQUOTED") } == "hello world"
|
45
|
+
insist { subject.get("BRACKETS") } == "hello world"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "test transforming keys to lowercase and values to uppercase" do
|
50
|
+
config <<-CONFIG
|
51
|
+
filter {
|
52
|
+
kv {
|
53
|
+
transform_key => "lowercase"
|
54
|
+
transform_value => "uppercase"
|
55
|
+
}
|
56
|
+
}
|
57
|
+
CONFIG
|
58
|
+
|
59
|
+
sample "Hello = World fOo =bar baz= FIZZ DOUBLEQUOTED = \"hellO worlD\" singlequoted= 'hEllo wOrld' brackets =(HELLO world)" do
|
60
|
+
insist { subject.get("hello") } == "WORLD"
|
61
|
+
insist { subject.get("foo") } == "BAR"
|
62
|
+
insist { subject.get("baz") } == "FIZZ"
|
63
|
+
insist { subject.get("doublequoted") } == "HELLO WORLD"
|
64
|
+
insist { subject.get("singlequoted") } == "HELLO WORLD"
|
65
|
+
insist { subject.get("brackets") } == "HELLO WORLD"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "test transforming keys and values to capitals" do
|
70
|
+
config <<-CONFIG
|
71
|
+
filter {
|
72
|
+
kv {
|
73
|
+
transform_key => "capitalize"
|
74
|
+
transform_value => "capitalize"
|
75
|
+
}
|
76
|
+
}
|
77
|
+
CONFIG
|
78
|
+
|
79
|
+
sample "Hello = World fOo =bar baz= FIZZ DOUBLEQUOTED = \"hellO worlD\" singlequoted= 'hEllo wOrld' brackets =(HELLO world)" do
|
80
|
+
insist { subject.get("Hello") } == "World"
|
81
|
+
insist { subject.get("Foo") } == "Bar"
|
82
|
+
insist { subject.get("Baz") } == "Fizz"
|
83
|
+
insist { subject.get("Doublequoted") } == "Hello world"
|
84
|
+
insist { subject.get("Singlequoted") } == "Hello world"
|
85
|
+
insist { subject.get("Brackets") } == "Hello world"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
29
89
|
describe "test spaces attached to the field_split" do
|
30
90
|
config <<-CONFIG
|
31
91
|
filter {
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-kv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash-core-plugin-api
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
14
20
|
requirement: !ruby/object:Gem::Requirement
|
15
21
|
requirements:
|
16
|
-
- -
|
22
|
+
- - ~>
|
17
23
|
- !ruby/object:Gem::Version
|
18
24
|
version: '2.0'
|
19
|
-
name: logstash-core-plugin-api
|
20
25
|
prerelease: false
|
21
26
|
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: logstash-devutils
|
22
29
|
version_requirements: !ruby/object:Gem::Requirement
|
23
30
|
requirements:
|
24
|
-
- -
|
31
|
+
- - '>='
|
25
32
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
-
- !ruby/object:Gem::Dependency
|
33
|
+
version: '0'
|
28
34
|
requirement: !ruby/object:Gem::Requirement
|
29
35
|
requirements:
|
30
|
-
- -
|
36
|
+
- - '>='
|
31
37
|
- !ruby/object:Gem::Version
|
32
38
|
version: '0'
|
33
|
-
name: logstash-devutils
|
34
39
|
prerelease: false
|
35
40
|
type: :development
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
41
|
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
|
42
42
|
email: info@elastic.co
|
43
43
|
executables: []
|
@@ -65,12 +65,12 @@ require_paths:
|
|
65
65
|
- lib
|
66
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- -
|
68
|
+
- - '>='
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|