logstash-filter-zeromq 2.0.4 → 2.1.1

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: c9a571be2bf820b9a4e19404f9a4eb6ecec99a6b
4
- data.tar.gz: afed6933e2b649926e0bb4732114c0d08f463a38
3
+ metadata.gz: 48c16132cbb65dec76d2a5ebf21265278767b372
4
+ data.tar.gz: af27398f55f31de69829946bd4c1d52312213631
5
5
  SHA512:
6
- metadata.gz: 4a3b8df1d7b6ff7fbe91a48236caf35db756909ddee44d9595b08d8ca2b34e0e362d1543c9fba10e886f58bd75bc9f34c193c227d6592be7011b22bc6cd99b4a
7
- data.tar.gz: 2247e68c40c1f6fe4576732c406577765485df3929db3f07a93d3f65cc4f57a58df588d0354af922a13b491928f9c9fba68fec3646b34edd00103981fdb9194c
6
+ metadata.gz: 9c2e51cab401a165b44ce818a3a4ee1a768ebe863f53f0a61c3dbbd4ed388e06b1ef45b8ddfdb8a48bedf1cea122fcd2d074225987a8dd880809699b9d23c8fb
7
+ data.tar.gz: f42425f4cfca6f31c4d5e1f7d3dafef3bd4464a4b9e2dfcae818b8b7b3a54716a82b6df460818d70aebd16d246e9ba3e02941a23feec3cd6dd246e652efe753d
data/CHANGELOG.md CHANGED
@@ -1,9 +1,14 @@
1
- # 2.0.4
1
+ ## 2.1.1
2
+ - make sure we correctly encode the object #7
3
+ ## 2.1.0
4
+ - Use logstash-mixin-zeromq
5
+ - Add tests
6
+ - Use a sentinel value to signal event cancellation instead of an empty string
7
+ ## 2.0.4
2
8
  - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
3
- # 2.0.3
9
+ ## 2.0.3
4
10
  - New dependency requirements for logstash-core for the 5.0 release
5
11
  ## 2.0.0
6
- - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
12
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
7
13
  instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
8
14
  - Dependency on logstash-core update to 2.0
9
-
data/CONTRIBUTORS CHANGED
@@ -10,6 +10,7 @@ Contributors:
10
10
  * Pier-Hugues Pellerin (ph)
11
11
  * Richard Pijnenburg (electrical)
12
12
  * Tom Howe (turtlebender)
13
+ * Avishai Ish-Shalom (avishai-ish-shalom)
13
14
 
14
15
  Note: If you've sent us patches, bug reports, or otherwise contributed to
15
16
  Logstash, and you aren't on the list above and want to be, please let us know
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
1
+ Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Logstash Plugin
2
2
 
3
- [![Build
4
- Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Filters/job/logstash-plugin-filter-zeromq-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Filters/job/logstash-plugin-filter-zeromq-unit/)
3
+ [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-filter-zeromq.svg)](https://travis-ci.org/logstash-plugins/logstash-filter-zeromq)
5
4
 
6
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
7
6
 
@@ -56,7 +55,12 @@ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
56
55
  ```
57
56
  - Install plugin
58
57
  ```sh
58
+ # Logstash 2.3 and higher
59
+ bin/logstash-plugin install --no-verify
60
+
61
+ # Prior to Logstash 2.3
59
62
  bin/plugin install --no-verify
63
+
60
64
  ```
61
65
  - Run Logstash with your plugin
62
66
  ```sh
@@ -74,7 +78,12 @@ gem build logstash-filter-awesome.gemspec
74
78
  ```
75
79
  - Install the plugin from the Logstash home
76
80
  ```sh
77
- bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
81
+ # Logstash 2.3 and higher
82
+ bin/logstash-plugin install --no-verify
83
+
84
+ # Prior to Logstash 2.3
85
+ bin/plugin install --no-verify
86
+
78
87
  ```
79
88
  - Start Logstash and proceed to test the plugin
80
89
 
@@ -29,6 +29,10 @@ class LogStash::Filters::ZeroMQ < LogStash::Filters::Base
29
29
  # If this is unset, the whole event will be sent
30
30
  config :field, :validate => :string
31
31
 
32
+ # A sentinel value to signal the filter to cancel the event
33
+ # If the peer returns the sentinel value, the event will be cancelled
34
+ config :sentinel, :validate => :string, :default => ""
35
+
32
36
  # 0mq mode
33
37
  # server mode binds/listens
34
38
  # client mode connects
@@ -71,8 +75,8 @@ class LogStash::Filters::ZeroMQ < LogStash::Filters::Base
71
75
  public
72
76
  def register
73
77
  require "ffi-rzmq"
74
- require "logstash/util/zeromq"
75
- self.class.send(:include, LogStash::Util::ZeroMQ)
78
+ require "logstash/plugin_mixins/zeromq"
79
+ self.class.send(:include, LogStash::PluginMixins::ZeroMQ)
76
80
  connect
77
81
  end #def register
78
82
 
@@ -121,13 +125,13 @@ class LogStash::Filters::ZeroMQ < LogStash::Filters::Base
121
125
  def send_recv(message)
122
126
  success = false
123
127
  @retries.times do
124
- @logger.debug("0mq: sending", :request => message)
128
+ @logger.debug? && @logger.debug("0mq: sending", :request => message)
125
129
  rc = @zsocket.send_string(message)
126
130
  if ZMQ::Util.resultcode_ok?(rc)
127
131
  success = true
128
132
  break
129
133
  else
130
- @logger.debug("0mq: error sending message (zmq_errno = #{ZMQ::Util.errno}, zmq_error_string = '#{ZMQ::Util.error_string}'")
134
+ @logger.debug? && @logger.debug("0mq: error sending message (zmq_errno = #{ZMQ::Util.errno}, zmq_error_string = '#{ZMQ::Util.error_string}'")
131
135
  reconnect
132
136
  end #if resultcode
133
137
  end #retries.times
@@ -142,13 +146,13 @@ class LogStash::Filters::ZeroMQ < LogStash::Filters::Base
142
146
  reply = ''
143
147
  success = false
144
148
  @retries.times do
145
- @logger.debug("0mq: polling for reply for #{@timeout}ms.")
149
+ @logger.debug? && @logger.debug("0mq: polling for reply for #{@timeout}ms.")
146
150
  #poll the socket. If > 0, something to read. If < 0, error. If zero, loop
147
151
  num_readable = @poller.poll(@timeout)
148
152
  if num_readable > 0
149
153
  #something to read, do it.
150
154
  rc = @zsocket.recv_string(reply)
151
- @logger.debug("0mq: message received, checking error")
155
+ @logger.debug? && @logger.debug("0mq: message received, checking error")
152
156
  error_check(rc, "in recv_string")
153
157
  success = true
154
158
  break
@@ -171,8 +175,6 @@ class LogStash::Filters::ZeroMQ < LogStash::Filters::Base
171
175
 
172
176
  public
173
177
  def filter(event)
174
-
175
-
176
178
  begin
177
179
  # TODO (lusis): Allow filtering multiple fields
178
180
  if @field
@@ -180,19 +182,19 @@ class LogStash::Filters::ZeroMQ < LogStash::Filters::Base
180
182
  else
181
183
  success, reply = send_recv(event.to_json)
182
184
  end
183
- # If we receive an empty reply, this is an indication that the filter
185
+ # If we receive an sentinel value as reply, this is an indication that the filter
184
186
  # wishes to cancel this event.
185
- if reply.empty?
186
- @logger.debug("0mq: recieved empty reply, cancelling event.")
187
+ if success && reply == @sentinel
188
+ @logger.debug? && @logger.debug("0mq: recieved sentinel value, cancelling event.")
187
189
  event.cancel
188
190
  return
189
191
  end
190
- @logger.debug("0mq: receiving", :reply => reply)
192
+ @logger.debug? && @logger.debug("0mq: receiving", :reply => reply)
191
193
  if @field
192
194
  event[@field] = event.sprintf(reply)
193
195
  filter_matched(event)
194
196
  else
195
- reply = LogStash::Json.load(reply)
197
+ reply = LogStash::Event.new(LogStash::Json.load(reply))
196
198
  event.overwrite(reply)
197
199
  end
198
200
  filter_matched(event)
@@ -1,10 +1,11 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-zeromq'
4
- s.version = '2.0.4'
4
+
5
+ s.version = '2.1.1'
5
6
  s.licenses = ['Apache License (2.0)']
6
7
  s.summary = "ZeroMQ filter. This is a way to send an event externally for filtering"
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"
8
+ 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"
8
9
  s.authors = ["Elastic"]
9
10
  s.email = 'info@elastic.co'
10
11
  s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
@@ -22,8 +23,7 @@ Gem::Specification.new do |s|
22
23
  # Gem dependencies
23
24
  s.add_runtime_dependency "logstash-core-plugin-api", "~> 1.0"
24
25
 
25
- s.add_runtime_dependency 'ffi-rzmq', '~> 2.0.4'
26
+ s.add_runtime_dependency "logstash-mixin-zeromq", ">= 2.0.1"
26
27
 
27
28
  s.add_development_dependency 'logstash-devutils'
28
29
  end
29
-
@@ -1,6 +1,56 @@
1
1
  require "logstash/devutils/rspec/spec_helper"
2
2
  require 'logstash/filters/zeromq'
3
+ require 'json'
4
+ require 'securerandom'
3
5
 
4
6
  describe LogStash::Filters::ZeroMQ do
7
+ let(:sentinel) { SecureRandom.hex[1..2] }
8
+ let(:filter) { LogStash::Plugin.lookup("filter", "zeromq").new({"sentinel" => sentinel}) }
9
+ let(:event) do
10
+ LogStash::Event.new({
11
+ "message" => "some message",
12
+ "seq" => rand(1000),
13
+ "field1" => "some field value",
14
+ "@version" => "1",
15
+ "@timestamp" => Time.now.utc.iso8601(3)
16
+ })
17
+ end
5
18
 
19
+ let(:event_text) { event.to_json }
20
+
21
+ before do
22
+ allow(filter).to receive(:connect)
23
+ end
24
+
25
+ it "should send entire event as json if field not specified" do
26
+ expect(filter).to receive(:send_recv).with(event_text)
27
+ filter.filter(event)
28
+ end
29
+
30
+ it "should cancel event if peer returns an answer==sentinel" do
31
+ expect(filter).to receive(:send_recv).and_return([true, sentinel])
32
+ expect(event).to receive(:cancel)
33
+ filter.filter(event)
34
+ end
35
+
36
+ it "should not cancel event if send_recv failed" do
37
+ expect(filter).to receive(:send_recv).and_return([false, event_text])
38
+ expect(event).to_not receive(:cancel)
39
+ filter.filter(event)
40
+ end
41
+
42
+ context "Filter specific field" do
43
+ let(:filter) { LogStash::Plugin.lookup("filter", "zeromq").new({"field" => "field1"}) }
44
+
45
+ it "should send only a single field" do
46
+ expect(filter).to receive(:send_recv).with(event["field1"])
47
+ filter.filter(event)
48
+ end
49
+
50
+ it "should not cancel event if send_recv failed and event field==sentinel" do
51
+ expect(filter).to receive(:send_recv).and_return([false, sentinel])
52
+ expect(event).to_not receive(:cancel)
53
+ filter.filter(event)
54
+ end
55
+ end
6
56
  end
metadata CHANGED
@@ -1,58 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-zeromq
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2016-04-26 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: '1.0'
14
20
  requirement: !ruby/object:Gem::Requirement
15
21
  requirements:
16
- - - "~>"
22
+ - - ~>
17
23
  - !ruby/object:Gem::Version
18
24
  version: '1.0'
19
- name: logstash-core-plugin-api
20
25
  prerelease: false
21
26
  type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: logstash-mixin-zeromq
22
29
  version_requirements: !ruby/object:Gem::Requirement
23
30
  requirements:
24
- - - "~>"
31
+ - - '>='
25
32
  - !ruby/object:Gem::Version
26
- version: '1.0'
27
- - !ruby/object:Gem::Dependency
33
+ version: 2.0.1
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
30
- - - "~>"
36
+ - - '>='
31
37
  - !ruby/object:Gem::Version
32
- version: 2.0.4
33
- name: ffi-rzmq
38
+ version: 2.0.1
34
39
  prerelease: false
35
40
  type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: logstash-devutils
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
- - - "~>"
45
+ - - '>='
39
46
  - !ruby/object:Gem::Version
40
- version: 2.0.4
41
- - !ruby/object:Gem::Dependency
47
+ version: '0'
42
48
  requirement: !ruby/object:Gem::Requirement
43
49
  requirements:
44
- - - ">="
50
+ - - '>='
45
51
  - !ruby/object:Gem::Version
46
52
  version: '0'
47
- name: logstash-devutils
48
53
  prerelease: false
49
54
  type: :development
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- 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
55
+ 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
56
56
  email: info@elastic.co
57
57
  executables: []
58
58
  extensions: []
@@ -65,7 +65,6 @@ files:
65
65
  - NOTICE.TXT
66
66
  - README.md
67
67
  - lib/logstash/filters/zeromq.rb
68
- - lib/logstash/util/zeromq.rb
69
68
  - logstash-filter-zeromq.gemspec
70
69
  - spec/filters/zeromq_spec.rb
71
70
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
@@ -80,12 +79,12 @@ require_paths:
80
79
  - lib
81
80
  required_ruby_version: !ruby/object:Gem::Requirement
82
81
  requirements:
83
- - - ">="
82
+ - - '>='
84
83
  - !ruby/object:Gem::Version
85
84
  version: '0'
86
85
  required_rubygems_version: !ruby/object:Gem::Requirement
87
86
  requirements:
88
- - - ">="
87
+ - - '>='
89
88
  - !ruby/object:Gem::Version
90
89
  version: '0'
91
90
  requirements: []
@@ -1,47 +0,0 @@
1
- # encoding: utf-8
2
- require 'ffi-rzmq'
3
- require "logstash/namespace"
4
-
5
- module LogStash::Util::ZeroMQ
6
- CONTEXT = ZMQ::Context.new
7
- # LOGSTASH-400
8
- # see https://github.com/chuckremes/ffi-rzmq/blob/master/lib/ffi-rzmq/socket.rb#L93-117
9
- STRING_OPTS = %w{IDENTITY SUBSCRIBE UNSUBSCRIBE}
10
-
11
- def context
12
- CONTEXT
13
- end
14
-
15
- def setup(socket, address)
16
- if server?
17
- error_check(socket.bind(address), "binding to #{address}")
18
- else
19
- error_check(socket.connect(address), "connecting to #{address}")
20
- end
21
- @logger.info("0mq: #{server? ? 'connected' : 'bound'}", :address => address)
22
- end
23
-
24
- def error_check(rc, doing)
25
- unless ZMQ::Util.resultcode_ok?(rc)
26
- @logger.error("ZeroMQ error while #{doing}", { :error_code => rc })
27
- raise "ZeroMQ Error while #{doing}"
28
- end
29
- end # def error_check
30
-
31
- def setopts(socket, options)
32
- options.each do |opt,value|
33
- sockopt = opt.split('::')[1]
34
- option = ZMQ.const_defined?(sockopt) ? ZMQ.const_get(sockopt) : ZMQ.const_missing(sockopt)
35
- unless STRING_OPTS.include?(sockopt)
36
- begin
37
- Float(value)
38
- value = value.to_i
39
- rescue ArgumentError
40
- raise "#{sockopt} requires a numeric value. #{value} is not numeric"
41
- end
42
- end # end unless
43
- error_check(socket.setsockopt(option, value),
44
- "while setting #{opt} == #{value}")
45
- end # end each
46
- end # end setopts
47
- end # module LogStash::Util::ZeroMQ