graylog2_exceptions 0.5.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/README +1 -0
- data/Rakefile +39 -8
- data/VERSION +1 -0
- data/lib/graylog2_exceptions.rb +20 -13
- data/test/helper.rb +6 -0
- data/test/test_graylog2_exceptions.rb +86 -0
- metadata +22 -24
- data/Manifest +0 -4
- data/graylog2_exceptions.gemspec +0 -33
data/.gitignore
ADDED
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
See http://www.graylog2.org/ for more information. Use gem as installation source. This is just the development repository.
|
data/Rakefile
CHANGED
@@ -1,11 +1,42 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
|
4
|
+
task :default => :test
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |gem|
|
9
|
+
gem.name = "graylog2_exceptions"
|
10
|
+
gem.summary = 'Graylog2 exception notifier'
|
11
|
+
gem.description = 'A Rack middleware that sends every Exception as GELF message to your Graylog2 server'
|
12
|
+
gem.email = "lennart@socketfeed.com"
|
13
|
+
gem.homepage = "http://www.graylog2.org/"
|
14
|
+
gem.authors = "Lennart Koopmann"
|
15
|
+
gem.add_dependency "gelf", "= 1.0.0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.rcov_opts << '--exclude gem'
|
36
|
+
test.verbose = true
|
37
|
+
end
|
38
|
+
rescue LoadError
|
39
|
+
task :rcov do
|
40
|
+
abort "RCov is not available. In order to run rcov, you must: gem install rcov"
|
41
|
+
end
|
11
42
|
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/lib/graylog2_exceptions.rb
CHANGED
@@ -3,11 +3,17 @@ require 'gelf'
|
|
3
3
|
require 'socket'
|
4
4
|
|
5
5
|
class Graylog2Exceptions
|
6
|
-
|
7
|
-
@gl2_hostname = options[:host] || "localhost"
|
8
|
-
@gl2_port = options[:port] || 12201
|
9
|
-
@local_app_name = options[:local_app_name] || Socket::gethostname
|
6
|
+
attr_reader :args
|
10
7
|
|
8
|
+
def initialize(app, args = {})
|
9
|
+
standard_args = {
|
10
|
+
:hostname => "localhost",
|
11
|
+
:port => 12201,
|
12
|
+
:local_app_name => Socket::gethostname,
|
13
|
+
:level => 3
|
14
|
+
}
|
15
|
+
|
16
|
+
@args = standard_args.merge(args)
|
11
17
|
@app = app
|
12
18
|
end
|
13
19
|
|
@@ -20,7 +26,7 @@ class Graylog2Exceptions
|
|
20
26
|
begin
|
21
27
|
# Call the app we are monitoring
|
22
28
|
@app.call(env)
|
23
|
-
rescue
|
29
|
+
rescue => err
|
24
30
|
# An exception has been raised. Send to Graylog2!
|
25
31
|
send_to_graylog2(err)
|
26
32
|
|
@@ -31,14 +37,15 @@ class Graylog2Exceptions
|
|
31
37
|
|
32
38
|
def send_to_graylog2 err
|
33
39
|
begin
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
notifier = GELF::Notifier.new(@args[:hostname], @args[:port])
|
41
|
+
notifier.notify!(
|
42
|
+
:short_message => err.message,
|
43
|
+
:full_message => err.backtrace.join("\n"),
|
44
|
+
:level => @args[:level],
|
45
|
+
:host => @args[:local_app_name],
|
46
|
+
:file => err.backtrace[0].split(":")[0],
|
47
|
+
:line => err.backtrace[0].split(":")[1]
|
48
|
+
)
|
42
49
|
rescue => i_err
|
43
50
|
puts "Graylog2 Exception logger. Could not send message: " + i_err.message
|
44
51
|
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestGraylog2Exceptions < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# Exceptions raised in the app should be thrown back
|
6
|
+
# to the app after handling. Simulating this by giving
|
7
|
+
# a nil app and expecting the caused exceptions.
|
8
|
+
def test_should_rethrow_exception
|
9
|
+
c = Graylog2Exceptions.new(nil, {})
|
10
|
+
assert_raise NoMethodError do
|
11
|
+
c.call nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_correct_parameters_when_custom_set
|
16
|
+
c = Graylog2Exceptions.new(nil, {:host => "localhost", :port => 1337, :local_app_name => "yomama", :level => 1})
|
17
|
+
|
18
|
+
assert_equal "yomama", c.args[:local_app_name]
|
19
|
+
assert_equal "localhost", c.args[:hostname]
|
20
|
+
assert_equal 1337, c.args[:port]
|
21
|
+
assert_equal 1, c.args[:level]
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_correct_parameters_when_not_custom_set
|
25
|
+
c = Graylog2Exceptions.new(nil, {})
|
26
|
+
|
27
|
+
assert_equal Socket.gethostname, c.args[:local_app_name]
|
28
|
+
assert_equal "localhost", c.args[:hostname]
|
29
|
+
assert_equal 12201, c.args[:port]
|
30
|
+
assert_equal 3, c.args[:level]
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_send_exception_to_graylog2_without_custom_parameters
|
34
|
+
ex = build_exception
|
35
|
+
|
36
|
+
c = Graylog2Exceptions.new(nil, {})
|
37
|
+
sent = Zlib::Inflate.inflate(c.send_to_graylog2(ex).join)
|
38
|
+
json = JSON.parse(sent)
|
39
|
+
|
40
|
+
assert json["short_message"].include?('undefined method `klopfer!')
|
41
|
+
assert json["full_message"].include?('in `build_exception')
|
42
|
+
assert_equal 3, json["level"]
|
43
|
+
assert_equal Socket.gethostname, json["host"]
|
44
|
+
assert_equal ex.backtrace[0].split(":")[1], json["line"]
|
45
|
+
assert_equal ex.backtrace[0].split(":")[0], json["file"]
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_send_exception_to_graylog2_with_custom_parameters
|
49
|
+
ex = build_exception
|
50
|
+
|
51
|
+
c = Graylog2Exceptions.new(nil, {:local_app_name => "machinexx", :level => 1})
|
52
|
+
sent = Zlib::Inflate.inflate(c.send_to_graylog2(ex).join)
|
53
|
+
json = JSON.parse(sent)
|
54
|
+
|
55
|
+
assert json["short_message"].include?('undefined method `klopfer!')
|
56
|
+
assert json["full_message"].include?('in `build_exception')
|
57
|
+
assert_equal 1, json["level"]
|
58
|
+
assert_equal "machinexx", json["host"]
|
59
|
+
assert_equal ex.backtrace[0].split(":")[1], json["line"]
|
60
|
+
assert_equal ex.backtrace[0].split(":")[0], json["file"]
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_invalid_port_detection
|
64
|
+
ex = build_exception
|
65
|
+
|
66
|
+
c = Graylog2Exceptions.new(nil, {:port => 0})
|
67
|
+
|
68
|
+
# send_to_graylog2 returns nil when nothing was sent
|
69
|
+
# the test is fine when the message is just not sent
|
70
|
+
# and there are no exceptions. the method informs
|
71
|
+
# the user via puts
|
72
|
+
assert_nil c.send_to_graylog2(ex)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# Returns a self-caused exception we can send.
|
78
|
+
def build_exception
|
79
|
+
begin
|
80
|
+
klopfer!
|
81
|
+
rescue => e
|
82
|
+
return e
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graylog2_exceptions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 13
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
6
|
+
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.5.3
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Lennart Koopmann
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-11-19 00:00:00 +01:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -24,12 +23,13 @@ dependencies:
|
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
27
|
-
- - "
|
26
|
+
- - "="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
31
|
- 0
|
32
|
-
version:
|
32
|
+
version: 1.0.0
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
description: A Rack middleware that sends every Exception as GELF message to your Graylog2 server
|
@@ -39,22 +39,22 @@ executables: []
|
|
39
39
|
extensions: []
|
40
40
|
|
41
41
|
extra_rdoc_files:
|
42
|
-
-
|
42
|
+
- README
|
43
43
|
files:
|
44
|
-
-
|
44
|
+
- .gitignore
|
45
|
+
- README
|
45
46
|
- Rakefile
|
46
|
-
-
|
47
|
+
- VERSION
|
47
48
|
- lib/graylog2_exceptions.rb
|
49
|
+
- test/helper.rb
|
50
|
+
- test/test_graylog2_exceptions.rb
|
48
51
|
has_rdoc: true
|
49
52
|
homepage: http://www.graylog2.org/
|
50
53
|
licenses: []
|
51
54
|
|
52
55
|
post_install_message:
|
53
56
|
rdoc_options:
|
54
|
-
- --
|
55
|
-
- --inline-source
|
56
|
-
- --title
|
57
|
-
- Graylog2_exceptions
|
57
|
+
- --charset=UTF-8
|
58
58
|
require_paths:
|
59
59
|
- lib
|
60
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -62,7 +62,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
62
|
requirements:
|
63
63
|
- - ">="
|
64
64
|
- !ruby/object:Gem::Version
|
65
|
-
hash: 3
|
66
65
|
segments:
|
67
66
|
- 0
|
68
67
|
version: "0"
|
@@ -71,17 +70,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
70
|
requirements:
|
72
71
|
- - ">="
|
73
72
|
- !ruby/object:Gem::Version
|
74
|
-
hash: 11
|
75
73
|
segments:
|
76
|
-
-
|
77
|
-
|
78
|
-
version: "1.2"
|
74
|
+
- 0
|
75
|
+
version: "0"
|
79
76
|
requirements: []
|
80
77
|
|
81
|
-
rubyforge_project:
|
78
|
+
rubyforge_project:
|
82
79
|
rubygems_version: 1.3.7
|
83
80
|
signing_key:
|
84
81
|
specification_version: 3
|
85
|
-
summary:
|
86
|
-
test_files:
|
87
|
-
|
82
|
+
summary: Graylog2 exception notifier
|
83
|
+
test_files:
|
84
|
+
- test/helper.rb
|
85
|
+
- test/test_graylog2_exceptions.rb
|
data/Manifest
DELETED
data/graylog2_exceptions.gemspec
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{graylog2_exceptions}
|
5
|
-
s.version = "0.5.3"
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Lennart Koopmann"]
|
9
|
-
s.date = %q{2010-10-08}
|
10
|
-
s.description = %q{A Rack middleware that sends every Exception as GELF message to your Graylog2 server}
|
11
|
-
s.email = %q{lennart@socketfeed.com}
|
12
|
-
s.extra_rdoc_files = ["lib/graylog2_exceptions.rb"]
|
13
|
-
s.files = ["Manifest", "Rakefile", "graylog2_exceptions.gemspec", "lib/graylog2_exceptions.rb"]
|
14
|
-
s.homepage = %q{http://www.graylog2.org/}
|
15
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Graylog2_exceptions"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{graylog2_exceptions}
|
18
|
-
s.rubygems_version = %q{1.3.7}
|
19
|
-
s.summary = %q{A Rack middleware that sends every Exception as GELF message to your Graylog2 server}
|
20
|
-
|
21
|
-
if s.respond_to? :specification_version then
|
22
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
-
s.specification_version = 3
|
24
|
-
|
25
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
s.add_runtime_dependency(%q<gelf>, [">= 0"])
|
27
|
-
else
|
28
|
-
s.add_dependency(%q<gelf>, [">= 0"])
|
29
|
-
end
|
30
|
-
else
|
31
|
-
s.add_dependency(%q<gelf>, [">= 0"])
|
32
|
-
end
|
33
|
-
end
|