logstash-output-websocket_topics 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b68f5c46a6f123d6663a8539a5e5a0f7ab599b3
4
+ data.tar.gz: 6d251431647f37e5c3ec332ec4d2ab65005ce30d
5
+ SHA512:
6
+ metadata.gz: 6f5434cdd2e86559001ac0113edbf56886b2ce45cde3963cdadfb2c1abbc17147bbbdb11d40e30f7314d9d9b041fbc8d3797af0d707cccc1bcd4747bb90a7c96
7
+ data.tar.gz: ac5db53cf1612c374fe6508f13aef251e2c6dddf529826af1a6ef9aa31d6011018edc61759f795703ee5f64fc7779a254bebe9e3c1fdc556f0b385a26e658221
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 2.0.0
2
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
3
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
4
+ - Dependency on logstash-core update to 2.0
5
+
data/CONTRIBUTORS ADDED
@@ -0,0 +1,15 @@
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
+ * Aaron Mildenstein (untergeek)
6
+ * John E. Vincent (lusis)
7
+ * Jordan Sissel (jordansissel)
8
+ * Pete Fritchman (fetep)
9
+ * Pier-Hugues Pellerin (ph)
10
+ * Richard Pijnenburg (electrical)
11
+
12
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
13
+ Logstash, and you aren't on the list above and want to be, please let us know
14
+ and we'll make sure you're here. Contributions from folks like you are what make
15
+ open source awesome.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Logstash Plugin
2
+
3
+ [![Build
4
+ Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-websocket-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-websocket-unit/)
5
+
6
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
7
+
8
+ 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.
9
+
10
+ ## Documentation
11
+
12
+ 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/).
13
+
14
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
15
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
16
+
17
+ ## Need Help?
18
+
19
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
20
+
21
+ ## Developing
22
+
23
+ ### 1. Plugin Developement and Testing
24
+
25
+ #### Code
26
+ - To get started, you'll need JRuby with the Bundler gem installed.
27
+
28
+ - 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).
29
+
30
+ - Install dependencies
31
+ ```sh
32
+ bundle install
33
+ ```
34
+
35
+ #### Test
36
+
37
+ - Update your dependencies
38
+
39
+ ```sh
40
+ bundle install
41
+ ```
42
+
43
+ - Run tests
44
+
45
+ ```sh
46
+ bundle exec rspec
47
+ ```
48
+
49
+ ### 2. Running your unpublished Plugin in Logstash
50
+
51
+ #### 2.1 Run in a local Logstash clone
52
+
53
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
54
+ ```ruby
55
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
56
+ ```
57
+ - Install plugin
58
+ ```sh
59
+ bin/plugin install --no-verify
60
+ ```
61
+ - Run Logstash with your plugin
62
+ ```sh
63
+ bin/logstash -e 'filter {awesome {}}'
64
+ ```
65
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
66
+
67
+ #### 2.2 Run in an installed Logstash
68
+
69
+ 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:
70
+
71
+ - Build your plugin gem
72
+ ```sh
73
+ gem build logstash-filter-awesome.gemspec
74
+ ```
75
+ - Install the plugin from the Logstash home
76
+ ```sh
77
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
78
+ ```
79
+ - Start Logstash and proceed to test the plugin
80
+
81
+ ## Contributing
82
+
83
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
84
+
85
+ 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.
86
+
87
+ It is more important to the community that you are able to contribute.
88
+
89
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ require "logstash/namespace"
3
+ require "logstash/outputs/base"
4
+
5
+
6
+ # This output runs a websocket server and publishes any
7
+ # messages to all connected websocket clients.
8
+ #
9
+ # You can connect to it with ws://<host\>:<port\>/
10
+ #
11
+ # If no clients are connected, any messages received are ignored.
12
+ class LogStash::Outputs::WebSocket < LogStash::Outputs::Base
13
+ config_name "websocket"
14
+
15
+ # The address to serve websocket data from
16
+ config :host, :validate => :string, :default => "0.0.0.0"
17
+
18
+ # The port to serve websocket data from
19
+ config :port, :validate => :number, :default => 3232
20
+
21
+ def make_pubsub(topic)
22
+ pubsub = Logstash::Outputs::WebSocket::Pubsub.new
23
+ pubsub.logger = @logger
24
+ end
25
+
26
+ public
27
+ def register
28
+ require "ftw"
29
+ require "logstash/outputs/websocket/app"
30
+ require "logstash/outputs/websocket/pubsub"
31
+ @channels = {}
32
+ @server = Thread.new(@channels) do |channels|
33
+ begin
34
+ Rack::Handler::FTW.run(LogStash::Outputs::WebSocket::App.new(channels, @logger),
35
+ :Host => @host, :Port => @port)
36
+ rescue => e
37
+ @logger.error("websocket server failed", :exception => e)
38
+ sleep 1
39
+ retry
40
+ end
41
+ end
42
+ end # def register
43
+
44
+ public
45
+ def receive(event)
46
+ json = event.to_json
47
+ topic = json.topic
48
+ if @channels.has_key?(topic)
49
+ @channels[topic].publish(json)
50
+ else
51
+ pubsub = make_pubsub(topic)
52
+ @channels[topic] = pubsub
53
+ pubsub.publish(json)
54
+ end # if
55
+ end # def receive
56
+
57
+ end # class LogStash::Outputs::Websocket
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ require "logstash/namespace"
3
+ require "logstash/outputs/websocket"
4
+ require "sinatra/base"
5
+ require "rack/handler/ftw" # from ftw
6
+ require "ftw/websocket/rack" # from ftw
7
+
8
+ class LogStash::Outputs::WebSocket::App < Sinatra::Base
9
+ def initialize(channels, logger)
10
+ @channels = channels
11
+ @logger = logger
12
+ end
13
+
14
+ set :reload_templates, false
15
+
16
+ get "/" do
17
+ # TODO(sissel): Support filters/etc.
18
+ ws = ::FTW::WebSocket::Rack.new(env)
19
+ @logger.debug("New websocket client")
20
+ stream(:keep_open) do |out|
21
+ ws.each do |payload|
22
+ json = payload.to_json
23
+ if json.type == 'subscribe-topic'
24
+ @channels[json.topic].subscribe do |event|
25
+ ws.publish(event)
26
+ end
27
+ elsif json.type == 'subscribe-all'
28
+ @channels.values.each do |channel|
29
+ channel.subscribe do |event|
30
+ ws.publish(event)
31
+ end
32
+ end
33
+ end
34
+ end # pubsub
35
+ end # stream
36
+
37
+ ws.rack_response
38
+ end # get /
39
+ end # class LogStash::Outputs::WebSocket::App
40
+
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ require "logstash/namespace"
3
+ require "logstash/outputs/websocket"
4
+
5
+ class LogStash::Outputs::WebSocket::Pubsub
6
+ attr_accessor :logger
7
+
8
+ def initialize
9
+ @subscribers = []
10
+ @subscribers_lock = Mutex.new
11
+ end # def initialize
12
+
13
+ def publish(object)
14
+ @subscribers_lock.synchronize do
15
+ break if @subscribers.size == 0
16
+
17
+ failed = []
18
+ @subscribers.each do |subscriber|
19
+ begin
20
+ subscriber.call(object)
21
+ rescue => e
22
+ @logger.error("Failed to publish to subscriber", :subscriber => subscriber, :exception => e)
23
+ failed << subscriber
24
+ end
25
+ end
26
+
27
+ failed.each do |subscriber|
28
+ @subscribers.delete(subscriber)
29
+ end
30
+ end # @subscribers_lock.synchronize
31
+ end # def Pubsub
32
+
33
+ def subscribe(&block)
34
+ queue = Queue.new
35
+ @subscribers_lock.synchronize do
36
+ @subscribers << proc do |event|
37
+ queue << event
38
+ end
39
+ end
40
+
41
+ while true
42
+ block.call(queue.pop)
43
+ end
44
+ end # def subscribe
45
+ end # class LogStash::Outputs::WebSocket::Pubsub
@@ -0,0 +1,30 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-output-websocket_topics'
4
+ s.version = '2.1.4'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "This output runs a websocket server and publishes any messages to those conencted clients that have subscribed to the topic being published."
7
+ 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"
8
+ s.authors = ["Andrew Osheroff"]
9
+ s.email = 'andrewosh@gmail.com'
10
+ s.homepage = ""
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
15
+
16
+ # Tests
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+
19
+ # Special flag to let us know this is actually a logstash plugin
20
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0.beta2", "< 3.0.0"
24
+ s.add_runtime_dependency 'logstash-codec-plain'
25
+ s.add_runtime_dependency 'sinatra', '~> 1.4.6'
26
+ s.add_runtime_dependency 'ftw', ['~> 0.0.40']
27
+
28
+ s.add_development_dependency 'logstash-devutils'
29
+ end
30
+
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/outputs/websocket"
4
+
5
+ describe "output/websocket" do
6
+
7
+ subject(:output) { LogStash::Outputs::WebSocket.new }
8
+
9
+ it "should register" do
10
+ expect {output.register}.to_not raise_error
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-websocket_topics
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Osheroff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0.beta2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 2.0.0.beta2
28
+ - - "<"
29
+ - !ruby/object:Gem::Version
30
+ version: 3.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-codec-plain
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: sinatra
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.4.6
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
58
+ version: 1.4.6
59
+ prerelease: false
60
+ type: :runtime
61
+ - !ruby/object:Gem::Dependency
62
+ name: ftw
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.0.40
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: 0.0.40
73
+ prerelease: false
74
+ type: :runtime
75
+ - !ruby/object:Gem::Dependency
76
+ name: logstash-devutils
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ prerelease: false
88
+ type: :development
89
+ 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
90
+ email: andrewosh@gmail.com
91
+ executables: []
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - CHANGELOG.md
96
+ - CONTRIBUTORS
97
+ - Gemfile
98
+ - LICENSE
99
+ - NOTICE.TXT
100
+ - README.md
101
+ - lib/logstash/outputs/websocket.rb
102
+ - lib/logstash/outputs/websocket/app.rb
103
+ - lib/logstash/outputs/websocket/pubsub.rb
104
+ - logstash-output-websocket_topics.gemspec
105
+ - spec/outputs/websocket_spec.rb
106
+ homepage: ''
107
+ licenses:
108
+ - Apache License (2.0)
109
+ metadata:
110
+ logstash_plugin: 'true'
111
+ logstash_group: output
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.8
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: This output runs a websocket server and publishes any messages to those conencted clients that have subscribed to the topic being published.
132
+ test_files:
133
+ - spec/outputs/websocket_spec.rb