Commit 70d21539b107df6471cd054e1f04fb9cb3571b96
Exists in
master
Merge remote-tracking branch 'mak-it/slack'
Showing
3 changed files
with
42 additions
and
52 deletions
Show diff stats
app/models/notification_services/slack_service.rb
| ... | ... | @@ -19,41 +19,35 @@ class NotificationServices::SlackService < NotificationService |
| 19 | 19 | |
| 20 | 20 | def post_payload(problem) |
| 21 | 21 | { |
| 22 | + username: "Errbit", | |
| 23 | + icon_emoji: ":collision:", | |
| 22 | 24 | attachments: [ |
| 23 | 25 | { |
| 24 | - fallback: message_for_slack(problem), | |
| 25 | - pretext: "<#{problem.url}|Errbit - #{problem.app.name}: #{problem.error_class}>", | |
| 26 | - color: "#D00000", | |
| 27 | - fields: [ | |
| 26 | + fallback: message_for_slack(problem), | |
| 27 | + title: problem.message.to_s.truncate(100), | |
| 28 | + title_link: problem.url, | |
| 29 | + text: problem.where, | |
| 30 | + color: "#D00000", | |
| 31 | + fields: [ | |
| 28 | 32 | { |
| 29 | - title: "Environment", | |
| 30 | - value: problem.environment, | |
| 31 | - short: false | |
| 33 | + title: "Application", | |
| 34 | + value: problem.app.name, | |
| 35 | + short: true | |
| 32 | 36 | }, |
| 33 | 37 | { |
| 34 | - title: "Location", | |
| 35 | - value: problem.where, | |
| 36 | - short: false | |
| 38 | + title: "Environment", | |
| 39 | + value: problem.environment, | |
| 40 | + short: true | |
| 37 | 41 | }, |
| 38 | 42 | { |
| 39 | - title: "Message", | |
| 40 | - value: problem.message.to_s, | |
| 41 | - short: false | |
| 43 | + title: "Times Occurred", | |
| 44 | + value: problem.notices_count, | |
| 45 | + short: true | |
| 42 | 46 | }, |
| 43 | 47 | { |
| 44 | 48 | title: "First Noticed", |
| 45 | - value: problem.first_notice_at, | |
| 46 | - short: false | |
| 47 | - }, | |
| 48 | - { | |
| 49 | - title: "Last Noticed", | |
| 50 | - value: problem.last_notice_at, | |
| 51 | - short: false | |
| 52 | - }, | |
| 53 | - { | |
| 54 | - title: "Times Occurred", | |
| 55 | - value: problem.notices_count, | |
| 56 | - short: false | |
| 49 | + value: problem.first_notice_at.try(:to_s, :db), | |
| 50 | + short: true | |
| 57 | 51 | } |
| 58 | 52 | ] |
| 59 | 53 | } | ... | ... |
spec/fabricators/notice_fabricator.rb
| ... | ... | @@ -2,7 +2,7 @@ Fabricator :notice do |
| 2 | 2 | app |
| 3 | 3 | err |
| 4 | 4 | error_class 'FooError' |
| 5 | - message 'Too Much Bar' | |
| 5 | + message 'FooError: Too Much Bar' | |
| 6 | 6 | backtrace |
| 7 | 7 | server_environment { { 'environment-name' => 'production' } } |
| 8 | 8 | request { { 'component' => 'foo', 'action' => 'bar' } } | ... | ... |
spec/models/notification_service/slack_service_spec.rb
| ... | ... | @@ -2,46 +2,42 @@ describe NotificationServices::SlackService, type: 'model' do |
| 2 | 2 | it "it should send a notification to Slack with hook url" do |
| 3 | 3 | # setup |
| 4 | 4 | notice = Fabricate :notice |
| 5 | - notification_service = Fabricate :slack_notification_service, app: notice.app, service_url: "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX" | |
| 5 | + notification_service = Fabricate :slack_notification_service, | |
| 6 | + app: notice.app, | |
| 7 | + service_url: "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXX" | |
| 6 | 8 | problem = notice.problem |
| 7 | 9 | |
| 8 | 10 | # faraday stubbing |
| 9 | 11 | payload = { |
| 12 | + username: "Errbit", | |
| 13 | + icon_emoji: ":collision:", | |
| 10 | 14 | attachments: [ |
| 11 | 15 | { |
| 12 | - fallback: notification_service.message_for_slack(problem), | |
| 13 | - pretext: "<#{problem.url}|Errbit - #{problem.app.name}: #{problem.error_class}>", | |
| 14 | - color: "#D00000", | |
| 15 | - fields: [ | |
| 16 | + fallback: notification_service.message_for_slack(problem), | |
| 17 | + title: problem.message.to_s.truncate(100), | |
| 18 | + title_link: problem.url, | |
| 19 | + text: problem.where, | |
| 20 | + color: "#D00000", | |
| 21 | + fields: [ | |
| 16 | 22 | { |
| 17 | - title: "Environment", | |
| 18 | - value: problem.environment, | |
| 19 | - short: false | |
| 23 | + title: "Application", | |
| 24 | + value: problem.app.name, | |
| 25 | + short: true | |
| 20 | 26 | }, |
| 21 | 27 | { |
| 22 | - title: "Location", | |
| 23 | - value: problem.where, | |
| 24 | - short: false | |
| 28 | + title: "Environment", | |
| 29 | + value: problem.environment, | |
| 30 | + short: true | |
| 25 | 31 | }, |
| 26 | 32 | { |
| 27 | - title: "Message", | |
| 28 | - value: problem.message.to_s, | |
| 29 | - short: false | |
| 33 | + title: "Times Occurred", | |
| 34 | + value: problem.notices_count, | |
| 35 | + short: true | |
| 30 | 36 | }, |
| 31 | 37 | { |
| 32 | 38 | title: "First Noticed", |
| 33 | - value: problem.first_notice_at, | |
| 34 | - short: false | |
| 35 | - }, | |
| 36 | - { | |
| 37 | - title: "Last Noticed", | |
| 38 | - value: problem.last_notice_at, | |
| 39 | - short: false | |
| 40 | - }, | |
| 41 | - { | |
| 42 | - title: "Times Occurred", | |
| 43 | - value: problem.notices_count, | |
| 44 | - short: false | |
| 39 | + value: problem.first_notice_at.try(:to_s, :db), | |
| 40 | + short: true | |
| 45 | 41 | } |
| 46 | 42 | ] |
| 47 | 43 | } | ... | ... |