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
|
# File 'lib/slack_500.rb', line 27
def self.post (request, exception, params = {})
url = self.webhook_url
begin
uri = URI.parse(url)
rescue
Rails.logger.error '** Slack500:: invalid Webhook URL.'
return
end
text = "#{request.method} #{request.url} (#{request.user_agent}) : #{request.query_parameters}\n#{exception.message}\n#{exception.backtrace.map {|s| s.gsub(Rails.root.to_s, '')}.join("\n")}"
default_params = {
pretext: self.pretext,
title: self.pretext,
color: self.color,
footer: self.
}
attachments = default_params.merge(params)
attachments[:text] = text
attachments[:title] = "#{request.parameters[:controller]}##{request.parameters[:action]} - #{attachments[:title]}"
params = {
attachments: [attachments]
}
begin
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.start do
request = Net::HTTP::Post.new(uri.path)
request.set_form_data(payload: params.to_json)
http.request(request)
end
rescue => e
Rails.logger.error "** Slack500:: #{e.full_message}."
end
end
|