axial_notifier 0.1.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/.document +5 -0
- data/.gitignore +21 -0
- data/README.md +35 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/lib/axial_notifier.rb +26 -0
- data/lib/axial_notifier/catcher.rb +10 -0
- data/lib/axial_notifier/configuration.rb +5 -0
- data/lib/axial_notifier/sender.rb +25 -0
- data/rails/init.rb +2 -0
- data/test/axial_notifier/catcher_test.rb +25 -0
- data/test/axial_notifier/configuration_test.rb +11 -0
- data/test/axial_notifier/sender_test.rb +47 -0
- data/test/axial_notifier_test.rb +26 -0
- data/test/helper.rb +11 -0
- metadata +102 -0
data/.document
ADDED
data/.gitignore
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# axial_notifier
|
|
2
|
+
|
|
3
|
+
Send exception notifications to the axially.net service.
|
|
4
|
+
|
|
5
|
+
# Usage
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
`config.gem axial_notifier` in Rails
|
|
10
|
+
|
|
11
|
+
OR
|
|
12
|
+
|
|
13
|
+
`gem axial_notifier` with Bundler
|
|
14
|
+
|
|
15
|
+
## Configure
|
|
16
|
+
|
|
17
|
+
We use the syslog service already running on your system. We will configure it to send messages
|
|
18
|
+
from the local7 facility. Edit /etc/syslog.conf (or your system's syslog configuration) adding:
|
|
19
|
+
|
|
20
|
+
`local7.* @axially.net:5140`
|
|
21
|
+
|
|
22
|
+
In your environment configure your api\_key:
|
|
23
|
+
|
|
24
|
+
<pre><code>
|
|
25
|
+
AxialNotifier.configure do |config|
|
|
26
|
+
config.api_key = 'abcdefg12345'
|
|
27
|
+
config.environment = 'production'
|
|
28
|
+
end
|
|
29
|
+
</code></pre>
|
|
30
|
+
|
|
31
|
+
If you do not set the environment you would like, we default to 'development'.
|
|
32
|
+
|
|
33
|
+
# Copyright
|
|
34
|
+
|
|
35
|
+
Copyright (c) 2009 [Tony Pitale](mailto:tony.pitale@viget.com) released under the MIT license
|
data/Rakefile
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "axial_notifier"
|
|
8
|
+
gem.summary = %Q{Send Rails exception to the Axial Service via Syslog}
|
|
9
|
+
gem.description = %Q{Send Rails exception to the Axial Service via Syslog}
|
|
10
|
+
gem.email = "tpitale@gmail.com"
|
|
11
|
+
gem.homepage = "http://github.com/tpitale/axial_notifier"
|
|
12
|
+
gem.authors = ["tpitale"]
|
|
13
|
+
gem.add_dependency "json", ">= 1.2.0"
|
|
14
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
|
15
|
+
gem.add_development_dependency "jferris-mocha", ">= 0.9.7"
|
|
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.verbose = true
|
|
36
|
+
end
|
|
37
|
+
rescue LoadError
|
|
38
|
+
task :rcov do
|
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
task :test => :check_dependencies
|
|
44
|
+
|
|
45
|
+
task :default => :test
|
|
46
|
+
|
|
47
|
+
require 'rake/rdoctask'
|
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
50
|
+
|
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
52
|
+
rdoc.title = "axial_notifier #{version}"
|
|
53
|
+
rdoc.rdoc_files.include('README*')
|
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
55
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'syslog'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'axial_notifier/sender'
|
|
4
|
+
require 'axial_notifier/catcher'
|
|
5
|
+
require 'axial_notifier/configuration'
|
|
6
|
+
|
|
7
|
+
module AxialNotifier
|
|
8
|
+
extend self
|
|
9
|
+
|
|
10
|
+
attr_accessor :configuration, :sender
|
|
11
|
+
|
|
12
|
+
def configure
|
|
13
|
+
yield(self.configuration ||= Configuration.new)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def log(exception)
|
|
17
|
+
self.sender ||= Sender.new(self.configuration)
|
|
18
|
+
self.sender.log(exception)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
AxialNotifier.configure do |config|
|
|
23
|
+
config.api_key = ''
|
|
24
|
+
config.environment = 'development'
|
|
25
|
+
config.facility = Syslog::LOG_LOCAL7
|
|
26
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module AxialNotifier
|
|
2
|
+
class Sender
|
|
3
|
+
def initialize(configuration)
|
|
4
|
+
@config = configuration
|
|
5
|
+
@syslog = Syslog.open(@config.api_key, nil, @config.facility)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def log(exception)
|
|
9
|
+
@syslog.err parse(exception)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def parse(exception)
|
|
13
|
+
if exception.is_a?(String)
|
|
14
|
+
{:message => exception}.to_json
|
|
15
|
+
else
|
|
16
|
+
{
|
|
17
|
+
:environment => (@config.environment),
|
|
18
|
+
:exception => exception.class,
|
|
19
|
+
:message => exception.message,
|
|
20
|
+
:backtrace => exception.backtrace.join('\n')
|
|
21
|
+
}.to_json
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/rails/init.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'helper')
|
|
2
|
+
|
|
3
|
+
module SuperLog
|
|
4
|
+
def log_error(exception)
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class CatcherMixer
|
|
9
|
+
include SuperLog
|
|
10
|
+
include AxialNotifier::Catcher
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module AxialNotifier
|
|
14
|
+
class CatcherTest < Test::Unit::TestCase
|
|
15
|
+
context "A class with the Catcher module mixed in" do
|
|
16
|
+
should "log exceptions to Axial" do
|
|
17
|
+
AxialNotifier.stubs(:log)
|
|
18
|
+
|
|
19
|
+
CatcherMixer.new.log_error("exception")
|
|
20
|
+
|
|
21
|
+
assert_received(AxialNotifier, :log) {|e| e.with("exception")}
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'helper')
|
|
2
|
+
|
|
3
|
+
module AxialNotifier
|
|
4
|
+
class SenderTest < Test::Unit::TestCase
|
|
5
|
+
context "A Sender" do
|
|
6
|
+
setup do
|
|
7
|
+
@syslog = stub
|
|
8
|
+
Syslog.stubs(:open).returns(@syslog)
|
|
9
|
+
|
|
10
|
+
@config = stub(:api_key => '1234', :facility => 'local7')
|
|
11
|
+
|
|
12
|
+
@sender = Sender.new(@config)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
should "parse strings" do
|
|
16
|
+
assert_equal '{"message":"volleyball"}', @sender.parse('volleyball')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
should "parse exceptions" do
|
|
20
|
+
exception = stub
|
|
21
|
+
exception.stubs(:class).returns(StandardError)
|
|
22
|
+
exception.stubs(:message).returns("panthers")
|
|
23
|
+
exception.stubs(:backtrace).returns(["abcdefg","12345"])
|
|
24
|
+
@config.stubs(:environment).returns('development')
|
|
25
|
+
|
|
26
|
+
Hash.any_instance.stubs(:to_json)
|
|
27
|
+
|
|
28
|
+
@sender.parse(exception)
|
|
29
|
+
|
|
30
|
+
assert_received(exception, :class)
|
|
31
|
+
assert_received(exception, :message)
|
|
32
|
+
assert_received(exception, :backtrace)
|
|
33
|
+
assert_received(@config, :environment)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
should "log with syslog" do
|
|
37
|
+
@syslog.stubs(:err)
|
|
38
|
+
@sender.stubs(:parse).returns("message to log")
|
|
39
|
+
|
|
40
|
+
@sender.log("something")
|
|
41
|
+
|
|
42
|
+
assert_received(@sender, :parse) {|e| e.with("something")}
|
|
43
|
+
assert_received(@syslog, :err) {|e| e.with("message to log")}
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'helper')
|
|
2
|
+
|
|
3
|
+
class AxialNotifierTest < Test::Unit::TestCase
|
|
4
|
+
context "The AxialNotifier Module" do
|
|
5
|
+
setup do
|
|
6
|
+
@config = stub
|
|
7
|
+
AxialNotifier.configuration = @config
|
|
8
|
+
@sender = stub
|
|
9
|
+
AxialNotifier.sender = @sender
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
should "log to Sender" do
|
|
13
|
+
@sender.stubs(:log)
|
|
14
|
+
|
|
15
|
+
AxialNotifier.log("exception")
|
|
16
|
+
|
|
17
|
+
assert_received(@sender, :log) {|e| e.with("exception")}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
should "yield its a configuration" do
|
|
21
|
+
AxialNotifier.configure do |config|
|
|
22
|
+
assert_equal @config, config
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/test/helper.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'shoulda'
|
|
4
|
+
require 'mocha'
|
|
5
|
+
|
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
8
|
+
require 'axial_notifier'
|
|
9
|
+
|
|
10
|
+
class Test::Unit::TestCase
|
|
11
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: axial_notifier
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- tpitale
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-12-21 00:00:00 -05:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: json
|
|
17
|
+
type: :runtime
|
|
18
|
+
version_requirement:
|
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: 1.2.0
|
|
24
|
+
version:
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: thoughtbot-shoulda
|
|
27
|
+
type: :development
|
|
28
|
+
version_requirement:
|
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: "0"
|
|
34
|
+
version:
|
|
35
|
+
- !ruby/object:Gem::Dependency
|
|
36
|
+
name: jferris-mocha
|
|
37
|
+
type: :development
|
|
38
|
+
version_requirement:
|
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 0.9.7
|
|
44
|
+
version:
|
|
45
|
+
description: Send Rails exception to the Axial Service via Syslog
|
|
46
|
+
email: tpitale@gmail.com
|
|
47
|
+
executables: []
|
|
48
|
+
|
|
49
|
+
extensions: []
|
|
50
|
+
|
|
51
|
+
extra_rdoc_files:
|
|
52
|
+
- README.md
|
|
53
|
+
files:
|
|
54
|
+
- .document
|
|
55
|
+
- .gitignore
|
|
56
|
+
- README.md
|
|
57
|
+
- Rakefile
|
|
58
|
+
- VERSION
|
|
59
|
+
- lib/axial_notifier.rb
|
|
60
|
+
- lib/axial_notifier/catcher.rb
|
|
61
|
+
- lib/axial_notifier/configuration.rb
|
|
62
|
+
- lib/axial_notifier/sender.rb
|
|
63
|
+
- rails/init.rb
|
|
64
|
+
- test/axial_notifier/catcher_test.rb
|
|
65
|
+
- test/axial_notifier/configuration_test.rb
|
|
66
|
+
- test/axial_notifier/sender_test.rb
|
|
67
|
+
- test/axial_notifier_test.rb
|
|
68
|
+
- test/helper.rb
|
|
69
|
+
has_rdoc: true
|
|
70
|
+
homepage: http://github.com/tpitale/axial_notifier
|
|
71
|
+
licenses: []
|
|
72
|
+
|
|
73
|
+
post_install_message:
|
|
74
|
+
rdoc_options:
|
|
75
|
+
- --charset=UTF-8
|
|
76
|
+
require_paths:
|
|
77
|
+
- lib
|
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: "0"
|
|
83
|
+
version:
|
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: "0"
|
|
89
|
+
version:
|
|
90
|
+
requirements: []
|
|
91
|
+
|
|
92
|
+
rubyforge_project:
|
|
93
|
+
rubygems_version: 1.3.5
|
|
94
|
+
signing_key:
|
|
95
|
+
specification_version: 3
|
|
96
|
+
summary: Send Rails exception to the Axial Service via Syslog
|
|
97
|
+
test_files:
|
|
98
|
+
- test/axial_notifier/catcher_test.rb
|
|
99
|
+
- test/axial_notifier/configuration_test.rb
|
|
100
|
+
- test/axial_notifier/sender_test.rb
|
|
101
|
+
- test/axial_notifier_test.rb
|
|
102
|
+
- test/helper.rb
|