ramon 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ramon.rb +58 -15
- data/lib/ramon/catcher.rb +18 -18
- data/lib/ramon/configuration.rb +63 -0
- data/lib/ramon/controller_exception_data.rb +49 -49
- data/lib/ramon/enviroment_data.rb +28 -28
- data/lib/ramon/exception_data.rb +97 -97
- data/lib/ramon/railtie.rb +13 -2
- data/lib/ramon/sender.rb +65 -0
- data/lib/ramon/version.rb +1 -1
- data/spec/config_spec.rb +13 -0
- data/spec/{logger_spec.rb → log_spec.rb} +8 -8
- data/spec/web_spec.rb +23 -15
- metadata +8 -10
- data/lib/ramon/config.rb +0 -48
- data/lib/ramon/log_factory.rb +0 -46
- data/lib/ramon/remote.rb +0 -35
- data/spec/remote_spec.rb +0 -0
data/lib/ramon.rb
CHANGED
@@ -1,28 +1,71 @@
|
|
1
1
|
def require_local(file)
|
2
|
-
|
2
|
+
require File.join(File.dirname(__FILE__), "ramon", file)
|
3
3
|
end
|
4
4
|
|
5
|
-
require_local
|
6
|
-
require_local
|
7
|
-
require_local
|
8
|
-
require_local
|
5
|
+
require_local "version"
|
6
|
+
require_local "sender"
|
7
|
+
require_local "configuration"
|
8
|
+
require_local "catcher"
|
9
9
|
require_local "exception_data"
|
10
10
|
require_local "controller_exception_data"
|
11
11
|
require_local "enviroment_data"
|
12
12
|
|
13
|
-
require_local
|
14
|
-
require_local
|
13
|
+
require_local "integration/rails" if defined?(Rails)
|
14
|
+
require_local "railtie" if defined?(Rails)
|
15
15
|
|
16
16
|
module Ramon
|
17
17
|
|
18
|
-
|
19
|
-
log_hash = Log.log(message, tags)
|
20
|
-
Remote.post('log', log_hash)
|
21
|
-
end
|
18
|
+
class << self
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
20
|
+
# The sender object is responsible for delivering formatted data to the Amon server.
|
21
|
+
attr_accessor :sender
|
26
22
|
|
27
|
-
|
23
|
+
# Ramon configuration object. Must act like a hash and return sensible
|
24
|
+
# values for all configuration options.
|
25
|
+
attr_writer :configuration
|
26
|
+
|
27
|
+
# Call this method to modify defaults in your initializers.
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# Ramon.configure do |config|
|
31
|
+
# config.app_key = '1234567890abcdef'
|
32
|
+
# config.host = 'http://127.0.0.1'
|
33
|
+
# config.port = 2464
|
34
|
+
# end
|
35
|
+
def configure()
|
36
|
+
yield(configuration)
|
37
|
+
self.sender = Sender.new(configuration)
|
38
|
+
self.sender
|
39
|
+
end
|
40
|
+
|
41
|
+
# The configuration object.
|
42
|
+
# @see Ramon.configure
|
43
|
+
def configuration
|
44
|
+
@configuration ||= Configuration.new
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# Look for the Rails logger currently defined
|
49
|
+
def logger
|
50
|
+
self.configuration.logger
|
51
|
+
end
|
52
|
+
|
53
|
+
def format_log(message, tags=nil)
|
54
|
+
tags ||= 'notset'
|
55
|
+
log = {"message" => message, "tags" => tags}
|
56
|
+
log
|
57
|
+
end
|
58
|
+
|
59
|
+
def log(message, tags=nil)
|
60
|
+
log = format_log(message, tags)
|
61
|
+
sender.post('log', log)
|
62
|
+
end
|
63
|
+
|
64
|
+
def post(type, data)
|
65
|
+
sender.post(type, data)
|
66
|
+
end
|
67
|
+
|
68
|
+
end # self end
|
69
|
+
|
70
|
+
end # module end
|
28
71
|
|
data/lib/ramon/catcher.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
module Ramon
|
2
|
-
class Catcher
|
3
|
-
|
4
|
-
|
5
|
-
def handle_with_controller(exception, controller=nil, request=nil)
|
6
|
-
data = ControllerExceptionData.new(exception, controller, request)
|
7
|
-
Ramon.post('exception', data)
|
8
|
-
end
|
9
|
-
|
10
|
-
def handle_with_rack(exception, environment, request)
|
11
|
-
data = RackExceptionData.new(exception, environment, request)
|
12
|
-
Ramon.post('exception', data)
|
13
|
-
end
|
2
|
+
class Catcher
|
3
|
+
class << self
|
14
4
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
5
|
+
def handle_with_controller(exception, controller=nil, request=nil)
|
6
|
+
data = ControllerExceptionData.new(exception, controller, request)
|
7
|
+
Ramon.post('exception', data)
|
8
|
+
end
|
19
9
|
|
20
|
-
|
21
|
-
|
10
|
+
def handle_with_rack(exception, environment, request)
|
11
|
+
data = RackExceptionData.new(exception, environment, request)
|
12
|
+
Ramon.post('exception', data)
|
13
|
+
end
|
14
|
+
|
15
|
+
def handle(exception, name=nil)
|
16
|
+
data = ExceptionData.new(exception, name)
|
17
|
+
Ramon.post('exception', data)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end # class end
|
22
22
|
end # module end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Ramon
|
2
|
+
class Configuration
|
3
|
+
class ConfigurationException < StandardError; end
|
4
|
+
OPTIONS = [:app_key, :host, :port, :secret,
|
5
|
+
:environment_name, :framework, :project_root].freeze
|
6
|
+
|
7
|
+
# The Aplication key. Only in Amon Plus.
|
8
|
+
attr_accessor :app_key
|
9
|
+
|
10
|
+
# Secret key, used for securely logging in the normal Amon version
|
11
|
+
attr_accessor :secret
|
12
|
+
|
13
|
+
# The host to connect to (defaults to 127.0.0.1).
|
14
|
+
attr_accessor :host
|
15
|
+
|
16
|
+
# The port on which your Amon instance runs. Defaults to 2464
|
17
|
+
attr_accessor :port
|
18
|
+
|
19
|
+
# The name of the environment the application is running in
|
20
|
+
attr_accessor :environment_name
|
21
|
+
|
22
|
+
# The path to the project in which the error occurred, such as the RAILS_ROOT
|
23
|
+
attr_accessor :project_root
|
24
|
+
|
25
|
+
# The framework Ramon is configured to use
|
26
|
+
attr_accessor :framework
|
27
|
+
|
28
|
+
# The logger used by Amon
|
29
|
+
attr_accessor :logger
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
@host = 'http://127.0.0.1'
|
33
|
+
@port = 2464
|
34
|
+
@app_key = ''
|
35
|
+
@secret = ''
|
36
|
+
@framework = 'Standalone'
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Allows config options to be read like a hash
|
41
|
+
#
|
42
|
+
# @param [Symbol] option Key for a given attribute
|
43
|
+
def [](option)
|
44
|
+
send(option)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns a hash of all configurable options
|
48
|
+
def to_hash
|
49
|
+
OPTIONS.inject({}) do |hash, option|
|
50
|
+
hash.merge(option.to_sym => send(option))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns a hash of all configurable options merged with +hash+
|
55
|
+
#
|
56
|
+
# @param [Hash] hash A set of configuration options that will take precedence over the defaults
|
57
|
+
def merge(hash)
|
58
|
+
to_hash.merge(hash)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end # Class end
|
63
|
+
end # Module end
|
@@ -1,59 +1,59 @@
|
|
1
1
|
require 'digest/md5'
|
2
2
|
|
3
3
|
module Ramon
|
4
|
-
class ControllerExceptionData < ExceptionData
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
class ControllerExceptionData < ExceptionData
|
5
|
+
def initialize(exception, controller=nil, request=nil)
|
6
|
+
super(exception)
|
7
|
+
@request = request
|
8
|
+
@controller = controller
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def framework
|
12
|
+
"rails"
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
def additional_data
|
16
|
+
return {} if @request.nil?
|
17
|
+
{
|
18
|
+
'request' => {
|
19
|
+
'url' => (@request.respond_to?(:url) ? @request.url : "#{@request.protocol}#{@request.host}#{@request.request_uri}"),
|
20
|
+
'controller' => @controller.class.to_s,
|
21
|
+
'action' => (@request.respond_to?(:parameters) ? @request.parameters['action'] : @request.params['action']),
|
22
|
+
'parameters' => filter_paramaters(@request.respond_to?(:parameters) ? @request.parameters : @request.params),
|
23
|
+
'request_method' => @request.request_method.to_s,
|
24
|
+
'remote_ip' => (@request.respond_to?(:remote_ip) ? @request.remote_ip : @request.ip),
|
25
|
+
#'headers' => extract_http_headers(@request.env),
|
26
|
+
'session' => self.class.sanitize_session(@request)
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
31
|
+
def filter_hash(keys_to_filter, hash)
|
32
|
+
if keys_to_filter.is_a?(Array) && !keys_to_filter.empty?
|
33
|
+
hash.each do |key, value|
|
34
|
+
if value.respond_to?(:to_hash)
|
35
|
+
filter_hash(keys_to_filter, hash[key])
|
36
|
+
elsif key_match?(key, keys_to_filter)
|
37
|
+
hash[key] = "[FILTERED]"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
hash
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
def key_match?(key, keys_to_filter)
|
45
|
+
keys_to_filter.map {|k| k.to_s}.include?(key.to_s)
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
def filter_paramaters(hash)
|
49
|
+
if @request.respond_to?(:env) && @request.env["action_dispatch.parameter_filter"]
|
50
|
+
filter_hash(@request.env["action_dispatch.parameter_filter"], hash)
|
51
|
+
elsif @controller.respond_to?(:filter_parameters)
|
52
|
+
@controller.send(:filter_parameters, hash)
|
53
|
+
else
|
54
|
+
hash
|
55
|
+
end
|
56
|
+
end
|
57
57
|
|
58
|
-
end # class end
|
58
|
+
end # class end
|
59
59
|
end # module end
|
@@ -1,37 +1,37 @@
|
|
1
1
|
require 'digest/md5'
|
2
2
|
|
3
3
|
module Ramon
|
4
|
-
class ApplicationEnvironment
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
class ApplicationEnvironment
|
5
|
+
def self.to_hash(framework)
|
6
|
+
{
|
7
|
+
'language' => 'ruby',
|
8
|
+
'language_version' => language_version_string,
|
9
|
+
'framework' => framework,
|
10
|
+
#'libraries_loaded' => libraries_loaded
|
11
|
+
}
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
def self.get_hostname
|
16
|
-
require 'socket' unless defined?(Socket)
|
17
|
-
Socket.gethostname
|
18
|
-
rescue
|
19
|
-
'UNKNOWN'
|
20
|
-
end
|
21
14
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
15
|
+
def self.get_hostname
|
16
|
+
require 'socket' unless defined?(Socket)
|
17
|
+
Socket.gethostname
|
18
|
+
rescue
|
19
|
+
'UNKNOWN'
|
20
|
+
end
|
26
21
|
|
22
|
+
def self.language_version_string
|
23
|
+
"#{RUBY_VERSION rescue '?.?.?'} p#{RUBY_PATCHLEVEL rescue '???'}
|
24
|
+
#{RUBY_RELEASE_DATE rescue '????-??-??'} #{RUBY_PLATFORM rescue '????'}"
|
25
|
+
end
|
27
26
|
|
28
|
-
def self.libraries_loaded
|
29
|
-
begin
|
30
|
-
return Hash[*Gem.loaded_specs.map{|name, gem_specification| [name, gem_specification.version.to_s]}.flatten]
|
31
|
-
rescue
|
32
|
-
end
|
33
|
-
{}
|
34
|
-
end
|
35
27
|
|
36
|
-
|
28
|
+
def self.libraries_loaded
|
29
|
+
begin
|
30
|
+
return Hash[*Gem.loaded_specs.map{|name, gem_specification| [name, gem_specification.version.to_s]}.flatten]
|
31
|
+
rescue
|
32
|
+
end
|
33
|
+
{}
|
34
|
+
end
|
35
|
+
|
36
|
+
end # class end
|
37
37
|
end # module end
|
data/lib/ramon/exception_data.rb
CHANGED
@@ -1,99 +1,99 @@
|
|
1
1
|
module Ramon
|
2
|
-
class ExceptionData
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end # class end
|
2
|
+
class ExceptionData
|
3
|
+
|
4
|
+
def initialize(exception, name=nil)
|
5
|
+
@exception = exception
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_hash
|
10
|
+
hash = {}
|
11
|
+
# We need the url before the main exception info
|
12
|
+
hash['data'] = additional_data
|
13
|
+
|
14
|
+
hash.merge!({
|
15
|
+
'exception_class' => @exception.class.to_s,
|
16
|
+
'message' => @exception.message,
|
17
|
+
'backtrace' => @exception.backtrace,
|
18
|
+
'url' => hash['data']['request']['url']
|
19
|
+
})
|
20
|
+
|
21
|
+
hash['data'].merge!(ApplicationEnvironment.to_hash(framework))
|
22
|
+
hash['data'].merge!(context_stuff)
|
23
|
+
hash['data'].merge!(extra_stuff)
|
24
|
+
self.class.sanitize_hash(hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
def extra_stuff
|
28
|
+
if @name
|
29
|
+
{'name' => @name}
|
30
|
+
else
|
31
|
+
{}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def context_stuff
|
36
|
+
context = Thread.current[:exceptional_context]
|
37
|
+
(context.nil? || context.empty?) ? {} : {'context' => context}
|
38
|
+
end
|
39
|
+
|
40
|
+
def framework
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def self.sanitize_hash(hash)
|
46
|
+
|
47
|
+
case hash
|
48
|
+
when Hash
|
49
|
+
hash.inject({}) do |result, (key, value)|
|
50
|
+
result.update(key => sanitize_hash(value))
|
51
|
+
end
|
52
|
+
when Array
|
53
|
+
hash.collect{|value| sanitize_hash(value)}
|
54
|
+
when Fixnum, String, Bignum
|
55
|
+
hash
|
56
|
+
else
|
57
|
+
hash.to_s
|
58
|
+
end
|
59
|
+
rescue Exception => e
|
60
|
+
{}
|
61
|
+
end
|
62
|
+
|
63
|
+
def extract_http_headers(env)
|
64
|
+
headers = {}
|
65
|
+
env.select{|k, v| k =~ /^HTTP_/}.each do |name, value|
|
66
|
+
proper_name = name.sub(/^HTTP_/, '').split('_').map{|upper_case| upper_case.capitalize}.join('-')
|
67
|
+
headers[proper_name] = value
|
68
|
+
end
|
69
|
+
unless headers['Cookie'].nil?
|
70
|
+
headers['Cookie'] = headers['Cookie'].sub(/_session=\S+/, '_session=[FILTERED]')
|
71
|
+
end
|
72
|
+
headers
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.sanitize_session(request)
|
76
|
+
|
77
|
+
session_hash = {'session_id' => "", 'data' => {}}
|
78
|
+
|
79
|
+
if request.respond_to?(:session)
|
80
|
+
|
81
|
+
session = request.session
|
82
|
+
session_hash['session_id'] = request.session_options ? request.session_options[:id] : nil
|
83
|
+
session_hash['session_id'] ||= session.respond_to?(:session_id) ? session.session_id : session.instance_variable_get("@session_id")
|
84
|
+
session_hash['data'] = session.respond_to?(:to_hash) ? session.to_hash : session.instance_variable_get("@data") || {}
|
85
|
+
session_hash['session_id'] ||= session_hash['data'][:session_id]
|
86
|
+
session_hash['data'].delete(:session_id)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Don't return the session hash if there is nothing in it
|
90
|
+
if session_hash['session_id'].nil? && session_hash['data'].empty?
|
91
|
+
{}
|
92
|
+
else
|
93
|
+
self.sanitize_hash(session_hash)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end # class end
|
99
99
|
end # module end
|
data/lib/ramon/railtie.rb
CHANGED
@@ -6,6 +6,17 @@ class Railtie < Rails::Railtie
|
|
6
6
|
initializer "amon.middleware" do |app|
|
7
7
|
app.config.middleware.use "Rack::RailsAmonException"
|
8
8
|
end
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
|
11
|
+
config.after_initialize do
|
12
|
+
Ramon.configure do |config|
|
13
|
+
config.logger ||= ::Rails.logger
|
14
|
+
config.environment_name ||= ::Rails.env
|
15
|
+
config.project_root ||= ::Rails.root
|
16
|
+
config.framework = "Rails: #{::Rails::VERSION::STRING}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end # class end
|
21
|
+
end # module end
|
11
22
|
|
data/lib/ramon/sender.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'zlib'
|
4
|
+
|
5
|
+
module Ramon
|
6
|
+
class Sender
|
7
|
+
def initialize(options = {})
|
8
|
+
[ :host,
|
9
|
+
:port,
|
10
|
+
:app_key,
|
11
|
+
:secret
|
12
|
+
].each do |option|
|
13
|
+
instance_variable_set("@#{option}", options[option])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
attr_reader :host,
|
19
|
+
:port,
|
20
|
+
:app_key,
|
21
|
+
:secret
|
22
|
+
|
23
|
+
def log(level, message)
|
24
|
+
logger.send level, '** Amon '+ message
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def logger
|
29
|
+
Ramon.logger
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def url
|
34
|
+
URI.parse("#{host}:#{port}/api/")
|
35
|
+
end
|
36
|
+
|
37
|
+
def post(type, data)
|
38
|
+
|
39
|
+
if type == 'log'
|
40
|
+
@url = "#{url}log/#{app_key}"
|
41
|
+
else
|
42
|
+
@url = "#{url}exception/#{app_key}"
|
43
|
+
end
|
44
|
+
|
45
|
+
request = Net::HTTP::Post.new(@url, initheader = {'Content-Type' =>'application/json'})
|
46
|
+
request.body = data.to_json
|
47
|
+
|
48
|
+
begin
|
49
|
+
response = Net::HTTP.new(url.host, url.port).start {|http| http.request(request) }
|
50
|
+
case response
|
51
|
+
when Net::HTTPSuccess
|
52
|
+
log :error, "#{@url} - #{response.message}"
|
53
|
+
return response
|
54
|
+
else
|
55
|
+
log :error, "#{@url} - #{response.code} - #{response.message}"
|
56
|
+
end
|
57
|
+
rescue Exception => e
|
58
|
+
log :error, "[Ramon::Sender#post] Cannot send data to #{@url} Error: #{e.class} - #{e.message}"
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end # Class end
|
65
|
+
end # Module end
|
data/lib/ramon/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Ramon
|
4
|
-
describe
|
4
|
+
describe "log" do
|
5
5
|
|
6
6
|
it "should return a hash with tags - debug and message - test" do
|
7
|
-
@log =
|
7
|
+
@log = Ramon.format_log('test', 'debug')
|
8
8
|
@log.should == {"tags" => "debug", "message" => "test"}
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should return a hash with tags - info and message - test" do
|
12
|
-
@log =
|
12
|
+
@log = Ramon.format_log('test', 'info')
|
13
13
|
@log.should == {"tags" => "info", "message" => "test"}
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should return a hash with tags - notset and message - test" do
|
17
|
-
@log =
|
17
|
+
@log = Ramon.format_log('test')
|
18
18
|
@log.should == {"tags" => "notset", "message" => "test"}
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should return a hash with tags - notset and a message hash" do
|
22
|
-
@log =
|
22
|
+
@log = Ramon.format_log({:test => "test value", :more => "even more value"})
|
23
23
|
@log.should == {"tags" => "notset", "message"=>{:more=>"even more value", :test=>"test value"}}
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should return a hash with tags - debug and a message hash" do
|
27
|
-
@log =
|
27
|
+
@log = Ramon.format_log({:test => "test value", :more => "even more value"},'debug')
|
28
28
|
@log.should == {"tags" => "debug", "message"=>{:more=>"even more value", :test=>"test value"}}
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should return a hash with tags - notset and a message array" do
|
32
|
-
@log =
|
32
|
+
@log = Ramon.format_log([1,2,3,4])
|
33
33
|
@log.should == {"tags" => "notset", "message"=>[1,2,3,4]}
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should return an array with tags - debug, benchmark and a message string" do
|
37
|
-
@log =
|
37
|
+
@log = Ramon.format_log("test", ["debug", "benchmark"])
|
38
38
|
@log.should == {"tags" => ["debug", "benchmark"], "message"=>"test"}
|
39
39
|
end
|
40
40
|
|
data/spec/web_spec.rb
CHANGED
@@ -1,22 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Ramon
|
4
|
+
# Works only when the Amon application is started
|
5
|
+
describe 'Web app test' do
|
5
6
|
|
6
|
-
|
7
|
-
Ramon.log([1,2,3,4]).response.code.should == "200"
|
8
|
-
Ramon.log({:test => 'data', :more_test => 'more_data'}).response.code.should == "200"
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'Test logging with multiple tags' do
|
12
|
-
Ramon.log("test", ['debug', 'benchmark']).response.code.should == "200"
|
13
|
-
Ramon.log({:test => 'data', :more_test => 'more_data'}, ['info','warning','user']).response.code.should == "200"
|
14
|
-
end
|
7
|
+
it 'Test logging' do
|
15
8
|
|
9
|
+
Ramon.configure do |config|
|
10
|
+
config.host = 'http://127.0.0.1'
|
11
|
+
config.port = 2464
|
12
|
+
end
|
13
|
+
|
14
|
+
Ramon.log([1,2,3,4]).response.code.should == "200"
|
15
|
+
Ramon.log({:test => 'data', :more_test => 'more_data'}).response.code.should == "200"
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
it 'Test logging with multiple tags' do
|
19
|
+
Ramon.log("test", ['debug', 'benchmark']).response.code.should == "200"
|
20
|
+
Ramon.log({:test => 'data', :more_test => 'more_data'}, ['info','warning','user']).response.code.should == "200"
|
21
|
+
end
|
20
22
|
|
21
|
-
|
23
|
+
|
24
|
+
it 'Test Exceptions' do
|
25
|
+
Ramon.post('exception', {:url => 'test', :exception_class => 'test_me'}).response.code.should == "200"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
22
30
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ramon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- martinrusev
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-02-23 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -47,21 +47,19 @@ files:
|
|
47
47
|
- Rakefile
|
48
48
|
- lib/ramon.rb
|
49
49
|
- lib/ramon/catcher.rb
|
50
|
-
- lib/ramon/
|
50
|
+
- lib/ramon/configuration.rb
|
51
51
|
- lib/ramon/controller_exception_data.rb
|
52
52
|
- lib/ramon/enviroment_data.rb
|
53
53
|
- lib/ramon/exception_data.rb
|
54
54
|
- lib/ramon/integration/rails.rb
|
55
|
-
- lib/ramon/log_factory.rb
|
56
55
|
- lib/ramon/railtie.rb
|
57
|
-
- lib/ramon/
|
56
|
+
- lib/ramon/sender.rb
|
58
57
|
- lib/ramon/version.rb
|
59
58
|
- ramon.gemspec
|
60
59
|
- spec/config_spec.rb
|
61
60
|
- spec/exception_data_spec.rb
|
62
|
-
- spec/
|
61
|
+
- spec/log_spec.rb
|
63
62
|
- spec/rails_integration_spec.rb
|
64
|
-
- spec/remote_spec.rb
|
65
63
|
- spec/spec_helper.rb
|
66
64
|
- spec/web_spec.rb
|
67
65
|
has_rdoc: true
|
data/lib/ramon/config.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module Ramon
|
4
|
-
class Config
|
5
|
-
class ConfigurationException < StandardError; end
|
6
|
-
|
7
|
-
class << self
|
8
|
-
DEFAULTS = {
|
9
|
-
:host => '127.0.0.1',
|
10
|
-
:port => 2464
|
11
|
-
}
|
12
|
-
|
13
|
-
def load
|
14
|
-
config_file ||= "/etc/amon.conf"
|
15
|
-
|
16
|
-
if File.file?(config_file)
|
17
|
-
begin
|
18
|
-
f = File.read(config_file)
|
19
|
-
config = JSON.parse(f)
|
20
|
-
|
21
|
-
@app_key = config['application_key'] unless config['application_key'].nil?
|
22
|
-
@port = config['web_app']['port'].to_i unless config['web_app']['port'].nil?
|
23
|
-
@host = config['web_app']['host'].to_s unless config['web_app']['host'].nil?
|
24
|
-
|
25
|
-
rescue Exception => e
|
26
|
-
raise ConfigurationException.new("Unable to load configuration file: #{config_file}")
|
27
|
-
end
|
28
|
-
else
|
29
|
-
puts "Amon::Config.load - /etc/amon.conf not found"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def application_root
|
34
|
-
(defined?(Rails) && Rails.respond_to?(:root)) ? Rails.root : Dir.pwd
|
35
|
-
end
|
36
|
-
|
37
|
-
def port
|
38
|
-
@port ||= DEFAULTS[:port]
|
39
|
-
end
|
40
|
-
|
41
|
-
def host
|
42
|
-
@host ||= DEFAULTS[:host]
|
43
|
-
end
|
44
|
-
|
45
|
-
end # self end
|
46
|
-
load
|
47
|
-
end # Config end
|
48
|
-
end # Module end
|
data/lib/ramon/log_factory.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
module Ramon
|
5
|
-
class Log
|
6
|
-
|
7
|
-
def self.log(message, tags=nil)
|
8
|
-
tags ||= 'notset'
|
9
|
-
log = {"message" => message, "tags" => tags}
|
10
|
-
|
11
|
-
log
|
12
|
-
end
|
13
|
-
|
14
|
-
end # class end
|
15
|
-
|
16
|
-
# Used internally
|
17
|
-
class LogFactory
|
18
|
-
|
19
|
-
def self.log
|
20
|
-
@logger ||= define_internal_logger
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
def self.define_internal_logger
|
25
|
-
log_dir = File.join(Config.application_root, 'log')
|
26
|
-
Dir.mkdir(log_dir) unless File.directory?(log_dir)
|
27
|
-
log_path = File.join(log_dir, "/ramon.log")
|
28
|
-
|
29
|
-
log = Logger.new(log_path)
|
30
|
-
log.level = Logger::INFO
|
31
|
-
|
32
|
-
log.formatter = proc do |severity, datetime, progname, msg|
|
33
|
-
"#{datetime}: #{msg} -- #{severity}\n"
|
34
|
-
end
|
35
|
-
|
36
|
-
log
|
37
|
-
end
|
38
|
-
|
39
|
-
end # class end
|
40
|
-
|
41
|
-
end # module end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
data/lib/ramon/remote.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'json'
|
3
|
-
require 'zlib'
|
4
|
-
require "#{File.dirname(__FILE__)}/config"
|
5
|
-
|
6
|
-
module Ramon
|
7
|
-
class Remote
|
8
|
-
def self.post(type, data)
|
9
|
-
|
10
|
-
if type == 'log'
|
11
|
-
@url = '/api/log'
|
12
|
-
else
|
13
|
-
@url = '/api/exception'
|
14
|
-
end
|
15
|
-
|
16
|
-
request = Net::HTTP::Post.new(@url, initheader = {'Content-Type' =>'application/json'})
|
17
|
-
request.body = data.to_json
|
18
|
-
|
19
|
-
begin
|
20
|
-
response = Net::HTTP.new(Config::host, Config::port).start {|http| http.request(request) }
|
21
|
-
case response
|
22
|
-
when Net::HTTPSuccess
|
23
|
-
LogFactory.log.info( "#{@url} - #{response.message}")
|
24
|
-
return response
|
25
|
-
else
|
26
|
-
LogFactory.log.error("#{@url} - #{response.code} - #{response.message}")
|
27
|
-
end
|
28
|
-
rescue Exception => e
|
29
|
-
LogFactory.log.error(e)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end # class end
|
34
|
-
end # module end
|
35
|
-
|
data/spec/remote_spec.rb
DELETED
File without changes
|