Class: Coalmine::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/coalmine/notification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Notification

Returns a new instance of Notification.



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
# File 'lib/coalmine/notification.rb', line 17

def initialize(args = {})
  
  exception = args[:exception]
  
  if exception
    self.stack_trace = exception.backtrace * "\n" if exception.backtrace
    self.message     = exception.message
    self.error_class = exception.class.name
    self.line_number = extract_line_number(exception.backtrace)
    self.file        = extract_file_name(exception.backtrace)
  end
  
  if args[:rack_env]
    set_from_rack_env(args[:rack_env])
  end
        
  args.keys.each do |key|
    setter = :"#{key}="
    send(setter, args[key]) if respond_to?(setter)
  end
  
  self.severity = "ERROR" unless self.severity
  self.hostname = Socket.gethostname
  
  begin
    self.process_id = Process::pid
  rescue
    # Ignore
  end
  
  begin
    self.thread_id = Thread.current.object_id
  rescue
    # Ignore
  end
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def action
  @action
end

#controllerObject

Returns the value of attribute controller.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def controller
  @controller
end

#cookiesObject

Returns the value of attribute cookies.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def cookies
  @cookies
end

#environmentObject

Returns the value of attribute environment.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def environment
  @environment
end

#error_classObject

Returns the value of attribute error_class.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def error_class
  @error_class
end

#fileObject

Returns the value of attribute file.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def file
  @file
end

#hostnameObject

Returns the value of attribute hostname.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def hostname
  @hostname
end

#ip_addressObject

Returns the value of attribute ip_address.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def ip_address
  @ip_address
end

#line_numberObject

Returns the value of attribute line_number.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def line_number
  @line_number
end

#messageObject

Returns the value of attribute message.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def message
  @message
end

#methodObject

Returns the value of attribute method.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def method
  @method
end

#parametersObject

Returns the value of attribute parameters.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def parameters
  @parameters
end

#process_idObject

Returns the value of attribute process_id.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def process_id
  @process_id
end

#referrerObject

Returns the value of attribute referrer.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def referrer
  @referrer
end

#serverObject

Returns the value of attribute server.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def server
  @server
end

#severityObject

Returns the value of attribute severity.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def severity
  @severity
end

#stack_traceObject

Returns the value of attribute stack_trace.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def stack_trace
  @stack_trace
end

#thread_idObject

Returns the value of attribute thread_id.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def thread_id
  @thread_id
end

#urlObject

Returns the value of attribute url.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def url
  @url
end

#user_agentObject

Returns the value of attribute user_agent.



12
13
14
# File 'lib/coalmine/notification.rb', line 12

def user_agent
  @user_agent
end

Instance Method Details

#post_dataObject



54
55
56
# File 'lib/coalmine/notification.rb', line 54

def post_data
  {:signature => Coalmine.config.signature, :json => to_json}
end

#resource_pathString

Remote resource path

Returns:

  • (String)

    The path of the remote resource. Will be appended to the remote base URL.



96
97
98
# File 'lib/coalmine/notification.rb', line 96

def resource_path
  "/notify/"
end

#serialize(options) ⇒ Object



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
# File 'lib/coalmine/notification.rb', line 62

def serialize(options)
  config = Coalmine.config
  results = {
    :version         => config.version, 
    :app_environment => config.environment,
    :url             => url,
    :file            => file,
    :line_number     => line_number,
    :message         => message, 
    :stack_trace     => stack_trace, 
    :class           => error_class, 
    :framework       => config.framework, 
    :parameters      => parameters, 
    :ip_address      => ip_address, 
    :user_agent      => user_agent, 
    :cookies         => cookies, 
    :method          => method,
    :environment     => environment,
    :server          => server,
    :severity        => severity,
    :hostname        => hostname,
    :process_id      => process_id,
    :thread_id       => thread_id.to_s, # Because it is a long
    :referrer        => referrer,
    :application     => Coalmine.custom_variables
  }
  
  Coalmine.filter(results)
end

#to_json(options = {}) ⇒ Object



58
59
60
# File 'lib/coalmine/notification.rb', line 58

def to_json(options = {})
  ActiveSupport::JSON.encode(serialize(options))
end