logstash-output-rollbar-k8s 0.0.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
+ SHA256:
3
+ metadata.gz: 184e39991e3029bf1f93d2c922861f3dfe77db6116b2438112bbbd0b43bf2263
4
+ data.tar.gz: 9fbe8a553970d23dfe6f4ac36c0c3d46114718f31addf459aeeeba3c99f41b8c
5
+ SHA512:
6
+ metadata.gz: 2d97e202b245bbbff5115406020d0b038f4a54854ff23a88b895d691eb60982d16520c5461ccd9aca0ac765a6d7cab19b32d9b764d4a17aab102535973a1c77e
7
+ data.tar.gz: d393e761bfb0e53026849350888949c5917e4d37d311cf76ad7a4820fa16193728d3653495da16e20e51bd72ead3a484d4bfedb408e7e3907a7375d7d476bbc8
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
4
+ vendor
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
+ * Colin Surprenant (colinsurprenant)
6
+ * John E. Vincent (lusis)
7
+ * Jordan Sissel (jordansissel)
8
+ * Kurt Hurtado (kurtado)
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,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "6.4"
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012-2015 Elasticsearch <http://www.elasticsearch.org>
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/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elasticsearch/logstash) that sends events to the [Rollbar](https://www.rollbar.com) error monitoring service.
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.elasticsearch.org/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/elasticsearch/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list.
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.
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ ```sh
35
+ bundle exec rspec
36
+ ```
37
+
38
+ The Logstash code required to run the tests/specs is specified in the `Gemfile` by the line similar to:
39
+ ```ruby
40
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
41
+ ```
42
+ To test against another version or a local Logstash, edit the `Gemfile` to specify an alternative location, for example:
43
+ ```ruby
44
+ gem "logstash", :github => "elasticsearch/logstash", :ref => "master"
45
+ ```
46
+ ```ruby
47
+ gem "logstash", :path => "/your/local/logstash"
48
+ ```
49
+
50
+ Then update your dependencies and run your tests:
51
+
52
+ ```sh
53
+ bundle install
54
+ bundle exec rspec
55
+ ```
56
+
57
+ ### 2. Running your unpublished Plugin in Logstash
58
+
59
+ #### 2.1 Run in a local Logstash clone
60
+
61
+ - Edit Logstash `tools/Gemfile` and add the local plugin path, for example:
62
+ ```ruby
63
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
64
+ ```
65
+ - Update Logstash dependencies
66
+ ```sh
67
+ rake vendor:gems
68
+ ```
69
+ - Run Logstash with your plugin
70
+ ```sh
71
+ bin/logstash -e 'filter {awesome {}}'
72
+ ```
73
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
74
+
75
+ #### 2.2 Run in an installed Logstash
76
+
77
+ - Build your plugin gem
78
+ ```sh
79
+ gem build logstash-filter-awesome.gemspec
80
+ ```
81
+ - Install the plugin from the Logstash home
82
+ ```sh
83
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
84
+ ```
85
+ - Start Logstash and proceed to test the plugin
86
+
87
+ ## Contributing
88
+
89
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
90
+
91
+ 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.
92
+
93
+ It is more important to me that you are able to contribute.
94
+
95
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ @files=[]
2
+
3
+ task :default do
4
+ system("rake -T")
5
+ end
6
+
7
+ require "logstash/devutils/rake"
@@ -0,0 +1,127 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require "logstash/namespace"
4
+ require "json"
5
+
6
+ # The Rollbar output will send events to the Rollbar event monitoring service.
7
+ # The only required field is a Rollbar project access token with post_server_item
8
+ # permissions. If you're already using Rollbar to report errors directly from your
9
+ # applications, you can use the same token.
10
+ class LogStash::Outputs::Rollbar < LogStash::Outputs::Base
11
+ config_name "rollbar"
12
+
13
+ # Each of these config values can be specified in the plugin configuration section, in which
14
+ # case they'll apply to all events, or you can override them on an event by event basis.
15
+ #
16
+ # Your default Rollbar access token. You can override this for a specific event by adding
17
+ # a "[rollbar][access_token]" field to that event
18
+ config :access_token, :validate => :password, :required => true
19
+
20
+ # The default Rollbar environment. You can override this for a specific event by adding
21
+ # a "[rollbar][environment]" field to that event
22
+ config :environment, :validate => :string, :default => 'production'
23
+
24
+ # The default level for Rollbar events (info, warning, error) You can override this for a specific
25
+ # event by adding a "[rollbar][level]" field to that event
26
+ config :level, :validate => ['debug', 'info', 'warning', 'error', 'critical'] , :default => 'info'
27
+
28
+ # The default format for the Rollbar "message" or item title. In most cases you'll want to override
29
+ # this and build up a message with specific fields from the event. You can override this for a specific
30
+ # event by adding a "[rollbar][format]" field to that event.
31
+ config :format, :validate => :string, :default => "%{error}"
32
+
33
+ # Rollbar API URL endpoint. You shouldn't need to change this.
34
+ config :endpoint, :validate => :string, :default => 'https://api.rollbar.com/api/1/item/'
35
+
36
+ def hash_recursive
37
+ Hash.new do |hash, key|
38
+ hash[key] = hash_recursive
39
+ end
40
+ end
41
+
42
+ public
43
+ def register
44
+ require 'net/https'
45
+ require 'uri'
46
+ @rb_uri = URI.parse(@endpoint)
47
+ @client = Net::HTTP.new(@rb_uri.host, @rb_uri.port)
48
+ if @rb_uri.scheme == "https"
49
+ @client.use_ssl = true
50
+ @client.verify_mode = OpenSSL::SSL::VERIFY_PEER
51
+ end
52
+ end # def register
53
+
54
+ public
55
+ def receive(event)
56
+ return unless output?(event)
57
+
58
+ rb_item = hash_recursive
59
+
60
+ # We'll want to remove fields from data without removing them from the original event
61
+ data = JSON.parse(event.to_json)
62
+
63
+ #
64
+ # If logstash has created 'rollbar' fields, we'll use those to populate the item...
65
+ #
66
+ #if data['rollbar']
67
+ # merge_keys = %w{access_token client context environment fingerprint format framework
68
+ # language level person platform request server title uuid }
69
+ # merge_keys.each do |key|
70
+ # data['rollbar'][key] && rb_item['data'][key] = data['rollbar'][key]
71
+ # end
72
+ # data.delete('rollbar')
73
+ #end
74
+
75
+ # ...then put whatever's left in 'custom'...
76
+ rb_item['data']['custom'] = data
77
+
78
+ # Some optimizations for k8s and Go Projects in AVS
79
+ rb_item['data']['timestamp'] = event.timestamp.to_i
80
+ rb_item['data']['level'] = data.has_key?('level') ? data['level'] : @level
81
+ rb_item['data']['environment'] = data['kubernetes'].has_key?('namespace') ? data['kubernetes']['namespace'] : @environment
82
+ rb_item['data']['title'] = data['message']
83
+ rb_item['data']['code_version'] = data['git_commit'] if data['git_commit']
84
+
85
+ #Server data
86
+ if data['kubernetes'] && data['kubernetes']['node']
87
+ rb_item['data']['server']['host'] = data['kubernetes']['node']['name'] if data['kubernetes']['node']['name']
88
+ end
89
+
90
+ rb_item['data']['notifier']['name'] = 'logstash'
91
+ rb_item['data']['notifier']['version'] = Gem.loaded_specs["logstash-output-rollbar-k8s"].version
92
+
93
+
94
+ # Construct the message body using either:
95
+ #
96
+ # - The default format string defined above "%{message}"
97
+ # - The format string specified in the rollbar plugin config section
98
+ # - The format string specified in the [rollbar][format] event field
99
+ #
100
+ format = rb_item['data'].has_key?('format') ? rb_item['data']['format'] : @format
101
+ rb_item['data']['body']['message']['body'] = event.sprintf(format)
102
+
103
+ # Treat the [rollbar][access_token] field as a special case, since we don't need to
104
+ # include it more than once in the Rollbar item
105
+ #
106
+ if rb_item['data'].has_key?('access_token')
107
+ rb_item['access_token'] = rb_item['data']['access_token']
108
+ rb_item['data'].delete('access_token')
109
+ else
110
+ rb_item['access_token'] = @access_token.value
111
+ end
112
+
113
+
114
+ @logger.debug("Rollbar Item", :rb_item => rb_item)
115
+
116
+ begin
117
+ request = Net::HTTP::Post.new(@rb_uri.path)
118
+ request.body = JSON.dump(rb_item)
119
+ @logger.debug("Rollbar Request", :request => request.body)
120
+ response = @client.request(request)
121
+ @logger.debug("Rollbar Response", :response => response.body)
122
+
123
+ rescue Exception => e
124
+ @logger.warn("Rollbar Exception", :rb_error => e.backtrace)
125
+ end
126
+ end # def receive
127
+ end # class LogStash::Outputs::Rollbar
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-output-rollbar-k8s'
4
+ s.version = '0.0.1'
5
+ s.licenses = ['Apache-2.0']
6
+ s.summary = "The Rollbar Logstash output sends events to the Rollbar error monitoring service."
7
+ s.description = "This gem is a logstash plugin. Install using: $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
8
+ s.authors = ["Maxim Pogozhiy"]
9
+ s.email = 'foxdalas@gmail.com'
10
+ s.homepage = "https://github.com/foxdalas/logstash-output-rollbar"
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*')
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', '>= 1.4.0', '< 7.0.0'
24
+
25
+ s.add_development_dependency 'logstash-devutils'
26
+ end
27
+
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-rollbar-k8s
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Maxim Pogozhiy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-05 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: 1.4.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 7.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: 1.4.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 7.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-devutils
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: 'This gem is a logstash plugin. Install using: $LS_HOME/bin/plugin install
48
+ gemname. This gem is not a stand-alone program'
49
+ email: foxdalas@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - ".gitignore"
55
+ - CONTRIBUTORS
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - lib/logstash/outputs/rollbar.rb
61
+ - logstash-output-rollbar-k8s.gemspec
62
+ - spec/outputs/rollbar_spec.rb
63
+ homepage: https://github.com/foxdalas/logstash-output-rollbar
64
+ licenses:
65
+ - Apache-2.0
66
+ metadata:
67
+ logstash_plugin: 'true'
68
+ logstash_group: output
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.7.7
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: The Rollbar Logstash output sends events to the Rollbar error monitoring
89
+ service.
90
+ test_files:
91
+ - spec/outputs/rollbar_spec.rb