Skip to content

Commit

Permalink
Incident management help tips direct message (#1046)
Browse files Browse the repository at this point in the history
* Sends message to incident commander with tips on how to manage the incident

* Adds missing type

* Bugfix
  • Loading branch information
mvilanova authored Apr 19, 2021
1 parent f51c01c commit 56f4f04
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/dispatch/incident/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
send_incident_closed_information_review_reminder,
send_incident_commander_readded_notification,
send_incident_created_notifications,
send_incident_management_help_tips_message,
send_incident_new_role_assigned_notification,
send_incident_participant_announcement_message,
send_incident_rating_feedback_message,
Expand Down Expand Up @@ -771,6 +772,9 @@ def incident_create_flow(*, incident_id: int, checkpoint: str = None, db_session
incident_id=incident.id,
)

# we send a message to the incident commander with tips on how to manage the incident
send_incident_management_help_tips_message(incident, db_session)


def incident_active_status_flow(incident: Incident, db_session=None):
"""Runs the incident active flow."""
Expand Down Expand Up @@ -1135,7 +1139,10 @@ def incident_assign_role_flow(
)

if assignee_role == ParticipantRoleType.incident_commander:
if incident.status != IncidentStatus.closed:
# we send a message to the incident commander with tips on how to manage the incident
send_incident_management_help_tips_message(incident, db_session)

if incident.status != IncidentStatus.closed.value:
# we update the conversation topic
set_conversation_topic(incident, db_session)

Expand Down
51 changes: 51 additions & 0 deletions src/dispatch/incident/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
INCIDENT_CLOSED_RATING_FEEDBACK_NOTIFICATION,
INCIDENT_COMMANDER,
INCIDENT_COMMANDER_READDED_NOTIFICATION,
INCIDENT_MANAGEMENT_HELP_TIPS_MESSAGE,
INCIDENT_NAME,
INCIDENT_NAME_WITH_ENGAGEMENT,
INCIDENT_NEW_ROLE_NOTIFICATION,
Expand Down Expand Up @@ -793,3 +794,53 @@ def send_incident_rating_feedback_message(incident: Incident, db_session: Sessio
)

log.debug("Incident rating and feedback message sent to all participants.")


def send_incident_management_help_tips_message(incident: Incident, db_session: SessionLocal):
"""
Sends a direct message to the incident commander
with help tips on how to manage the incident.
"""
notification_text = "Incident Management Help Tips"
message_template = INCIDENT_MANAGEMENT_HELP_TIPS_MESSAGE

plugin = plugin_service.get_active(
db_session=db_session, project_id=incident.project.id, plugin_type="conversation"
)
if not plugin:
log.warning(
"Incident management help tips message not sent, no conversation plugin enabled."
)
return

engage_oncall_command = plugin.instance.get_command_name(ConversationCommands.engage_oncall)
list_resources_command = plugin.instance.get_command_name(ConversationCommands.list_resources)
executive_report_command = plugin.instance.get_command_name(
ConversationCommands.executive_report
)
tactical_report_command = plugin.instance.get_command_name(ConversationCommands.tactical_report)
update_command = plugin.instance.get_command_name(ConversationCommands.update_incident)

items = [
{
"name": incident.name,
"title": incident.title,
"engage_oncall_command": engage_oncall_command,
"list_resources_command": list_resources_command,
"executive_report_command": executive_report_command,
"tactical_report_command": tactical_report_command,
"update_command": update_command,
}
]

plugin.instance.send_direct(
incident.commander.individual.email,
notification_text,
message_template,
MessageType.incident_management_help_tips,
items=items,
)

log.debug(
f"Incident management help tips message sent to incident commander with email {incident.commander.individual.email}."
)
19 changes: 19 additions & 0 deletions src/dispatch/messaging/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MessageType(str, Enum):
incident_daily_report = "incident-daily-report"
incident_executive_report = "incident-executive-report"
incident_feedback_daily_report = "incident-feedback-daily-report"
incident_management_help_tips = "incident-management-help-tips"
incident_notification = "incident-notification"
incident_participant_suggested_reading = "incident-participant-suggested-reading"
incident_participant_welcome = "incident-participant-welcome"
Expand Down Expand Up @@ -277,6 +278,16 @@ class MessageType(str, Enum):
INCIDENT_CLOSED_RATING_FEEDBACK_DESCRIPTION = """
Thanks for participating in the {{name}} ("{{title}}") incident. We would appreciate if you could rate your experience and provide feedback."""

INCIDENT_MANAGEMENT_HELP_TIPS_MESSAGE_DESCRIPTION = """
Hey, I see you're the Incident Commander for {{name}} ("{{title}}"). Here are a few things to consider when managing the incident:
\n • Keep the incident and its status up to date using the Slack `{{update_command}}` command.
\n • Invite incident participants and team oncalls by mentioning them in the incident channel or using the Slack `{{engage_oncall_command}}` command.
\n • Keep incident participants and stakeholders informed using the `{{tactical_report_command}}` and `{{executive_report_command}}` commands.
\n • Get links to all incident resources including the Slack commands reference sheet and Security Incident Response FAQ by running the `{{list_resources_command}}` command.
\n\n
To find a Slack command, simply type `/` in the message field or click the lightning bolt icon to the left of the message field.
"""

INCIDENT_TYPE_CHANGE_DESCRIPTION = """
The incident type has been changed from {{ incident_type_old }} to {{ incident_type_new }}.""".replace(
"\n", " "
Expand Down Expand Up @@ -617,6 +628,14 @@ class MessageType(str, Enum):
]


INCIDENT_MANAGEMENT_HELP_TIPS_MESSAGE = [
{
"title": "{{name}} Incident - Management Help Tips",
"text": INCIDENT_MANAGEMENT_HELP_TIPS_MESSAGE_DESCRIPTION,
}
]


def render_message_template(message_template: List[dict], **kwargs):
"""Renders the jinja data included in the template itself."""
data = []
Expand Down
4 changes: 4 additions & 0 deletions src/dispatch/plugins/dispatch_slack/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ def get_template(message_type: MessageType):
default_notification,
None,
),
MessageType.incident_management_help_tips: (
default_notification,
None,
),
}

template_func, description = template_map.get(message_type, (None, None))
Expand Down

0 comments on commit 56f4f04

Please sign in to comment.