Skip to content

Commit

Permalink
Merge pull request #889 from threatsim/feature/slack_service_changes
Browse files Browse the repository at this point in the history
Adds in formatting for Slack
  • Loading branch information
stevecrozz committed May 22, 2015
2 parents abbad62 + f16e413 commit 4f26840
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
42 changes: 41 additions & 1 deletion app/models/notification_services/slack_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,47 @@ def message_for_slack(problem)
end

def post_payload(problem)
{:text => message_for_slack(problem) }.to_json
{
:attachments => [
{
:fallback => message_for_slack(problem),
:pretext => "<#{problem_url(problem)}|Errbit - #{problem.app.name}: #{problem.error_class}>",
:color => "#D00000",
:fields => [
{
:title => "Environment",
:value => problem.environment,
:short => false
},
{
:title => "Location",
:value => problem.where,
:short => false
},
{
:title => "Message",
:value => problem.message.to_s,
:short => false
},
{
: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
}
]
}
]
}.to_json
end

def create_notification(problem)
Expand Down
42 changes: 41 additions & 1 deletion spec/models/notification_service/slack_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,47 @@
problem = notice.problem

# faraday stubbing
payload = {:text => notification_service.message_for_slack(problem)}.to_json
payload = {
:attachments => [
{
:fallback => notification_service.message_for_slack(problem),
:pretext => "<#{notification_service.problem_url(problem)}|Errbit - #{problem.app.name}: #{problem.error_class}>",
:color => "#D00000",
:fields => [
{
:title => "Environment",
:value => problem.environment,
:short => false
},
{
:title => "Location",
:value => problem.where,
:short => false
},
{
:title => "Message",
:value => problem.message.to_s,
:short => false
},
{
: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
}
]
}
]
}.to_json
expect(HTTParty).to receive(:post).with(notification_service.service_url, :body => payload, :headers => {"Content-Type" => "application/json"}).and_return(true)

notification_service.create_notification(problem)
Expand Down

0 comments on commit 4f26840

Please sign in to comment.