elastic_notifier 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: ed027f810badc2de1a6a7dc4006bc8cfe30ff87b
4
+ data.tar.gz: d4b82848b6452585d537f0fe876dcae40e204811
5
+ SHA512:
6
+ metadata.gz: 9b796cb23416d6f95fe619450dfd744f5e4ff85c38de109e5493db278bd936cba9b658e79638af4d6ae599c434501f274de55dfdadf13a14aa0de1f20a356688
7
+ data.tar.gz: 43ad99bc00c4849bb800293c3f725c1ac1e56edda062166bfe3baeccaa99d9c58962e43903a23e02de607bdec5e4af7a24bf6dea810afa2dad5fdc22b3e545e0
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /tags
10
+ /Gemfile.lock
11
+ /*.gem
@@ -0,0 +1,14 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.16.0.pre.3
6
+ before_script:
7
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
8
+ - chmod +x ./cc-test-reporter
9
+ - ./cc-test-reporter before-build
10
+ after_script:
11
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
12
+ env:
13
+ global:
14
+ - CC_TEST_REPORTER_ID=ec4fd9d5fdb3f0b610069686575e97d79b4b3c03f3102517e6145076b5ee22d5
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the [Contributor Covenant, version 1.2.0](http://contributor-covenant.org/version/1/2/0/).
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in elastic_notifier.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Fabio Pitino
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,95 @@
1
+ # ElasticNotifier
2
+
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/92763b5c5c012431d829/maintainability)](https://codeclimate.com/github/hspazio/elastic_notifier/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/92763b5c5c012431d829/test_coverage)](https://codeclimate.com/github/hspazio/elastic_notifier/test_coverage)
5
+ [![Build Status](https://travis-ci.org/hspazio/elastic_notifier.svg?branch=master)](https://travis-ci.org/hspazio/elastic_notifier)
6
+
7
+ ElasticNotifier gem provides a simple API to send error notifications to an Elastic Search instance.
8
+
9
+ It can also be used as plug-in for [exception_notification][exception_notification] gem to send error notifications caught by the Rack middleware.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'elastic_notifier'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install elastic_notifier
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ NOTIFIER = ElasticNotifier.new(
31
+ url: "http://myserver.com:9200", # default is http://localhost:9200
32
+ index: "my_custom_index", # default is :elastic_notifier
33
+ type: "my_document_type" # default is :signals
34
+ )
35
+ ```
36
+
37
+ For __Rails__ applications you can add the code above to `config/initializers/elastic_notifier.rb` so it will be available throghout the app.
38
+
39
+ Then send error notifications as you rescue errors:
40
+
41
+ ```ruby
42
+ begin
43
+ # some code that raises an exception
44
+ rescue => error
45
+ NOTIFIER.notify_error(error)
46
+ end
47
+ ```
48
+
49
+ ## As ExceptionNotification's Plugin
50
+
51
+ If you are already using [exception_notification][exception_notification] gem within a Rails app you can use ElasticNotifier out of the box.
52
+
53
+ In `config/initializers/elastic_notifier.rb`, after initializing the notifier object as described above, you need to register it [as documented here](https://github.com/smartinez87/exception_notification#custom-notifier).
54
+
55
+ ```ruby
56
+ notifier = ElasticNotifier.new(url: "http://myserver.com:9200")
57
+ ExceptionNotifier.add_notifier :elastic_search, notifier
58
+ ```
59
+
60
+ ## What information is being sent?
61
+
62
+ At the time the notifier is invoked it collects some information from the environment, serializes it together with the exception details and sent it to the Elastic instance.
63
+
64
+ ```ruby
65
+ {
66
+ severity: "error",
67
+ timestamp: "2017-12-31 23:59:59",
68
+ program_name: "my_app.rb",
69
+ pid: 1345,
70
+ hostname: "myservicename",
71
+ ip: "123.123.123.123",
72
+ data: {
73
+ name: "NoMethodError",
74
+ message: "undefined method `test` for nil:NilClass",
75
+ backtrace: [...]
76
+ }
77
+ }
78
+
79
+ ```
80
+
81
+ It is possible to override parameters such as `program_name` which will remain static for the notifier instance.
82
+
83
+ ```ruby
84
+ notifier = ElasticNotifier.new(url: "http://myserver.com:9200", program_name: "custom_name")
85
+ ```
86
+
87
+ ## Contributing
88
+
89
+ Bug reports and pull requests are very welcome. Please be aware that you are expected to follow the [code of conduct](https://github.com/hspazio/elastic_notifier/blob/master/CODE_OF_CONDUCT.md).
90
+
91
+ ## License
92
+
93
+ Copyright (c) 2017 Fabio Pitino, released under the [MIT license](http://www.opensource.org/licenses/MIT).
94
+
95
+ [exception_notification]: https://github.com/smartinez87/exception_notification
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "elastic_notifier"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "elastic_notifier/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "elastic_notifier"
8
+ spec.version = ElasticNotifier::VERSION
9
+ spec.authors = ["Fabio Pitino"]
10
+ spec.email = ["pitinofabio@gmail.com"]
11
+
12
+ spec.summary = %q{ElasticSearch error notifier}
13
+ spec.description = %q{Send errors to ElasticSearch }
14
+ spec.homepage = "https://github.com/hspazio/elastic_notifier"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ spec.add_development_dependency "vcr", "~> 3.0"
28
+ spec.add_development_dependency "webmock", "~> 3.0"
29
+ spec.add_development_dependency "simplecov", "~> 0.15"
30
+ spec.add_dependency "elasticsearch-persistence", "~> 5.0"
31
+ spec.add_dependency "typhoeus", "~> 1.3"
32
+ end
@@ -0,0 +1,34 @@
1
+ require 'elasticsearch/persistence'
2
+ require 'typhoeus/adapters/faraday'
3
+ require 'socket'
4
+
5
+ require 'elastic_notifier/signal'
6
+ require 'elastic_notifier/error'
7
+ require 'elastic_notifier/version'
8
+
9
+ module ElasticNotifier
10
+ def self.new(options = {})
11
+ Notifier.new(options)
12
+ end
13
+
14
+ class Notifier
15
+ def initialize(options)
16
+ @repo ||= Elasticsearch::Persistence::Repository.new do
17
+ client Elasticsearch::Client.new url: options[:url]
18
+ index options.fetch(:index, :elastic_notifier)
19
+ type options.fetch(:type, :signals)
20
+ end
21
+ @options = options
22
+ end
23
+
24
+ def notify_error(exception, params = {})
25
+ overrides = {
26
+ program_name: @options[:program_name]
27
+ }
28
+ error = Error.new(exception, overrides).to_hash
29
+ @repo.save(error)
30
+ end
31
+ alias call notify_error
32
+ end
33
+ end
34
+
@@ -0,0 +1,22 @@
1
+ module ElasticNotifier
2
+ class Error < Signal
3
+ attr_reader :attributes
4
+
5
+ def initialize(error, overrides = {})
6
+ super(overrides)
7
+ @error = error
8
+ end
9
+
10
+ def severity
11
+ 'error'
12
+ end
13
+
14
+ def data
15
+ {
16
+ name: @error.class.name,
17
+ message: @error.message,
18
+ backtrace: @error.backtrace
19
+ }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ module ElasticNotifier
2
+ class Signal
3
+ attr_reader :attributes
4
+
5
+ def initialize(overrides = {})
6
+ @pid = Process.pid
7
+ @hostname = Socket.gethostname
8
+ @ip = find_ip_address
9
+ @timestamp = Time.now.strftime('%Y-%m-%dT%H:%M:%S')
10
+ @program_name = overrides[:program_name] || $PROGRAM_NAME
11
+ end
12
+
13
+ def to_hash
14
+ {
15
+ severity: severity,
16
+ timestamp: @timestamp,
17
+ program_name: @program_name,
18
+ pid: @pid,
19
+ hostname: @hostname,
20
+ ip: @ip,
21
+ data: data
22
+ }
23
+ end
24
+
25
+ def severity
26
+ raise NotImplementedError
27
+ end
28
+
29
+ def data
30
+ raise NotImplementedError
31
+ end
32
+
33
+ private
34
+
35
+ def find_ip_address
36
+ Socket.ip_address_list.find { |ip| ip.ipv4? && !ip.ipv4_loopback? }.ip_address
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module ElasticNotifier
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elastic_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fabio Pitino
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.15'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.15'
97
+ - !ruby/object:Gem::Dependency
98
+ name: elasticsearch-persistence
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: typhoeus
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.3'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.3'
125
+ description: 'Send errors to ElasticSearch '
126
+ email:
127
+ - pitinofabio@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - CODE_OF_CONDUCT.md
135
+ - Gemfile
136
+ - LICENSE
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - elastic_notifier.gemspec
142
+ - lib/elastic_notifier.rb
143
+ - lib/elastic_notifier/error.rb
144
+ - lib/elastic_notifier/signal.rb
145
+ - lib/elastic_notifier/version.rb
146
+ homepage: https://github.com/hspazio/elastic_notifier
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.5.1
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: ElasticSearch error notifier
170
+ test_files: []