logstash-output-mqtt 0.9.0 → 0.9.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: 17013b01e741f72e3f02d5c3a10593eeef722fd3
4
- data.tar.gz: 671cfaa6cfdb3f8439024e67be40e36a7e3e638c
3
+ metadata.gz: 3dcc117ed489aa6aa8ae774a3d300f9df65b153b
4
+ data.tar.gz: 54f322258c1d332cbdf8e64a07d506cbb2abbeaf
5
5
  SHA512:
6
- metadata.gz: ebd202f9302921cf5c4586093e51b6aa90413abb13f6d414fa9b1e20535333523b8fa67827a896ba67dea491a5feb4e5253a8a952c0926218b41d036d9ef9373
7
- data.tar.gz: 41599ded9be3f55f788af0dccf0bcfb1eb0d59ef939df61e0815b87b7fb55b87551a1a4c716f2f8a0617482253282eadf75579c743cfe143eb4e9ad7daf5dd3e
6
+ metadata.gz: 4d6baf3c028c4a729a2baa094099729ee54acdb133c5040dc5ad8b664e8c6326c5ea0b1eb5ccb77a1a403823ae67f7065feaa67196000e080b9708632ff3198b
7
+ data.tar.gz: df91c4d1db2ba435611aa3b801bad8a42c49b9452bd5b71aa8a9f28c48bd593f65c6fc5ca26a80125d257ec37c2ba23b4e3b2628d456eaf8019e1b73de4010d1
@@ -43,8 +43,16 @@ require "mqtt"
43
43
  # }
44
44
  # ----------------------------------
45
45
  #
46
- # Note that you will obtain the above configuration items when connecting a device in AWS IoT service.
47
- # The root CA certificate is also available from Symantec https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem[here].
46
+ # Topic may also depend on parts of the event using the standard sprintf syntax.
47
+ # [source,ruby]
48
+ # ----------------------------------
49
+ # output {
50
+ # mqtt {
51
+ # ...
52
+ # topic => "something/%{myfield}"
53
+ # }
54
+ # }
55
+ # ----------------------------------
48
56
 
49
57
  class LogStash::Outputs::MQTT < LogStash::Outputs::Base
50
58
 
@@ -128,7 +136,7 @@ class LogStash::Outputs::MQTT < LogStash::Outputs::Base
128
136
  # Use an array as a buffer so the multi_receive can handle multiple events with a single connection
129
137
  @event_buffer = Array.new
130
138
  @codec.on_event do |event, encoded_event|
131
- @event_buffer.push(encoded_event)
139
+ @event_buffer.push([event, encoded_event])
132
140
  end
133
141
 
134
142
  end # def register
@@ -162,9 +170,9 @@ class LogStash::Outputs::MQTT < LogStash::Outputs::Base
162
170
  # This way it is easy to cope with network failures, ie. if connection fails just try it again
163
171
  @logger.debug("Connecting MQTT with options #{@options}")
164
172
  MQTT::Client.connect(@options) do |client|
165
- while encoded_event = @event_buffer.first do
166
- @logger.debug("Publishing MQTT event #{encoded_event} with topic #{@topic}, retain #{@retain}, qos #{@qos}")
167
- client.publish(@topic, encoded_event, @retain, @qos)
173
+ while event = @event_buffer.first do
174
+ @logger.debug("Publishing MQTT event #{event[1]} with topic #{@topic}, retain #{@retain}, qos #{@qos}")
175
+ client.publish(event[0].sprintf(@topic), event[1], @retain, @qos)
168
176
  @event_buffer.shift
169
177
  end
170
178
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-mqtt'
3
- s.version = "0.9.0"
3
+ s.version = "0.9.1"
4
4
  s.licenses = ["Apache License (2.0)"]
5
5
  s.summary = "This is Logstash output plugin for the http://mqtt.org/[MQTT] protocol"
6
6
  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"
@@ -3,11 +3,15 @@ require "logstash/devutils/rspec/spec_helper"
3
3
  require "logstash/outputs/mqtt"
4
4
  require "logstash/codecs/json"
5
5
  require "logstash/event"
6
+ require "time"
6
7
 
7
8
  describe LogStash::Outputs::MQTT do
8
9
  # Define a sample event and its JSON encoded form
9
- let(:sample_event) { LogStash::Event.new("message" => "test message", "@timestamp" => "2016-01-01") }
10
- encoded_event = "{\"message\":\"test message\",\"@timestamp\":\"2016-01-01T00:00:00.000Z\",\"@version\":\"1\"}"
10
+ datestring = "2016-01-01"
11
+ tstamp = Time.parse(datestring)
12
+ tstamp_utc = tstamp.utc.iso8601(3)
13
+ let(:sample_event) { LogStash::Event.new("message" => "test message", "@timestamp" => datestring) }
14
+ encoded_event = "{\"message\":\"test message\",\"@timestamp\":\"" + tstamp_utc + "\",\"@version\":\"1\"}"
11
15
 
12
16
  settings = {
13
17
  "host" => "test.mosquitto.org",
@@ -54,3 +58,40 @@ describe LogStash::Outputs::MQTT do
54
58
  end
55
59
  end
56
60
  end
61
+
62
+ describe "Test subtopic:" do
63
+ # Define a sample event and its JSON encoded form
64
+ datestring = "2016-01-01"
65
+ tstamp = Time.parse(datestring)
66
+ tstamp_utc = tstamp.utc.iso8601(3)
67
+ let(:sample_event) { LogStash::Event.new("message" => "test message", "@timestamp" => datestring, "subtopic" => "mysubtopic") }
68
+ encoded_event = "{\"message\":\"test message\",\"@timestamp\":\"" + tstamp_utc + "\",\"subtopic\":\"mysubtopic\",\"@version\":\"1\"}"
69
+
70
+ settings = {
71
+ "host" => "test.mosquitto.org",
72
+ "topic" => "hello/%{subtopic}"
73
+ }
74
+ let(:output) { LogStash::Outputs::MQTT.new(settings) }
75
+ let(:stub_client) { Object.new }
76
+
77
+ before do
78
+ output.register
79
+ end
80
+
81
+ describe "receive message on a subtopic based on a field of an event" do
82
+ it "connects and publishes" do
83
+
84
+ expect(MQTT::Client).to receive(:connect).with(
85
+ :host => "test.mosquitto.org",
86
+ :port => 8883
87
+ ) do |*args, &block|
88
+ block.call(stub_client)
89
+ end
90
+
91
+ expect(stub_client).to receive(:publish).with("hello/mysubtopic", encoded_event, false, 0)
92
+
93
+ output.receive(sample_event)
94
+ end
95
+ end
96
+
97
+ end
metadata CHANGED
@@ -1,22 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-mqtt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.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-01-14 00:00:00.000000000 Z
11
+ date: 2016-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - '>='
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
18
  version: 2.0.0
19
- - - <
19
+ - - "<"
20
20
  - !ruby/object:Gem::Version
21
21
  version: 3.0.0
22
22
  name: logstash-core
@@ -24,16 +24,16 @@ dependencies:
24
24
  type: :runtime
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: 2.0.0
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 3.0.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
- - - '>='
36
+ - - ">="
37
37
  - !ruby/object:Gem::Version
38
38
  version: '0'
39
39
  name: logstash-codec-json
@@ -41,13 +41,13 @@ dependencies:
41
41
  type: :runtime
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  requirements:
50
- - - '>='
50
+ - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  name: mqtt
@@ -55,13 +55,13 @@ dependencies:
55
55
  type: :runtime
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - '>='
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - '>='
64
+ - - ">="
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  name: logstash-devutils
@@ -69,7 +69,7 @@ dependencies:
69
69
  type: :development
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  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
@@ -98,17 +98,17 @@ require_paths:
98
98
  - lib
99
99
  required_ruby_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - '>='
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.4.8
111
+ rubygems_version: 2.6.6
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: This is Logstash output plugin for the http://mqtt.org/[MQTT] protocol