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 +4 -4
- data/lib/logstash/outputs/mqtt.rb +14 -6
- data/logstash-output-mqtt.gemspec +1 -1
- data/spec/outputs/mqtt_spec.rb +43 -2
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dcc117ed489aa6aa8ae774a3d300f9df65b153b
|
4
|
+
data.tar.gz: 54f322258c1d332cbdf8e64a07d506cbb2abbeaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d6baf3c028c4a729a2baa094099729ee54acdb133c5040dc5ad8b664e8c6326c5ea0b1eb5ccb77a1a403823ae67f7065feaa67196000e080b9708632ff3198b
|
7
|
+
data.tar.gz: df91c4d1db2ba435611aa3b801bad8a42c49b9452bd5b71aa8a9f28c48bd593f65c6fc5ca26a80125d257ec37c2ba23b4e3b2628d456eaf8019e1b73de4010d1
|
@@ -43,8 +43,16 @@ require "mqtt"
|
|
43
43
|
# }
|
44
44
|
# ----------------------------------
|
45
45
|
#
|
46
|
-
#
|
47
|
-
#
|
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
|
166
|
-
@logger.debug("Publishing MQTT event #{
|
167
|
-
client.publish(@topic,
|
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.
|
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"
|
data/spec/outputs/mqtt_spec.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
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.
|
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-
|
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.
|
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
|