logstash-input-nats 0.1.0

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: 8f4eb2f314b77cc0a9cb8e7143373e3d40713401d350338ab2cddf462d7751fb
4
+ data.tar.gz: 47747c0edd3fee9275c85472fa3ffcf0637edba47487a3d34af1b35630035ced
5
+ SHA512:
6
+ metadata.gz: 63156ed6427bb0bbb0776b8ecd3b7f761fdc0cc58b46e2fecb49d3222227b7995e1fbab5d2b932a90dc1672a1eb7c37f3b51f203f8645e828dac79a1478a6852
7
+ data.tar.gz: 01ad32aede5b833463bd8102d3d03adabd5b2dd7a97b2a9a4d5ede2b995764e40df16f73b201bb95ed4b26bd262e06b4e0c39ef08592a3d38c93e9a21ec56079
@@ -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
+ * -
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-nats
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,86 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ 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.
6
+
7
+ ## Documentation
8
+
9
+ 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/).
10
+
11
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement and Testing
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - 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).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-input-nats", :path => "/your/local/logstash-input-nats"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ bin/logstash-plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'input {nats {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ 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:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-input-nats.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/logstash-plugin install /your/local/plugin/logstash-input-nats-.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ 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.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,154 @@
1
+ # encoding: utf-8
2
+ require "logstash/inputs/base"
3
+ require "logstash/namespace"
4
+ require "nats/client"
5
+
6
+ # .Compatibility Note
7
+ # [NOTE]
8
+ # ================================================================================
9
+ # This plugin does not support SSL authentication yet
10
+ #
11
+ # ================================================================================
12
+
13
+ # This input plugin will read events from a NATS instance; it does not support NATS streaming instance.
14
+ # This plugin used the following ruby nats client: https://github.com/nats-io/ruby-nats
15
+ #
16
+ # For more information about Nats, see <http://nats.io>
17
+ #
18
+ # Examples:
19
+ #
20
+ # [source,ruby]
21
+ # input {
22
+ # # Read events on subject "example" by using an "url" without authentication
23
+ # nats {
24
+ # url => "nats://localhost:4222"
25
+ # subjects => ["example"]
26
+ # }
27
+ # }
28
+ #
29
+ # [source,ruby]
30
+ # input {
31
+ # # Read events on subject "example" by using an "url" with authentication
32
+ # nats {
33
+ # url => "nats://user:passwd@localhost:4222"
34
+ # subjects => ["example"]
35
+ # }
36
+ # }
37
+ #
38
+ # [source,ruby]
39
+ # input {
40
+ # # Read events on two subjects by using other paramaters
41
+ # nats {
42
+ # host => "localhost"
43
+ # port => 4222
44
+ # user => "user"
45
+ # pass => "password"
46
+ # subjects => [ "first", "second" ]
47
+ # }
48
+ # }
49
+
50
+ class LogStash::Inputs::Nats < LogStash::Inputs::Base
51
+ config_name "nats"
52
+
53
+ milestone 1
54
+
55
+ # If undefined, Logstash will complain, even if codec is unused.
56
+ default :codec, "json"
57
+
58
+ # The url of nats server to connect on
59
+ config :url, :validate => :string
60
+
61
+ # The hostname of the nats server
62
+ config :host, :validate => :string, :default => "127.0.0.1"
63
+
64
+ # The port to connect on
65
+ config :port, :validate => :number, :default => 4222
66
+
67
+ # SSL
68
+ config :ssl, :validate => :boolean, :default => false
69
+
70
+ # User to authenticate with
71
+ config :user, :validate => :string, :required => false
72
+
73
+ # Password to authenticate with
74
+ config :pass, :validate => :password, :required => false
75
+
76
+ # List of subjects to subscribe on
77
+ config :subjects, :validate => :array, :default => ["logstash"]
78
+
79
+ # The queue group to join if needed
80
+ config :queue_group, :validate => :string, :required => false
81
+
82
+ # The name of the nats client
83
+ config :name, :validate => :string, :required => false
84
+
85
+ # Path of the private key file if ssl is used
86
+ config :private_key_file, :validate => :string, :required => false
87
+
88
+ # Path of the certificate file if ssl is used
89
+ config :cert_file, :validate => :string, :required => false
90
+
91
+ # Turn on ACK
92
+ config :verbose, :validate => :boolean, :default => false
93
+
94
+ # Turns on additional strict format checking
95
+ config :pedantic, :validate => :boolean, :default => false
96
+
97
+ # Time to wait before reconnecting
98
+ config :reconnect_time_wait, :validate => :number
99
+
100
+ # Number of attempts to connect on nats server
101
+ config :max_reconnect_attempts, :validate => :number
102
+
103
+ public
104
+ def register
105
+
106
+ @nats_server = build_nats_server
107
+
108
+ @nats_config = {
109
+ uri: @nats_server,
110
+ ssl: @ssl,
111
+ pedantic: @pedantic,
112
+ verbose: @verbose,
113
+ reconnect_time_wait: @reconnect_time_wait.nil? ? nil : @reconnect_time_wait.value,
114
+ max_reconnect_attempts: @max_reconnect_attempts.nil? ? nil : @max_reconnect_attempts.value
115
+ }
116
+ end # def register
117
+
118
+
119
+ def run(queue)
120
+ ['TERM', 'INT'].each { |s| trap(s) { puts; exit! } }
121
+
122
+ NATS.on_error { |err| puts "Server Error: #{err}"; exit! }
123
+
124
+ NATS.start(@nats_config) do
125
+ @subjects.each do |subject|
126
+ puts "Listening on [#{subject}]" #unless $show_raw
127
+ NATS.subscribe(subject, :queue => @queue_group ) do |msg, _, sub|
128
+ @codec.decode(msg) do |event|
129
+ decorate(event)
130
+ event.set("nats_subject", sub)
131
+ queue << event
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ private
139
+
140
+ def build_nats_server
141
+ if @url.nil?
142
+ if @user.nil? || @pass.nil?
143
+ nats_server = "nats://#{@host}:#{@port}"
144
+ else
145
+ nats_server = "nats://#{@user}:#{@pass.value}@#{@host}:#{@port}"
146
+ end
147
+ else
148
+ @logger.warn("Parameter 'url' is set, ignoring connection parameters: 'host', 'port', 'user' and 'pass'")
149
+ nats_server = @url
150
+ end
151
+ return nats_server
152
+ end
153
+
154
+ end # class LogStash::Inputs::Nats
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-input-nats'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Read events from a nats channel'
6
+ s.description = 'This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program'
7
+ s.homepage = 'http://www.elastic.co/guide/en/logstash/current/index.html'
8
+ s.authors = ['lliknart']
9
+ s.email = 'lliknart31@gmail.com'
10
+ s.require_paths = ['lib']
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
22
+ s.add_runtime_dependency 'logstash-codec-plain'
23
+ s.add_runtime_dependency 'stud', '>= 0.0.22'
24
+ s.add_runtime_dependency 'nats', '>= 0.8.4'
25
+ s.add_development_dependency 'logstash-devutils', '>= 0.0.16'
26
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/nats"
4
+ require "nats/client"
5
+ require "thread"
6
+ require "logstash/event"
7
+
8
+ describe LogStash::Inputs::Nats do
9
+ it_behaves_like "an interruptible input plugin" do
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-nats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - lliknart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-22 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: 0.0.22
47
+ name: stud
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.22
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.8.4
61
+ name: nats
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.4
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.0.16
75
+ name: logstash-devutils
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.16
83
+ description: This gem is a Logstash plugin required to be installed on top of the
84
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
85
+ gem is not a stand-alone program
86
+ email: lliknart31@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - CHANGELOG.md
92
+ - CONTRIBUTORS
93
+ - DEVELOPER.md
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - lib/logstash/inputs/nats.rb
98
+ - logstash-input-nats.gemspec
99
+ - spec/inputs/nats_spec.rb
100
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
101
+ licenses:
102
+ - Apache-2.0
103
+ metadata:
104
+ logstash_plugin: 'true'
105
+ logstash_group: input
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.6.13
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Read events from a nats channel
126
+ test_files:
127
+ - spec/inputs/nats_spec.rb