Skip to content

Commit

Permalink
fix tests and incident id insert in slack message
Browse files Browse the repository at this point in the history
  • Loading branch information
diegocepedaw authored and jwon committed Jul 20, 2021
1 parent 6bc8a33 commit cb7c3d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/iris/vendors/iris_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ def construct_attachment(self, message):
return {
'fallback': self.message_attachments.get('fallback'),
'pretext': self.message_attachments.get('pretext'),
'title': 'Iris incident %r' % message['incident_id'],
'title': 'Iris incident %r' % message.get('incident_id'),
'mrkdwn_in': ['pretext'],
'attachment_type': 'default',
'callback_id': message.get('message_id'),
'color': 'danger',
'title_link': '%s/%s' % (
self.config['iris_incident_url'], message['incident_id']),
self.config['iris_incident_url'], message.get('incident_id')),
'actions': [
{
'name': 'claim',
Expand Down Expand Up @@ -108,6 +108,8 @@ def get_message_payload(self, message):
slack_message.get('text', ''))
# For incidents, add the Iris attachments at the end
if 'incident_id' in message:
slack_message['incident_id'] = message.get('incident_id')
slack_message['message_id'] = message.get('message_id')
slack_message.setdefault('attachments', []).append(self.construct_attachment(slack_message))
return slack_message

Expand Down
5 changes: 1 addition & 4 deletions test/test_iris_vendor_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-

from iris.vendors.iris_slack import iris_slack
import ujson as json


def test_atttachments_construction_for_incident():
Expand All @@ -23,11 +22,10 @@ def test_atttachments_construction_for_incident():
}
msg_payload = slack_vendor.get_message_payload(fake_msg)
assert msg_payload['text'] == '[grafana] %s' % fake_msg['body']
assert msg_payload['token'] == 'abc'
assert msg_payload['channel'] == '@user1'

attachments = msg_payload['attachments']
assert json.loads(attachments) == [{
assert attachments == [{
'fallback': 'foo fallback',
'pretext': 'foo pretext',
'title': 'Iris incident %r' % fake_msg['incident_id'],
Expand Down Expand Up @@ -77,6 +75,5 @@ def test_atttachments_construction_for_notification():
msg_payload = slack_vendor.get_message_payload(fake_msg)
assert msg_payload == {
'text': '[grafana] %s' % fake_msg['body'],
'token': 'abc',
'channel': '@user1'
}

0 comments on commit cb7c3d7

Please sign in to comment.