logstash-output-status 0.1.1

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: 69b0b8f8d17f2f0633ba711d0d2f1f77b1f8c582
4
+ data.tar.gz: 1769b9b45bb5732de9751abc301d3079f7dc6e52
5
+ SHA512:
6
+ metadata.gz: 1ed5bc0383582ff03a8d362c6120755b00c83e830b4098434a690bf410656dea34b58c6a865af2b0fe7078dc61871291c6a1e7d379b3d83336ed7b9d7e65389d
7
+ data.tar.gz: 619747c5289a11b6d047b7952d07e59a0b61c34178d4e6edf86ebaaff61f115b97d2db9d0227dc8e23213a8d9749da8da45da1a23829281d55a4210484392891
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ## 2.0.1
2
+ - Add encoding: utf-8 to spec files. This can help prevent issues during testing.
3
+ ## 2.0.0
4
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
5
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
6
+ - Dependency on logstash-core update to 2.0
7
+
data/CONTRIBUTORS ADDED
@@ -0,0 +1,11 @@
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
+ * Pier-Hugues Pellerin (ph)
7
+
8
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
9
+ Logstash, and you aren't on the list above and want to be, please let us know
10
+ and we'll make sure you're here. Contributions from folks like you are what make
11
+ open source awesome.
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-output-example
2
+ Example output plugin. This should help bootstrap your effort to write your own output plugin!
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,142 @@
1
+ # Logstash output status
2
+
3
+ An output plugin for monitoring Logstash.
4
+
5
+ This output plugin stores the last event, and serves it as HTTP, in JSON.
6
+
7
+ This code use copy/paste oriented programmation, from http input and elapsed filter.
8
+
9
+ # Example
10
+
11
+ ```
12
+ input {
13
+ heartbeat {
14
+ interval => 10
15
+ message => "sequence"
16
+ type => "heart"
17
+ }
18
+ }
19
+
20
+ filter {}
21
+
22
+ output {
23
+ if [type] == "heart" {
24
+ stdout { codec => rubydebug }
25
+ status {
26
+ }
27
+ }
28
+ }
29
+ ```
30
+
31
+ Now you use curl to know if logstash is alive :
32
+
33
+ ```
34
+ $ curl -v http://localhost:8080/
35
+ * Trying ::1...
36
+ * Connected to localhost (::1) port 8080 (#0)
37
+ > GET / HTTP/1.1
38
+ > Host: localhost:8080
39
+ > User-Agent: curl/7.43.0
40
+ > Accept: */*
41
+ >
42
+ < HTTP/1.1 200 OK
43
+ < Content-Type: application/json
44
+ < Content-Length: 138
45
+ <
46
+ * Connection #0 to host localhost left intact
47
+ {"clock":1,"host":"My-Laptop.local","@version":"1","@timestamp":"2016-01-14T16:07:52.424Z","type":"heart","@delta":1.314}
48
+
49
+ ```
50
+
51
+ A special _@delta_ attribute is the difference between last seen event and now.
52
+
53
+
54
+ # Logstash Plugin
55
+
56
+ [![Build
57
+ Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-example-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-example-unit/)
58
+
59
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
60
+
61
+ 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.
62
+
63
+ ## Documentation
64
+
65
+ 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/).
66
+
67
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
68
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
69
+
70
+ ## Need Help?
71
+
72
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
73
+
74
+ ## Developing
75
+
76
+ ### 1. Plugin Developement and Testing
77
+
78
+ #### Code
79
+ - To get started, you'll need JRuby with the Bundler gem installed.
80
+
81
+ - 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).
82
+
83
+ - Install dependencies
84
+ ```sh
85
+ bundle install
86
+ ```
87
+
88
+ #### Test
89
+
90
+ - Update your dependencies
91
+
92
+ ```sh
93
+ bundle install
94
+ ```
95
+
96
+ - Run tests
97
+
98
+ ```sh
99
+ bundle exec rspec
100
+ ```
101
+
102
+ ### 2. Running your unpublished Plugin in Logstash
103
+
104
+ #### 2.1 Run in a local Logstash clone
105
+
106
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
107
+ ```ruby
108
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
109
+ ```
110
+ - Install plugin
111
+ ```sh
112
+ bin/plugin install --no-verify
113
+ ```
114
+ - Run Logstash with your plugin
115
+ ```sh
116
+ bin/logstash -e 'filter {awesome {}}'
117
+ ```
118
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
119
+
120
+ #### 2.2 Run in an installed Logstash
121
+
122
+ 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:
123
+
124
+ - Build your plugin gem
125
+ ```sh
126
+ gem build logstash-filter-awesome.gemspec
127
+ ```
128
+ - Install the plugin from the Logstash home
129
+ ```sh
130
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
131
+ ```
132
+ - Start Logstash and proceed to test the plugin
133
+
134
+ ## Contributing
135
+
136
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
137
+
138
+ 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.
139
+
140
+ It is more important to the community that you are able to contribute.
141
+
142
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,116 @@
1
+ # encoding: utf-8
2
+ require 'logstash/outputs/base'
3
+ require 'logstash/namespace'
4
+ require 'puma/server'
5
+ require 'puma/minissl'
6
+ require 'base64'
7
+
8
+ class Puma::Server
9
+ # ensure this method doesn't mess up our vanilla request
10
+ def normalize_env(env, client); end
11
+ end
12
+
13
+ class LogStash::Outputs::Status < LogStash::Outputs::Base
14
+ attr_accessor :lastbeat
15
+
16
+ config_name 'status'
17
+
18
+ # The host or ip to bind
19
+ config :host, validate: :string, default: '0.0.0.0'
20
+
21
+ # The TCP port to bind to
22
+ config :port, validate: :number, default: 8080
23
+
24
+ # Maximum number of threads to use
25
+ config :threads, validate: :number, default: 4
26
+
27
+ # Username for basic authorization
28
+ config :user, validate: :string, required: false
29
+
30
+ # Password for basic authorization
31
+ config :password, validate: :password, required: false
32
+
33
+ # SSL Configurations
34
+ #
35
+ # Enable SSL
36
+ config :ssl, validate: :boolean, default: false
37
+
38
+ # The JKS keystore to validate the client's certificates
39
+ config :keystore, validate: :path
40
+
41
+ # Set the truststore password
42
+ config :keystore_password, validate: :password
43
+
44
+ # useless headers puma adds to the requests
45
+ # mostly due to rack compliance
46
+ REJECTED_HEADERS = ['puma.socket', 'rack.hijack?', 'rack.hijack', 'rack.url_scheme', 'rack.after_reply', 'rack.version', 'rack.errors', 'rack.multithread', 'rack.multiprocess', 'rack.run_once', 'SCRIPT_NAME', 'QUERY_STRING', 'SERVER_PROTOCOL', 'SERVER_SOFTWARE', 'GATEWAY_INTERFACE']
47
+
48
+ RESPONSE_HEADERS = { 'Content-Type' => 'application/json' }
49
+
50
+ public
51
+
52
+ def register
53
+ @mutex = Mutex.new
54
+ @lastbeat = {}
55
+ @server = ::Puma::Server.new(nil) # we'll set the rack handler later
56
+ if @user && @password
57
+ token = Base64.strict_encode64("#{@user}:#{@password.value}")
58
+ @auth_token = "Basic #{token}"
59
+ end
60
+ if @ssl
61
+ if @keystore.nil? || @keystore_password.nil?
62
+ fail(LogStash::ConfigurationError, 'Settings :keystore and :keystore_password are required because :ssl is enabled.')
63
+ end
64
+ ctx = Puma::MiniSSL::Context.new
65
+ ctx.keystore = @keystore
66
+ ctx.keystore_pass = @keystore_password.value
67
+ @server.add_ssl_listener(@host, @port, ctx)
68
+ else
69
+ @server.add_tcp_listener(@host, @port)
70
+ end
71
+ @server.min_threads = 0
72
+ @server.max_threads = @threads
73
+
74
+ # proc needs to be defined at this context
75
+ # to capture @codecs, @logger and lowercase_keys
76
+ p = proc do |req|
77
+ begin
78
+ remote_host = req['puma.socket'].peeraddr[3]
79
+ REJECTED_HEADERS.each { |k| req.delete(k) }
80
+ body = req.delete('rack.input')
81
+ last = @lastbeat.clone
82
+ last['@delta'] = Time.new - last['@timestamp'].time
83
+ ['200', RESPONSE_HEADERS, [last.to_json]]
84
+ rescue => e
85
+ @logger.error("unable to process event #{req.inspect}. exception => #{e.inspect}")
86
+ ['500', RESPONSE_HEADERS, ['internal error']]
87
+ end
88
+ end
89
+
90
+ auth = proc do |username, password|
91
+ username == @user && password == @password.value
92
+ end if @user && @password
93
+
94
+ @server.app = Rack::Builder.new do
95
+ use(Rack::Auth::Basic, &auth) if auth
96
+ run(p)
97
+ end
98
+ @pid = @server.run
99
+ end # def register
100
+
101
+ public
102
+
103
+ def receive(_event)
104
+ 'Event received'
105
+ @mutex.synchronize do
106
+ @lastbeat = _event
107
+ end
108
+ end # def receive
109
+
110
+ public
111
+
112
+ def close
113
+ @pid.join
114
+ @server.graceful_shutdown
115
+ end # def close
116
+ end # class LogStash::Outputs::Status
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-status'
3
+ s.version = "0.1.1"
4
+ s.licenses = ["Apache License (2.0)"]
5
+ s.summary = "Http output status for monitoring"
6
+ s.description = ""
7
+ s.authors = ["athoune"]
8
+ s.email = "mlecarme@bearstech.com"
9
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec',
14
+ '*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
15
+ # Tests
16
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
+
18
+ # Special flag to let us know this is actually a logstash plugin
19
+ s.metadata = { "logstash_plugin" => "true",
20
+ "logstash_group" => "output" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
24
+ s.add_runtime_dependency "logstash-codec-plain"
25
+ s.add_runtime_dependency 'puma', '~> 2.11.3'
26
+
27
+ s.add_development_dependency "logstash-devutils"
28
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require 'logstash/devutils/rspec/spec_helper'
3
+ require 'logstash/outputs/status'
4
+ require 'logstash/codecs/plain'
5
+ require 'logstash/event'
6
+
7
+ describe LogStash::Outputs::Status do
8
+ let(:sample_event) { LogStash::Event.new }
9
+ let(:output) { LogStash::Outputs::Status.new }
10
+
11
+ before do
12
+ output.register
13
+ end
14
+
15
+ describe 'receive message' do
16
+ subject { output.receive(sample_event) }
17
+
18
+ it 'returns a string' do
19
+ expect(output.lastbeat).to notnil
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - athoune
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-18 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.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: logstash-codec-plain
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: 2.11.3
53
+ name: puma
54
+ prerelease: false
55
+ type: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 2.11.3
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ name: logstash-devutils
68
+ prerelease: false
69
+ type: :development
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: ''
76
+ email: mlecarme@bearstech.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - CHANGELOG.md
82
+ - CONTRIBUTORS
83
+ - DEVELOPER.md
84
+ - Gemfile
85
+ - LICENSE
86
+ - NOTICE.TXT
87
+ - README.md
88
+ - lib/logstash/outputs/status.rb
89
+ - logstash-output-status.gemspec
90
+ - spec/outputs/status_spec.rb
91
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
92
+ licenses:
93
+ - Apache License (2.0)
94
+ metadata:
95
+ logstash_plugin: 'true'
96
+ logstash_group: output
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Http output status for monitoring
117
+ test_files:
118
+ - spec/outputs/status_spec.rb