logstash-output-websocket-topics 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bfca6218dcc45082cc58e3a033fa2d51bba3834c
4
+ data.tar.gz: 73c69b324105cc9aa81125b5b9fdfd7de7bbc36d
5
+ SHA512:
6
+ metadata.gz: aa8bdc7efa01e7d8623faf7ce34fe6429677fc72ae3ba0301616066eadc1a4a2520d8a6e032d4e68222cd2c67e1b97b962ecc2afdf9a2081ac87dbcec399946e
7
+ data.tar.gz: 4b937a613c2450a0ffc2099c4c4fa1c23f83214f6f58a676701f62b59b95ed548d469bf936cf4797ecb3df0809234ee60beadc34bfd2a0f8382d1eceb78312fd
@@ -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
+
@@ -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.
@@ -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/).
@@ -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.2'
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,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-websocket-topics
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.2
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
+ requirement: !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
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0.beta2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-codec-plain
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: sinatra
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.4.6
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.4.6
61
+ - !ruby/object:Gem::Dependency
62
+ name: ftw
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.0.40
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.0.40
75
+ - !ruby/object:Gem::Dependency
76
+ name: logstash-devutils
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: This gem is a logstash plugin required to be installed on top of the
90
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
91
+ a stand-alone program
92
+ email: andrewosh@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - CHANGELOG.md
98
+ - CONTRIBUTORS
99
+ - Gemfile
100
+ - LICENSE
101
+ - NOTICE.TXT
102
+ - README.md
103
+ - lib/logstash/outputs/websocket.rb
104
+ - lib/logstash/outputs/websocket/app.rb
105
+ - lib/logstash/outputs/websocket/pubsub.rb
106
+ - logstash-output-websocket.gemspec
107
+ - spec/outputs/websocket_spec.rb
108
+ homepage: ''
109
+ licenses:
110
+ - Apache License (2.0)
111
+ metadata:
112
+ logstash_plugin: 'true'
113
+ logstash_group: output
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.4.6
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: This output runs a websocket server and publishes any messages to those conencted
134
+ clients that have subscribed to the topic being published.
135
+ test_files:
136
+ - spec/outputs/websocket_spec.rb