logstash-output-sentry 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
+ SHA1:
3
+ metadata.gz: d8de667fbcb016da4649ee29c7d6193ef99af069
4
+ data.tar.gz: deb9057c87497347303620fbf2bc700726cec89c
5
+ SHA512:
6
+ metadata.gz: 7145110b5052de92e18c1808be0f187edfe5084f0a7517742341f6bb08225cc770045376ad51894583a14a6500eb66730a7606e5d4f4b48c051e55f75d4486bb
7
+ data.tar.gz: 3e81262b7f1bbd9b5e891bbda08fb7045b4528459392d33022926d76ccd4b450476ebdabe7915e5539aae0e249c5aaf77a7af3e873319681107811569972a3af
@@ -0,0 +1,4 @@
1
+ ## 0.1.0
2
+ - Starting project from clarkdave/logstash-sentry.rb
3
+ - Packing script in a gem so it can be easily installed.
4
+ - Adding parameters so that we can use the plugin to send data to our own sentry server.
@@ -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
+ * Javier Matos Odut (javiermatos)
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 @@
1
+ # logstash-output-sentry
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-example-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-example-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,93 @@
1
+ # encoding: utf-8
2
+ # The MIT License (MIT)
3
+
4
+ # Copyright (c) 2014 Dave Clark
5
+
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+
24
+ require 'logstash/outputs/base'
25
+ require 'logstash/namespace'
26
+
27
+ class LogStash::Outputs::Sentry < LogStash::Outputs::Base
28
+
29
+ config_name 'sentry'
30
+
31
+ config :host, :validate => :string, :required => true, :default => 'app.getsentry.com'
32
+ config :use_ssl, :validate => :boolean, :required => false, :default => true
33
+ config :key, :validate => :string, :required => true
34
+ config :secret, :validate => :string, :required => true
35
+ config :project_id, :validate => :string, :required => true
36
+
37
+ public
38
+ def register
39
+ require 'net/https'
40
+ require 'uri'
41
+
42
+ @url = "%{proto}://#{host}/api/#{project_id}/store/" % { :proto => use_ssl ? 'https' : 'http' }
43
+ @uri = URI.parse(@url)
44
+ @client = Net::HTTP.new(@uri.host, @uri.port)
45
+ @client.use_ssl = use_ssl
46
+ @client.verify_mode = OpenSSL::SSL::VERIFY_NONE
47
+
48
+ @logger.debug('Client', :client => @client.inspect)
49
+ end
50
+
51
+ public
52
+ def receive(event)
53
+ return unless output?(event)
54
+
55
+ require 'json'
56
+ require 'securerandom'
57
+
58
+ packet = {
59
+ :event_id => SecureRandom.uuid.gsub('-', ''),
60
+ :timestamp => event['@timestamp'],
61
+ :message => event['message']
62
+ }
63
+
64
+ packet[:level] = event['[fields][level]']
65
+
66
+ packet[:platform] = 'logstash'
67
+ packet[:server_name] = event['host']
68
+ #packet[:extra] = event['fields'].to_hash
69
+
70
+ @logger.debug('Sentry packet', :sentry_packet => packet)
71
+
72
+ auth_header = "Sentry sentry_version=5," +
73
+ "sentry_client=raven_logstash/1.0," +
74
+ "sentry_timestamp=#{event['@timestamp'].to_i}," +
75
+ "sentry_key=#{@key}," +
76
+ "sentry_secret=#{@secret}"
77
+
78
+ request = Net::HTTP::Post.new(@uri.path)
79
+
80
+ begin
81
+ request.body = packet.to_json
82
+ request.add_field('X-Sentry-Auth', auth_header)
83
+
84
+ response = @client.request(request)
85
+
86
+ @logger.info('Sentry response', :request => request.inspect, :response => response.inspect)
87
+
88
+ raise unless response.code == '200'
89
+ rescue Exception => e
90
+ @logger.warn('Unhandled exception', :request => request.inspect, :response => response.inspect, :exception => e.inspect)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-sentry'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = 'This output plugin sends messages to any sentry server.'
6
+ 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.'
7
+ s.authors = ['Javier Matos Odut']
8
+ s.email = 'iam@javiermatos.com'
9
+ s.homepage = 'https://github.com/javiermatos/logstash-output-sentry'
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' => 'output' }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency 'logstash-core', '>= 2.0.0', '< 3.0.0'
22
+ s.add_runtime_dependency 'logstash-codec-plain'
23
+ s.add_runtime_dependency 'json', '>=1.8.0', '< 2.0.0'
24
+ s.add_development_dependency 'logstash-devutils'
25
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require 'logstash/devutils/rspec/spec_helper'
3
+ require 'logstash/outputs/sentry'
4
+ require 'logstash/codecs/plain'
5
+ require 'logstash/event'
6
+
7
+ describe LogStash::Outputs::Sentry do
8
+ let(:sample_event) { LogStash::Event.new }
9
+ let(:output) { LogStash::Outputs::Sentry.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(subject).to eq('Event received')
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-sentry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Javier Matos Odut
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-02 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
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
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: json
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.8.0
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: 2.0.0
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.8.0
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: 2.0.0
67
+ - !ruby/object:Gem::Dependency
68
+ name: logstash-devutils
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ description: This gem is a logstash plugin required to be installed on top of the
82
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
83
+ a stand-alone program.
84
+ email: iam@javiermatos.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - CHANGELOG.md
90
+ - CONTRIBUTORS
91
+ - DEVELOPER.md
92
+ - Gemfile
93
+ - LICENSE
94
+ - NOTICE.TXT
95
+ - README.md
96
+ - lib/logstash/outputs/sentry.rb
97
+ - logstash-output-sentry.gemspec
98
+ - spec/outputs/sentry_spec.rb
99
+ homepage: https://github.com/javiermatos/logstash-output-sentry
100
+ licenses:
101
+ - Apache License (2.0)
102
+ metadata:
103
+ logstash_plugin: 'true'
104
+ logstash_group: output
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: This output plugin sends messages to any sentry server.
125
+ test_files:
126
+ - spec/outputs/sentry_spec.rb