diff --git a/app/models/notification_services/slack_service.rb b/app/models/notification_services/slack_service.rb index 6c1f7ed..a30a1f6 100644 --- a/app/models/notification_services/slack_service.rb +++ b/app/models/notification_services/slack_service.rb @@ -19,41 +19,35 @@ class NotificationServices::SlackService < NotificationService def post_payload(problem) { + username: "Errbit", + icon_emoji: ":collision:", attachments: [ { - fallback: message_for_slack(problem), - pretext: "<#{problem.url}|Errbit - #{problem.app.name}: #{problem.error_class}>", - color: "#D00000", - fields: [ + fallback: message_for_slack(problem), + title: problem.message.to_s.truncate(100), + title_link: problem.url, + text: problem.where, + color: "#D00000", + fields: [ { - title: "Environment", - value: problem.environment, - short: false + title: "Application", + value: problem.app.name, + short: true }, { - title: "Location", - value: problem.where, - short: false + title: "Environment", + value: problem.environment, + short: true }, { - title: "Message", - value: problem.message.to_s, - short: false + title: "Times Occurred", + value: problem.notices_count, + short: true }, { title: "First Noticed", - value: problem.first_notice_at, - short: false - }, - { - title: "Last Noticed", - value: problem.last_notice_at, - short: false - }, - { - title: "Times Occurred", - value: problem.notices_count, - short: false + value: problem.first_notice_at.try(:to_s, :db), + short: true } ] } diff --git a/spec/fabricators/notice_fabricator.rb b/spec/fabricators/notice_fabricator.rb index 3de4a41..3188018 100644 --- a/spec/fabricators/notice_fabricator.rb +++ b/spec/fabricators/notice_fabricator.rb @@ -2,7 +2,7 @@ Fabricator :notice do app err error_class 'FooError' - message 'Too Much Bar' + message 'FooError: Too Much Bar' backtrace server_environment { { 'environment-name' => 'production' } } request { { 'component' => 'foo', 'action' => 'bar' } } diff --git a/spec/models/notification_service/slack_service_spec.rb b/spec/models/notification_service/slack_service_spec.rb index 0e80091..1df9a31 100644 --- a/spec/models/notification_service/slack_service_spec.rb +++ b/spec/models/notification_service/slack_service_spec.rb @@ -2,46 +2,42 @@ describe NotificationServices::SlackService, type: 'model' do it "it should send a notification to Slack with hook url" do # setup notice = Fabricate :notice - notification_service = Fabricate :slack_notification_service, app: notice.app, service_url: "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX" + notification_service = Fabricate :slack_notification_service, + app: notice.app, + service_url: "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX" problem = notice.problem # faraday stubbing payload = { + username: "Errbit", + icon_emoji: ":collision:", attachments: [ { - fallback: notification_service.message_for_slack(problem), - pretext: "<#{problem.url}|Errbit - #{problem.app.name}: #{problem.error_class}>", - color: "#D00000", - fields: [ + fallback: notification_service.message_for_slack(problem), + title: problem.message.to_s.truncate(100), + title_link: problem.url, + text: problem.where, + color: "#D00000", + fields: [ { - title: "Environment", - value: problem.environment, - short: false + title: "Application", + value: problem.app.name, + short: true }, { - title: "Location", - value: problem.where, - short: false + title: "Environment", + value: problem.environment, + short: true }, { - title: "Message", - value: problem.message.to_s, - short: false + title: "Times Occurred", + value: problem.notices_count, + short: true }, { title: "First Noticed", - value: problem.first_notice_at, - short: false - }, - { - title: "Last Noticed", - value: problem.last_notice_at, - short: false - }, - { - title: "Times Occurred", - value: problem.notices_count, - short: false + value: problem.first_notice_at.try(:to_s, :db), + short: true } ] } -- libgit2 0.21.2