logstash-filter-esquerystring 1.0.1 → 1.2.0

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: 5f2e7609d982d3e5e6061e7045f099acab855995a9094ead59264464d5c10da5
4
- data.tar.gz: 526113a947f5e5ee7becedaa3133d418ce6ac38a47d8d11db174a2c33cfd6d5d
3
+ metadata.gz: '0608e5bf3e3a027b7ebfcbd6eb83fdef7de8caea701c20add1d4cccfa62a5c92'
4
+ data.tar.gz: d7bdabec91119b6ed833fe789f0c2413d31faa616fcea8e4c3d87ef55dc011f8
5
5
  SHA512:
6
- metadata.gz: 010e960574ef6776432aca3281e3aa7306b45990f7464f58ab18a149e61b24948cbea7d069c431a599cd99df6e48ce7935dd8d0cefcd1fc5f89a7bbfea8773ce
7
- data.tar.gz: 5536154e93d0792c8cde70517638d4e40fef0b76a1b7d4c730d2084b4aa7b04474d445eb0da38ede972abda43d3dcdd57049c8e31786f270ca09760ea7dc7162
6
+ metadata.gz: 3ad22fc8ece75dcceeacfa366a5777f76c1280b5a180e5676c3dc619e5e9fc19771c53c0727fa71a80695fc9cb5e7c836ca96b63c30ca6de51fc907d5b821651
7
+ data.tar.gz: 8dbe2b99216417fba9080ded313b3d7702ba50588b21828b97cbc9ca4489eaed9db1943eac4ca0f9f4bf9d3db0dfc85d3271b420c0a142070befb492404ff42d
@@ -5,7 +5,7 @@ require "logstash/namespace"
5
5
  class LogStash::Filters::Esquerystring < LogStash::Filters::Base
6
6
  config_name "esquerystring"
7
7
 
8
- config :source, :validate => :string, :required => true
8
+ config :source, :validate => :array, :required => true
9
9
  config :target, :validate => :string, :required => true
10
10
 
11
11
  public
@@ -15,14 +15,20 @@ class LogStash::Filters::Esquerystring < LogStash::Filters::Base
15
15
 
16
16
  public
17
17
  def filter(event)
18
- return unless event.include?(@source)
18
+ values = []
19
19
 
20
- value = event.get(@source)
21
- if value.is_a?(Array)
22
- value = "(" + value.uniq.join(" OR ") + ")"
20
+ @source.each do |field|
21
+ next unless event.include?(field)
22
+ value = event.get(field)
23
+ next if value.nil?
24
+ value = [value] unless value.is_a?(Array)
25
+ next if value.length == 0
26
+ values += value
23
27
  end
24
28
 
25
- event.set(@target, value)
29
+ return if values.length == 0
30
+ values = "(" + values.uniq.map { |x| '"' + x + '"' }.join(" OR ") + ")"
31
+ event.set(@target, values)
26
32
  end # def filter
27
33
 
28
34
  end # class LogStash::Filters::Esquerystring
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-esquerystring'
4
- s.version = '1.0.1'
4
+ s.version = '1.2.0'
5
5
  s.licenses = ['Apache-2.0']
6
6
  s.summary = "This filter converts values of source field to elasticsearch query string"
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"
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+
3
+ require "logstash/devutils/rspec/spec_helper"
4
+ require "logstash/filters/esquerystring"
5
+
6
+ describe LogStash::Filters::Esquerystring do
7
+
8
+ describe "esquerystring with single value" do
9
+ config <<-CONFIG
10
+ filter {
11
+ esquerystring {
12
+ source => "src"
13
+ target => "dst"
14
+ }
15
+ }
16
+ CONFIG
17
+
18
+ sample("src" => "arg1") do
19
+ insist { subject.get("dst") } == '("arg1")'
20
+ end
21
+ end
22
+
23
+ describe "esquerystring string with array" do
24
+ config <<-CONFIG
25
+ filter {
26
+ esquerystring {
27
+ source => "src"
28
+ target => "dst"
29
+ }
30
+ }
31
+ CONFIG
32
+
33
+ sample("src" => ["arg1", "arg2"]) do
34
+ insist { subject.get("dst") } == '("arg1" OR "arg2")'
35
+ end
36
+ end
37
+
38
+ describe "esquerystring string with non unique array" do
39
+ config <<-CONFIG
40
+ filter {
41
+ esquerystring {
42
+ source => "src"
43
+ target => "dst"
44
+ }
45
+ }
46
+ CONFIG
47
+
48
+ sample("src" => ["arg1", "arg2", "arg2", "arg3"]) do
49
+ insist { subject.get("dst") } == '("arg1" OR "arg2" OR "arg3")'
50
+ end
51
+ end
52
+
53
+ describe "esquerystring with multiple source fields" do
54
+ config <<-CONFIG
55
+ filter {
56
+ esquerystring {
57
+ source => ["src1", "src2"]
58
+ target => "dst"
59
+ }
60
+ }
61
+ CONFIG
62
+
63
+ sample("src1" => "arg1", "src2" => "arg2") do
64
+ insist { subject.get("dst") } == '("arg1" OR "arg2")'
65
+ end
66
+ end
67
+
68
+ describe "esquerystring with multiple source fields but only one non empty" do
69
+ config <<-CONFIG
70
+ filter {
71
+ esquerystring {
72
+ source => ["src1", "src2"]
73
+ target => "dst"
74
+ }
75
+ }
76
+ CONFIG
77
+
78
+ sample("src1" => [], "src2" => "arg2") do
79
+ insist { subject.get("dst") } == '("arg2")'
80
+ end
81
+ end
82
+
83
+ describe "esquerystring with multiple source fields and not all present in record" do
84
+ config <<-CONFIG
85
+ filter {
86
+ esquerystring {
87
+ source => ["src1", "src2", "src3"]
88
+ target => "dst"
89
+ }
90
+ }
91
+ CONFIG
92
+
93
+ sample("src1" => ["arg1"], "src2" => "arg2") do
94
+ insist { subject.get("dst") } == '("arg1" OR "arg2")'
95
+ end
96
+ end
97
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-esquerystring
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-05 00:00:00.000000000 Z
11
+ date: 2017-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -61,7 +61,7 @@ files:
61
61
  - docs/index.asciidoc
62
62
  - lib/logstash/filters/esquerystring.rb
63
63
  - logstash-filter-esquerystring.gemspec
64
- - spec/filters/anonymize_spec.rb
64
+ - spec/filters/esquerystring_spec.rb
65
65
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
66
66
  licenses:
67
67
  - Apache-2.0
@@ -89,4 +89,4 @@ signing_key:
89
89
  specification_version: 4
90
90
  summary: This filter converts values of source field to elasticsearch query string
91
91
  test_files:
92
- - spec/filters/anonymize_spec.rb
92
+ - spec/filters/esquerystring_spec.rb
@@ -1,55 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "logstash/devutils/rspec/spec_helper"
4
- require "logstash/filters/esquerystring"
5
-
6
- describe LogStash::Filters::Esquerystring do
7
-
8
- describe "esquerystring with single value" do
9
- # The logstash config goes here.
10
- # At this time, only filters are supported.
11
- config <<-CONFIG
12
- filter {
13
- esquerystring {
14
- source => "src"
15
- target => "dst"
16
- }
17
- }
18
- CONFIG
19
-
20
- sample("src" => "arg1") do
21
- insist { subject.get("dst") } == "arg1"
22
- end
23
- end
24
-
25
- describe "esquerystring string with array" do
26
- config <<-CONFIG
27
- filter {
28
- esquerystring {
29
- source => "src"
30
- target => "dst"
31
- }
32
- }
33
- CONFIG
34
-
35
- sample("src" => ["arg1", "arg2"]) do
36
- insist { subject.get("dst") } == "(arg1 OR arg2)"
37
- end
38
- end
39
-
40
- describe "esquerystring string with non unique array" do
41
- config <<-CONFIG
42
- filter {
43
- esquerystring {
44
- source => "src"
45
- target => "dst"
46
- }
47
- }
48
- CONFIG
49
-
50
- sample("src" => ["arg1", "arg2", "arg2", "arg3"]) do
51
- insist { subject.get("dst") } == "(arg1 OR arg2 OR arg3)"
52
- end
53
- end
54
-
55
- end