logstash-input-paho-mqtt 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6f57500b43c224171c87f8597719d6ae0601cd13cf021720aa677d98d9b3eccc
4
+ data.tar.gz: 635d7155ad11d9e580a1ffec59beef8adb42354983462caa225cd6bab7a08347
5
+ SHA512:
6
+ metadata.gz: 5b1168093eda663eca3d1dced28d7783fded9b186b9bce784c9caad67af57a80df97f542694aced53abf2693b9edfaebe2a76a57e541abe94b030d6b6648ebae
7
+ data.tar.gz: 9f902bfb7eeaaa1e141bef9092c2ab7382cc39ebe241dc46f340e244024bd8190a9fceb5730cb8b83c26ec259dcdabc3adcb6863c04894ead448f4a344a398f0
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
@@ -0,0 +1,10 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * juri - jurkiewiczmichal@gmail.com
6
+
7
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
8
+ Logstash, and you aren't on the list above and want to be, please let us know
9
+ and we'll make sure you're here. Contributions from folks like you are what make
10
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-input-mqtt
2
+ Example input plugin. This should help bootstrap your effort to write your own input plugin!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
@@ -0,0 +1,108 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ The aim of this project is to provide production-ready logstash input plugin for MQTT protocol. This plugin uses paho.mqtt.ruby client implementation which is less popular than other libraries but supports features like QoS and persistent connection out of box.
6
+
7
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
8
+
9
+ ## Documentation
10
+
11
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
12
+
13
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
14
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
15
+
16
+ ## Need Help?
17
+
18
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
19
+
20
+ ## Developing
21
+
22
+ ### 1. Plugin Developement and Testing
23
+
24
+ #### Code
25
+ - To get started, you'll need JRuby with the Bundler gem installed.
26
+
27
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
28
+
29
+ - Install dependencies
30
+ ```sh
31
+ bundle install
32
+ ```
33
+
34
+ #### Test
35
+
36
+ - Update your dependencies
37
+
38
+ ```sh
39
+ bundle install
40
+ ```
41
+
42
+ - Run tests
43
+
44
+ ```sh
45
+ bundle exec rspec
46
+ ```
47
+
48
+ ### 2. Running your unpublished Plugin in Logstash
49
+
50
+ #### 2.1 Run in a local Logstash clone
51
+
52
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
53
+ ```ruby
54
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
55
+ ```
56
+ - Install plugin
57
+ ```sh
58
+ bin/logstash-plugin install --no-verify
59
+ ```
60
+ - Run Logstash with your plugin
61
+ ```sh
62
+ bin/logstash -e 'filter {awesome {}}'
63
+ ```
64
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
65
+
66
+ #### 2.2 Run in an installed Logstash
67
+
68
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
69
+
70
+ - Build your plugin gem
71
+ ```sh
72
+ gem build logstash-filter-awesome.gemspec
73
+ ```
74
+ - Install the plugin from the Logstash home
75
+ ```sh
76
+ bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
77
+ ```
78
+ - Start Logstash and proceed to test the plugin
79
+
80
+ ### 3. Usage
81
+
82
+ ```
83
+ input {
84
+ mqtt {
85
+ host => "localhost"
86
+ port => 1883
87
+ topic => "/logstash/input/mqtt/test"
88
+ qos => 2
89
+ }
90
+ }
91
+
92
+ filter {
93
+ }
94
+
95
+ output {
96
+ stdout {}
97
+ }
98
+ ```
99
+
100
+ ## Contributing
101
+
102
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
103
+
104
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
105
+
106
+ It is more important to the community that you are able to contribute.
107
+
108
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ require 'logstash/inputs/base'
3
+ require 'logstash/namespace'
4
+ require 'socket'
5
+ require 'paho-mqtt'
6
+
7
+ # Generate a repeating message.
8
+ #
9
+ # This plugin is intented only as an example.
10
+
11
+ class LogStash::Inputs::Mqtt < LogStash::Inputs::Base
12
+ config_name 'mqtt'
13
+
14
+ # If undefined, Logstash will complain, even if codec is unused.
15
+ default :codec, 'plain'
16
+
17
+ # https://github.com/RubyDevInc/paho.mqtt.ruby#clients-parameters
18
+ config :host, :validate => :string, :required => true
19
+ config :port, :validate => :number, :default => 1883
20
+ config :topic, :validate => :string, :required => true
21
+ config :qos, :validate => :number, :default => 0
22
+ config :mqtt_version, :validate => :string, :default => '3.1.1'
23
+ config :clean_session, :validate => :boolean, :default => true
24
+ config :client_id, :validate => :string, :default => nil
25
+ config :username, :validate => :string, :default => nil
26
+ config :password, :validate => :string, :default => nil
27
+ config :ssl, :validate => :boolean, :default => false
28
+ config :will_topic, :validate => :string, :default => nil
29
+ config :will_payload, :validate => :string, :default => ''
30
+ config :will_qos, :validate => :string, :default => 0
31
+ config :will_retain, :validate => :boolean, :default => false
32
+
33
+ public
34
+ def register
35
+ @logstash_host = Socket.gethostname
36
+ end # def register
37
+
38
+ def run(queue)
39
+ @client = PahoMqtt::Client.new({
40
+ :host => @host,
41
+ :port => @port,
42
+ :persistent => true, # keep connection persistent
43
+ :mqtt_version => @mqtt_version,
44
+ :clean_session => @clean_session,
45
+ :client_id => @client_id,
46
+ :username => @username,
47
+ :password => @password,
48
+ :ssl => @ssl,
49
+ :will_topic => @will_topic,
50
+ :will_payload => @will_payload,
51
+ :will_qos => @will_qos,
52
+ :will_retain => @will_retain
53
+ })
54
+ @client.on_message do |message|
55
+ event = LogStash::Event.new('message' => message.payload, 'host' => @logstash_host)
56
+ decorate(event)
57
+ queue << event
58
+ end
59
+ @client.connect
60
+ @client.subscribe([@topic, @qos])
61
+
62
+ Stud.stoppable_sleep(1) { stop? } while !stop?
63
+ end # def run
64
+
65
+ end # class LogStash::Inputs::Mqtt
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-input-paho-mqtt'
3
+ s.version = '0.1.1'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Logstash MQTT input plugin.'
6
+ s.homepage = 'https://github.com/jurek7/logstash-input-mqtt'
7
+ s.authors = ['juri']
8
+ s.email = 'jurkiewiczmichal@gmail.com'
9
+ s.require_paths = ['lib']
10
+
11
+ # Files
12
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
13
+ # Tests
14
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
15
+
16
+ # Special flag to let us know this is actually a logstash plugin
17
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
18
+
19
+ # Gem dependencies
20
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
21
+ s.add_runtime_dependency 'logstash-codec-plain'
22
+ s.add_runtime_dependency 'paho-mqtt', '>= 1.0.5'
23
+ s.add_development_dependency 'logstash-devutils', '>= 0.0.16'
24
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/mqtt"
4
+
5
+ describe LogStash::Inputs::Mqtt do
6
+
7
+ it_behaves_like "an interruptible input plugin" do
8
+ let(:config) { { "interval" => 100 } }
9
+ end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-paho-mqtt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - juri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: logstash-codec-plain
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.5
47
+ name: paho-mqtt
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.5
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.0.16
61
+ name: logstash-devutils
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.16
69
+ description:
70
+ email: jurkiewiczmichal@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - CHANGELOG.md
76
+ - CONTRIBUTORS
77
+ - DEVELOPER.md
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - lib/logstash/inputs/mqtt.rb
82
+ - logstash-input-mqtt.gemspec
83
+ - spec/inputs/mqtt_spec.rb
84
+ homepage: https://github.com/jurek7/logstash-input-mqtt
85
+ licenses:
86
+ - Apache-2.0
87
+ metadata:
88
+ logstash_plugin: 'true'
89
+ logstash_group: input
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.6.13
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Logstash MQTT input plugin.
110
+ test_files:
111
+ - spec/inputs/mqtt_spec.rb