logstash-filter-split 0.1.3 → 0.1.4

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
  SHA1:
3
- metadata.gz: 7c4bc332ece646e8a99928445c29d2f1be070ec2
4
- data.tar.gz: ebf872000c93ee05a2b9c20a1bcd500c6a38c93c
3
+ metadata.gz: 08af0cf5a85da1eab3f09a72076c3b4db993a451
4
+ data.tar.gz: 54ff96f7d81eb7265c1fd79998ffedd422ccf301
5
5
  SHA512:
6
- metadata.gz: 6245d66733350ac9ce5d8a8beb725281fb2b471492861bf81c52551fde65a17febb4cb6f92876d3a331d0a0da1dd72b26c38c113773181522ae8a34826f8cf74
7
- data.tar.gz: 1fe65cceaff412f37d0e86a3e8134d8b21c23db66c155787681cd74e9722d5473aa0197c815a75eaca928df838ba8d31c981284c20ffdd23a55a8cb9ca550397
6
+ metadata.gz: 058a428b4716d3a1effdb21d2b15849f50e735e36a077f5985e9e9740a4a909b5f0bcfe767dc695d7d549197ac045536a1925ed3fc4a029e9709b56a76ada0ba
7
+ data.tar.gz: 62368a8c91a19bb248648734e4289ca5ed36188691d3be21f05323132506f40dbe2abf633bd5408cebdffd8983e3664d17eb978e6844fe8317069bd9e2bd55db
@@ -21,6 +21,10 @@ class LogStash::Filters::Split < LogStash::Filters::Base
21
21
  # The field which value is split by the terminator
22
22
  config :field, :validate => :string, :default => "message"
23
23
 
24
+ # The field within the new event which the value is split into.
25
+ # If not set, target field defaults to split field name.
26
+ config :target, :validate => :string
27
+
24
28
  public
25
29
  def register
26
30
  # Nothing to do
@@ -32,12 +36,15 @@ class LogStash::Filters::Split < LogStash::Filters::Base
32
36
 
33
37
  original_value = event[@field]
34
38
 
35
- # If for some reason the field is an array of values, take the first only.
36
- original_value = original_value.first if original_value.is_a?(Array)
37
-
38
- # Using -1 for 'limit' on String#split makes ruby not drop trailing empty
39
- # splits.
40
- splits = original_value.split(@terminator, -1)
39
+ if original_value.is_a?(Array)
40
+ splits = original_value
41
+ elsif original_value.is_a?(String)
42
+ # Using -1 for 'limit' on String#split makes ruby not drop trailing empty
43
+ # splits.
44
+ splits = original_value.split(@terminator, -1)
45
+ else
46
+ raise LogStash::ConfigurationError, "Only String and Array types are splittable. field:#{@field} is of type = #{original_value.class}"
47
+ end
41
48
 
42
49
  # Skip filtering if splitting this event resulted in only one thing found.
43
50
  return if splits.length == 1
@@ -48,7 +55,7 @@ class LogStash::Filters::Split < LogStash::Filters::Base
48
55
 
49
56
  event_split = event.clone
50
57
  @logger.debug("Split event", :value => value, :field => @field)
51
- event_split[@field] = value
58
+ event_split[(@target || @field)] = value
52
59
  filter_matched(event_split)
53
60
 
54
61
  # Push this new event onto the stack at the LogStash::FilterWorker
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-split'
4
- s.version = '0.1.3'
4
+ s.version = '0.1.4'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "The split filter is for splitting multiline messages into separate events."
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/plugin install gemname. This gem is not a stand-alone program"
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/devutils/rspec/spec_helper"
3
3
  require "logstash/filters/split"
4
+ require "logstash/event"
4
5
 
5
6
  describe LogStash::Filters::Split do
6
7
 
@@ -56,4 +57,49 @@ describe LogStash::Filters::Split do
56
57
  end
57
58
  end
58
59
 
60
+ describe "split array" do
61
+ config <<-CONFIG
62
+ filter {
63
+ split {
64
+ field => "array"
65
+ }
66
+ }
67
+ CONFIG
68
+
69
+ sample("array" => ["big", "bird", "sesame street"], "untouched" => "1\n2\n3") do
70
+ insist { subject.length } == 3
71
+ subject.each do |s|
72
+ insist { s["untouched"] } == "1\n2\n3"
73
+ end
74
+ insist { subject[0]["array"] } == "big"
75
+ insist { subject[1]["array"] } == "bird"
76
+ insist { subject[2]["array"] } == "sesame street"
77
+ end
78
+ end
79
+
80
+ describe "split array into new field" do
81
+ config <<-CONFIG
82
+ filter {
83
+ split {
84
+ field => "array"
85
+ target => "element"
86
+ }
87
+ }
88
+ CONFIG
89
+
90
+ sample("array" => ["big", "bird", "sesame street"]) do
91
+ insist { subject.length } == 3
92
+ insist { subject[0]["element"] } == "big"
93
+ insist { subject[1]["element"] } == "bird"
94
+ insist { subject[2]["element"] } == "sesame street"
95
+ end
96
+ end
97
+
98
+ context "when invalid type is passed" do
99
+ it "should raise exception" do
100
+ filter = LogStash::Filters::Split.new({"field" => "field"})
101
+ event = LogStash::Event.new("field" => 10)
102
+ expect {filter.filter(event)}.to raise_error
103
+ end
104
+ end
59
105
  end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-split
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elasticsearch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-27 00:00:00.000000000 Z
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- requirement: !ruby/object:Gem::Requirement
14
+ name: logstash
15
+ version_requirements: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - '>='
17
18
  - !ruby/object:Gem::Version
@@ -19,10 +20,7 @@ dependencies:
19
20
  - - <
20
21
  - !ruby/object:Gem::Version
21
22
  version: 2.0.0
22
- name: logstash
23
- prerelease: false
24
- type: :runtime
25
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: !ruby/object:Gem::Requirement
26
24
  requirements:
27
25
  - - '>='
28
26
  - !ruby/object:Gem::Version
@@ -30,20 +28,22 @@ dependencies:
30
28
  - - <
31
29
  - !ruby/object:Gem::Version
32
30
  version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
33
  - !ruby/object:Gem::Dependency
34
- requirement: !ruby/object:Gem::Requirement
34
+ name: logstash-devutils
35
+ version_requirements: !ruby/object:Gem::Requirement
35
36
  requirements:
36
37
  - - '>='
37
38
  - !ruby/object:Gem::Version
38
39
  version: '0'
39
- name: logstash-devutils
40
- prerelease: false
41
- type: :development
42
- version_requirements: !ruby/object:Gem::Requirement
40
+ requirement: !ruby/object:Gem::Requirement
43
41
  requirements:
44
42
  - - '>='
45
43
  - !ruby/object:Gem::Version
46
44
  version: '0'
45
+ prerelease: false
46
+ type: :development
47
47
  description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
48
48
  email: info@elasticsearch.com
49
49
  executables: []