class AppsignalReport::SlackMessage
Attributes
report[R]
webhook_uri[R]
Public Class Methods
new(report:, webhook_url:)
click to toggle source
# File lib/appsignal_report/slack_message.rb, line 5 def initialize(report:, webhook_url:) @report = report @webhook_uri = URI(webhook_url) end
Public Instance Methods
attachment_messages()
click to toggle source
# File lib/appsignal_report/slack_message.rb, line 34 def attachment_messages [ ":information_source: #{report.report[:messages][:info]}", "#{error_rate_icon} #{report.report[:messages][:error_rate]}", "#{response_time_icon} #{report.report[:messages][:response_time]}", "#{throughput_icon} #{report.report[:messages][:throughput]}", ] end
error_rate_icon()
click to toggle source
# File lib/appsignal_report/slack_message.rb, line 43 def error_rate_icon report.report[:diff][:error_rate].negative? ? ':+1:' : ':-1:' end
payload()
click to toggle source
@return [Hash]
# File lib/appsignal_report/slack_message.rb, line 27 def payload { text: report.title, attachments: attachment_messages.map { |message| { text: message } }, } end
post()
click to toggle source
@return [Hash]
# File lib/appsignal_report/slack_message.rb, line 11 def post http = Net::HTTP.new(webhook_uri.host, webhook_uri.port) http.use_ssl = true post = Net::HTTP::Post.new(webhook_uri, 'Content-Type' => 'application/json') post.body = payload.to_json response = http.request(post) unless response.is_a? Net::HTTPSuccess raise StandardError, "[API ERROR] #{response.code} - #{response.message}" end end
response_time_icon()
click to toggle source
# File lib/appsignal_report/slack_message.rb, line 47 def response_time_icon report.report[:diff][:response_time].negative? ? ':+1:' : ':-1:' end
throughput_icon()
click to toggle source
# File lib/appsignal_report/slack_message.rb, line 51 def throughput_icon up_down = report.report[:diff][:throughput].negative? ? 'downwards' : 'upwards' ":chart_with_#{up_down}_trend:" end