logstash-output-mqtt 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/logstash/outputs/mqtt.rb +13 -23
- data/logstash-output-mqtt.gemspec +5 -3
- data/spec/outputs/mqtt_spec.rb +8 -23
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6466f5b821ccadda609280f2b3fa5f8db9db834a67a09b3687504058233c391a
|
4
|
+
data.tar.gz: eadd6cde4e746c043b2ca6fc400ff98f08181cbdf1c930dc2580cc594cb3c99d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fdd61209f6761f2c06459d2099632472b68880a836224315634b5789fb2334c1955df195c461d2f1285b60d3990b7813a607abc1b7100143ee76d6a37bfeee4
|
7
|
+
data.tar.gz: 7ad0be8ab0e16a818673cc4622778fb4b9e88481f5a0e949092fdb4d7428c52b805a00806b892c4f35304c5555edecd02b3c5e6576278989b1e4610d3db4152c
|
@@ -102,7 +102,6 @@ class LogStash::Outputs::MQTT < LogStash::Outputs::Base
|
|
102
102
|
# Time in seconds to wait before retrying a connection
|
103
103
|
config :connect_retry_interval, :validate => :number, :default => 10
|
104
104
|
|
105
|
-
public
|
106
105
|
def register
|
107
106
|
@options = {
|
108
107
|
:host => @host
|
@@ -138,50 +137,41 @@ class LogStash::Outputs::MQTT < LogStash::Outputs::Base
|
|
138
137
|
@codec.on_event do |event, encoded_event|
|
139
138
|
@event_buffer.push([event, encoded_event])
|
140
139
|
end
|
141
|
-
|
142
140
|
end # def register
|
143
141
|
|
144
|
-
public
|
145
142
|
def receive(event)
|
146
|
-
|
147
143
|
@codec.encode(event)
|
148
144
|
handle_events
|
149
145
|
end # def receive
|
150
146
|
|
151
|
-
public
|
152
147
|
def multi_receive(events)
|
153
|
-
events.each
|
154
|
-
@codec.encode(event)
|
155
|
-
end
|
156
|
-
|
148
|
+
events.each { |event| @codec.encode(event) }
|
157
149
|
# Handle all events at once to prevent taking a new connection for each event
|
158
150
|
handle_events
|
159
151
|
end
|
160
152
|
|
161
|
-
public
|
162
153
|
def close
|
163
|
-
|
164
154
|
@closing = true
|
165
155
|
end # def close
|
166
156
|
|
167
157
|
private
|
168
|
-
|
169
|
-
|
170
|
-
# This way it is easy to cope with network failures, ie. if connection fails just try it again
|
158
|
+
|
159
|
+
def mqtt_client
|
171
160
|
@logger.debug("Connecting MQTT with options #{@options}")
|
172
|
-
MQTT::Client.connect(@options)
|
173
|
-
|
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)
|
176
|
-
@event_buffer.shift
|
177
|
-
end
|
178
|
-
end
|
161
|
+
@mqtt_client ||= MQTT::Client.connect(@options)
|
162
|
+
end
|
179
163
|
|
164
|
+
def handle_events
|
165
|
+
# It is easy to cope with network failures, ie. if connection fails just try it again
|
166
|
+
while event = @event_buffer.first do
|
167
|
+
@logger.debug("Publishing MQTT event #{event[1]} with topic #{@topic}, retain #{@retain}, qos #{@qos}")
|
168
|
+
mqtt_client.publish(event[0].sprintf(@topic), event[1], @retain, @qos)
|
169
|
+
@event_buffer.shift
|
170
|
+
end
|
180
171
|
rescue StandardError => e
|
181
172
|
@logger.error("Error #{e.message} while publishing to MQTT server. Will retry in #{@connect_retry_interval} seconds.")
|
182
|
-
|
173
|
+
@mqtt_client = nil
|
183
174
|
Stud.stoppable_sleep(@connect_retry_interval, 1) { @closing }
|
184
175
|
retry
|
185
176
|
end # def handle_event
|
186
|
-
|
187
177
|
end # class LogStash::Outputs::MQTT
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-output-mqtt'
|
3
|
-
s.version = "1.
|
4
|
-
s.licenses = ["Apache
|
3
|
+
s.version = "1.2.0"
|
4
|
+
s.licenses = ["Apache-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"
|
7
7
|
s.authors = ["Tommi Palomäki"]
|
@@ -22,5 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
|
23
23
|
s.add_runtime_dependency "logstash-codec-json"
|
24
24
|
s.add_runtime_dependency "mqtt"
|
25
|
-
|
25
|
+
|
26
|
+
# 1.3.5 version has some problems, stick to 1.3.4 by now
|
27
|
+
s.add_development_dependency "logstash-devutils", "< 1.3.6"
|
26
28
|
end
|
data/spec/outputs/mqtt_spec.rb
CHANGED
@@ -4,6 +4,7 @@ require "logstash/outputs/mqtt"
|
|
4
4
|
require "logstash/codecs/json"
|
5
5
|
require "logstash/event"
|
6
6
|
require "time"
|
7
|
+
require "json"
|
7
8
|
|
8
9
|
describe LogStash::Outputs::MQTT do
|
9
10
|
# Define a sample event and its JSON encoded form
|
@@ -11,48 +12,37 @@ describe LogStash::Outputs::MQTT do
|
|
11
12
|
tstamp = Time.parse(datestring)
|
12
13
|
tstamp_utc = tstamp.utc.iso8601(3)
|
13
14
|
let(:sample_event) { LogStash::Event.new("message" => "test message", "@timestamp" => datestring) }
|
14
|
-
encoded_event = "{\"
|
15
|
+
encoded_event = "{\"message\":\"test message\",\"@version\":\"1\",\"@timestamp\":\"" + tstamp_utc + "\"}"
|
15
16
|
|
16
17
|
settings = {
|
17
18
|
"host" => "test.mosquitto.org",
|
18
19
|
"topic" => "hello"
|
19
20
|
}
|
20
21
|
let(:output) { LogStash::Outputs::MQTT.new(settings) }
|
21
|
-
let(:stub_client) {
|
22
|
+
let(:stub_client) { instance_double(MQTT::Client) }
|
22
23
|
|
23
24
|
before do
|
24
25
|
output.register
|
25
26
|
end
|
26
27
|
|
27
28
|
describe "receive message" do
|
28
|
-
|
29
29
|
it "connects and publishes with correct arguments" do
|
30
|
-
|
31
30
|
expect(MQTT::Client).to receive(:connect).with(
|
32
31
|
:host => "test.mosquitto.org",
|
33
32
|
:port => 8883
|
34
|
-
)
|
35
|
-
block.call(stub_client)
|
36
|
-
end
|
37
|
-
|
33
|
+
).and_return(stub_client)
|
38
34
|
expect(stub_client).to receive(:publish).with("hello", encoded_event, false, 0)
|
39
|
-
|
40
35
|
output.receive(sample_event)
|
41
36
|
end
|
42
37
|
end
|
43
38
|
|
44
39
|
describe "multi_receive" do
|
45
40
|
it "connects once and publishes all messages" do
|
46
|
-
|
47
41
|
expect(MQTT::Client).to receive(:connect).once.with(
|
48
42
|
:host => "test.mosquitto.org",
|
49
43
|
:port => 8883
|
50
|
-
)
|
51
|
-
block.call(stub_client)
|
52
|
-
end
|
53
|
-
|
44
|
+
).and_return(stub_client)
|
54
45
|
expect(stub_client).to receive(:publish).exactly(3).times.with("hello", encoded_event, false, 0)
|
55
|
-
|
56
46
|
three_events = [sample_event, sample_event, sample_event]
|
57
47
|
output.multi_receive(three_events)
|
58
48
|
end
|
@@ -65,14 +55,14 @@ describe "Test subtopic:" do
|
|
65
55
|
tstamp = Time.parse(datestring)
|
66
56
|
tstamp_utc = tstamp.utc.iso8601(3)
|
67
57
|
let(:sample_event) { LogStash::Event.new("message" => "test message", "@timestamp" => datestring, "subtopic" => "mysubtopic") }
|
68
|
-
encoded_event = "{\"@timestamp\":\"" + tstamp_utc + "\",\"
|
58
|
+
encoded_event = "{\"@version\":\"1\",\"@timestamp\":\"" + tstamp_utc + "\",\"message\":\"test message\",\"subtopic\":\"mysubtopic\"}"
|
69
59
|
|
70
60
|
settings = {
|
71
61
|
"host" => "test.mosquitto.org",
|
72
62
|
"topic" => "hello/%{subtopic}"
|
73
63
|
}
|
74
64
|
let(:output) { LogStash::Outputs::MQTT.new(settings) }
|
75
|
-
let(:stub_client) {
|
65
|
+
let(:stub_client) { instance_double(MQTT::Client) }
|
76
66
|
|
77
67
|
before do
|
78
68
|
output.register
|
@@ -80,16 +70,11 @@ describe "Test subtopic:" do
|
|
80
70
|
|
81
71
|
describe "receive message on a subtopic based on a field of an event" do
|
82
72
|
it "connects and publishes" do
|
83
|
-
|
84
73
|
expect(MQTT::Client).to receive(:connect).with(
|
85
74
|
:host => "test.mosquitto.org",
|
86
75
|
:port => 8883
|
87
|
-
)
|
88
|
-
block.call(stub_client)
|
89
|
-
end
|
90
|
-
|
76
|
+
).and_return(stub_client)
|
91
77
|
expect(stub_client).to receive(:publish).with("hello/mysubtopic", encoded_event, false, 0)
|
92
|
-
|
93
78
|
output.receive(sample_event)
|
94
79
|
end
|
95
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-output-mqtt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommi Palomäki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
requirements:
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: 1.3.
|
60
|
+
version: 1.3.6
|
61
61
|
name: logstash-devutils
|
62
62
|
prerelease: false
|
63
63
|
type: :development
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
requirements:
|
66
66
|
- - "<"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.3.
|
68
|
+
version: 1.3.6
|
69
69
|
description: This gem is a logstash plugin required to be installed on top of the
|
70
70
|
Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
|
71
71
|
a stand-alone program
|
@@ -85,7 +85,7 @@ files:
|
|
85
85
|
- spec/outputs/mqtt_spec.rb
|
86
86
|
homepage: https://github.com/kompa3/logstash-output-mqtt
|
87
87
|
licenses:
|
88
|
-
- Apache
|
88
|
+
- Apache-2.0
|
89
89
|
metadata:
|
90
90
|
logstash_plugin: 'true'
|
91
91
|
logstash_group: output
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.6
|
108
|
+
rubygems_version: 2.7.6
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: This is Logstash output plugin for the http://mqtt.org/[MQTT] protocol
|