logstash-input-paho-mqtt 0.1.2 → 0.1.4
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/inputs/mqtt.rb +33 -6
- data/lib/logstash/inputs/mqtt/logstash_mqtt.rb +53 -0
- data/logstash-input-mqtt.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8305817f372e5cb1bc4e67aa01f6e4b70c5d3d706a883012622774a42fd38ae1
|
4
|
+
data.tar.gz: f29106c4f90d9c4a7802ed19de9e10f57f6271e7d947b9534713757cd92d611c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fab45a3ef1c8b3808a93af58b65c8d02e6fc5ee02838e9dae667b2e8b14fe987a005c38d9f8660cc9c1e2d324893942cd817cd23483c41f2d80881b5e0712c72
|
7
|
+
data.tar.gz: 0aaa45dee17ba825821093e9ebdf1a87fc8ab31b99e8651e3882123a96bb1cc2aad43759903b72fb1f7a8ede22ef151062df591393c2ab6fe41e2ce106bc1d2f
|
data/lib/logstash/inputs/mqtt.rb
CHANGED
@@ -9,6 +9,8 @@ require 'paho-mqtt'
|
|
9
9
|
# This plugin is intented only as an example.
|
10
10
|
|
11
11
|
class LogStash::Inputs::Mqtt < LogStash::Inputs::Base
|
12
|
+
require "logstash/inputs/mqtt/logstash_mqtt"
|
13
|
+
|
12
14
|
config_name 'mqtt'
|
13
15
|
|
14
16
|
# If undefined, Logstash will complain, even if codec is unused.
|
@@ -29,6 +31,14 @@ class LogStash::Inputs::Mqtt < LogStash::Inputs::Base
|
|
29
31
|
config :will_payload, :validate => :string, :default => ''
|
30
32
|
config :will_qos, :validate => :string, :default => 0
|
31
33
|
config :will_retain, :validate => :boolean, :default => false
|
34
|
+
config :persistent, :validate => :boolean, :default => true
|
35
|
+
config :logfile, :validate => :string, :default => nil
|
36
|
+
config :log_level, :validate => :string, :default => 'ERROR'
|
37
|
+
config :reconnect_retries, :validate => :number, :default => -1 #-1 infinite loop
|
38
|
+
config :reconnect_sleep_time, :validate => :number, :default => 5
|
39
|
+
config :certificate_path, :validate => :string, :default => nil
|
40
|
+
config :key_path, :validate => :string, :default => nil
|
41
|
+
config :root_ca_path, :validate => :string, :default => nil
|
32
42
|
|
33
43
|
public
|
34
44
|
def register
|
@@ -36,10 +46,14 @@ class LogStash::Inputs::Mqtt < LogStash::Inputs::Base
|
|
36
46
|
end # def register
|
37
47
|
|
38
48
|
def run(queue)
|
39
|
-
|
49
|
+
PahoMqtt.logger = @logfile unless @logfile.nil?
|
50
|
+
#levels: DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
|
51
|
+
PahoMqtt.logger.level = @log_level unless @logfile.nil?
|
52
|
+
|
53
|
+
@client = RecoverableMqttClient.new({
|
40
54
|
:host => @host,
|
41
55
|
:port => @port,
|
42
|
-
:persistent =>
|
56
|
+
:persistent => @persistent, # keep connection persistent
|
43
57
|
:mqtt_version => @mqtt_version,
|
44
58
|
:clean_session => @clean_session,
|
45
59
|
:client_id => @client_id,
|
@@ -49,20 +63,31 @@ class LogStash::Inputs::Mqtt < LogStash::Inputs::Base
|
|
49
63
|
:will_topic => @will_topic,
|
50
64
|
:will_payload => @will_payload,
|
51
65
|
:will_qos => @will_qos,
|
52
|
-
:will_retain => @will_retain
|
66
|
+
:will_retain => @will_retain,
|
67
|
+
:retry_reconnection_max_count => @reconnect_retries,
|
68
|
+
:retry_reconnection_sleep_time => @reconnect_sleep_time,
|
53
69
|
})
|
70
|
+
|
71
|
+
if @ssl
|
72
|
+
@client.config_ssl_context(@certificate_path, @key_path, @root_ca_path)
|
73
|
+
end
|
74
|
+
|
54
75
|
@client.on_message do |message|
|
55
76
|
@codec.decode(message.payload) do |event|
|
56
77
|
host = event.get("host") || @logstash_host
|
57
78
|
event.set("host", host)
|
79
|
+
event.set("topic", message.topic)
|
58
80
|
|
59
81
|
decorate(event)
|
60
82
|
queue << event
|
61
83
|
end
|
62
84
|
end
|
63
85
|
|
86
|
+
is_connected = false
|
87
|
+
|
64
88
|
begin
|
65
89
|
@client.connect
|
90
|
+
is_connected = true
|
66
91
|
rescue PahoMqtt::Exception => e
|
67
92
|
@logger.warn("Error while setting up connection for MQTT broker! Retrying.",
|
68
93
|
:message => e.message,
|
@@ -73,10 +98,12 @@ class LogStash::Inputs::Mqtt < LogStash::Inputs::Base
|
|
73
98
|
retry
|
74
99
|
end
|
75
100
|
|
76
|
-
|
77
|
-
|
101
|
+
if is_connected
|
102
|
+
# subscribe to topic
|
103
|
+
@client.subscribe([@topic, @qos])
|
78
104
|
|
79
|
-
|
105
|
+
Stud.stoppable_sleep(1) { stop? } while !stop?
|
106
|
+
end
|
80
107
|
end # def run
|
81
108
|
|
82
109
|
end # class LogStash::Inputs::Mqtt
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "paho-mqtt"
|
2
|
+
require "logger"
|
3
|
+
|
4
|
+
module LogStash
|
5
|
+
module Inputs
|
6
|
+
class Mqtt
|
7
|
+
class RecoverableMqttClient < PahoMqtt::Client
|
8
|
+
|
9
|
+
attr_accessor :retry_reconnection_max_count
|
10
|
+
attr_accessor :retry_reconnection_sleep_time
|
11
|
+
|
12
|
+
def initialize(*args)
|
13
|
+
@retry_reconnection_max_count = 3
|
14
|
+
@retry_reconnection_sleep_time = 5
|
15
|
+
@stop_connection = false
|
16
|
+
super(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def reconnect
|
20
|
+
@reconnect_thread = Thread.new do
|
21
|
+
retries = @retry_reconnection_max_count
|
22
|
+
while retries != 0 do
|
23
|
+
retries -= 1 unless retry_reconnection_max_count < 0
|
24
|
+
if @stop
|
25
|
+
PahoMqtt.logger.warn("RecoverableClient::Reconnection attempt is over due to stop request.") if PahoMqtt.logger?
|
26
|
+
disconnect(false)
|
27
|
+
exit(1)
|
28
|
+
break
|
29
|
+
end
|
30
|
+
PahoMqtt.logger.debug("RecoverableClient::New reconnect attempt...remaining retries #{retries}") if PahoMqtt.logger?
|
31
|
+
connect
|
32
|
+
if connected?
|
33
|
+
break
|
34
|
+
else
|
35
|
+
sleep @retry_reconnection_sleep_time
|
36
|
+
end
|
37
|
+
end
|
38
|
+
unless connected?
|
39
|
+
PahoMqtt.logger.error("RecoverableClient::Reconnection attempt counter is over.(#{@retry_reconnection_max_count} times)") if PahoMqtt.logger?
|
40
|
+
disconnect(false)
|
41
|
+
exit(1)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def stop
|
48
|
+
@stop_connection = true
|
49
|
+
end
|
50
|
+
end #class RecoverableMqttClient
|
51
|
+
end #class Mqtt
|
52
|
+
end #module Inputs
|
53
|
+
end #module LogStash
|
data/logstash-input-mqtt.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-paho-mqtt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- juri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- LICENSE
|
80
80
|
- README.md
|
81
81
|
- lib/logstash/inputs/mqtt.rb
|
82
|
+
- lib/logstash/inputs/mqtt/logstash_mqtt.rb
|
82
83
|
- logstash-input-mqtt.gemspec
|
83
84
|
- spec/inputs/mqtt_spec.rb
|
84
85
|
homepage: https://github.com/jurek7/logstash-input-mqtt
|