Commit 4f26840551099fcb1814909d76895a7f11d9e26f
Exists in
master
and in
1 other branch
Merge pull request #889 from threatsim/feature/slack_service_changes
Adds in formatting for Slack
Showing
2 changed files
with
82 additions
and
2 deletions
Show diff stats
app/models/notification_services/slack_service.rb
| ... | ... | @@ -18,7 +18,47 @@ class NotificationServices::SlackService < NotificationService |
| 18 | 18 | end |
| 19 | 19 | |
| 20 | 20 | def post_payload(problem) |
| 21 | - {:text => message_for_slack(problem) }.to_json | |
| 21 | + { | |
| 22 | + :attachments => [ | |
| 23 | + { | |
| 24 | + :fallback => message_for_slack(problem), | |
| 25 | + :pretext => "<#{problem_url(problem)}|Errbit - #{problem.app.name}: #{problem.error_class}>", | |
| 26 | + :color => "#D00000", | |
| 27 | + :fields => [ | |
| 28 | + { | |
| 29 | + :title => "Environment", | |
| 30 | + :value => problem.environment, | |
| 31 | + :short => false | |
| 32 | + }, | |
| 33 | + { | |
| 34 | + :title => "Location", | |
| 35 | + :value => problem.where, | |
| 36 | + :short => false | |
| 37 | + }, | |
| 38 | + { | |
| 39 | + :title => "Message", | |
| 40 | + :value => problem.message.to_s, | |
| 41 | + :short => false | |
| 42 | + }, | |
| 43 | + { | |
| 44 | + :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 | |
| 57 | + } | |
| 58 | + ] | |
| 59 | + } | |
| 60 | + ] | |
| 61 | + }.to_json | |
| 22 | 62 | end |
| 23 | 63 | |
| 24 | 64 | def create_notification(problem) | ... | ... |
spec/models/notification_service/slack_service_spec.rb
| ... | ... | @@ -6,7 +6,47 @@ describe NotificationService::SlackService, type: 'model' do |
| 6 | 6 | problem = notice.problem |
| 7 | 7 | |
| 8 | 8 | # faraday stubbing |
| 9 | - payload = {:text => notification_service.message_for_slack(problem)}.to_json | |
| 9 | + payload = { | |
| 10 | + :attachments => [ | |
| 11 | + { | |
| 12 | + :fallback => notification_service.message_for_slack(problem), | |
| 13 | + :pretext => "<#{notification_service.problem_url(problem)}|Errbit - #{problem.app.name}: #{problem.error_class}>", | |
| 14 | + :color => "#D00000", | |
| 15 | + :fields => [ | |
| 16 | + { | |
| 17 | + :title => "Environment", | |
| 18 | + :value => problem.environment, | |
| 19 | + :short => false | |
| 20 | + }, | |
| 21 | + { | |
| 22 | + :title => "Location", | |
| 23 | + :value => problem.where, | |
| 24 | + :short => false | |
| 25 | + }, | |
| 26 | + { | |
| 27 | + :title => "Message", | |
| 28 | + :value => problem.message.to_s, | |
| 29 | + :short => false | |
| 30 | + }, | |
| 31 | + { | |
| 32 | + :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 | |
| 45 | + } | |
| 46 | + ] | |
| 47 | + } | |
| 48 | + ] | |
| 49 | + }.to_json | |
| 10 | 50 | expect(HTTParty).to receive(:post).with(notification_service.service_url, :body => payload, :headers => {"Content-Type" => "application/json"}).and_return(true) |
| 11 | 51 | |
| 12 | 52 | notification_service.create_notification(problem) | ... | ... |