def delete_participant_groups(incident: Incident, db_session: SessionLocal): """Deletes the external participant groups.""" # we get the tactical group tactical_group = group_service.get_by_incident_id_and_resource_type( db_session=db_session, incident_id=incident.id, resource_type=INCIDENT_RESOURCE_TACTICAL_GROUP, ) # we get the notifications group notifications_group = group_service.get_by_incident_id_and_resource_type( db_session=db_session, incident_id=incident.id, resource_type=INCIDENT_RESOURCE_NOTIFICATIONS_GROUP, ) p = plugins.get(INCIDENT_PLUGIN_GROUP_SLUG) p.delete(email=tactical_group.email) p.delete(email=notifications_group.email) event_service.log( db_session=db_session, source=p.title, description="Tactical and notification groups deleted", incident_id=incident.id, )
def add_participant_to_tactical_group(user_email: str, incident_id: int, db_session: SessionLocal): """Adds participant to the tactical group.""" # we get the tactical group tactical_group = group_service.get_by_incident_id_and_resource_type( db_session=db_session, incident_id=incident_id, resource_type=INCIDENT_RESOURCE_TACTICAL_GROUP, ) plugin = plugin_service.get_active(db_session=db_session, plugin_type="participant-group") plugin.instance.add(tactical_group.email, [user_email])
def add_participant_to_tactical_group(user_email: str, incident_id: int, db_session=None): """Adds participant to the tactical group.""" # we get the tactical group tactical_group = group_service.get_by_incident_id_and_resource_type( db_session=db_session, incident_id=incident_id, resource_type=INCIDENT_RESOURCE_TACTICAL_GROUP, ) p = plugins.get(INCIDENT_PLUGIN_GROUP_SLUG) p.add(tactical_group.email, [user_email])
def send_executive_report_to_notifications_group( incident_id: int, executive_report: Report, db_session: SessionLocal, ): """Sends an executive report to the notifications group.""" # we load the incident instance incident = incident_service.get(db_session=db_session, incident_id=incident_id) notification_group = group_service.get_by_incident_id_and_resource_type( db_session=db_session, incident_id=incident.id, resource_type=INCIDENT_RESOURCE_NOTIFICATIONS_GROUP, ) subject = f"{incident.name.upper()} - Executive Report" email_plugin = plugins.get(INCIDENT_PLUGIN_EMAIL_SLUG) email_plugin.send( notification_group.email, INCIDENT_EXECUTIVE_REPORT, MessageType.incident_executive_report, subject=subject, name=subject, title=incident.title, current_status=executive_report.details.get("current_status"), overview=executive_report.details.get("overview"), next_steps=executive_report.details.get("next_steps"), weblink=executive_report.document.weblink, notifications_group=notification_group.email, contact_fullname=incident.commander.name, contact_weblink=incident.commander.weblink, ) log.debug( f"Executive report sent to notifications group {notification_group.email}." )
def incident_update_flow(user_email: str, incident_id: int, previous_incident: IncidentRead, notify=True, db_session=None): """Runs the incident update flow.""" conversation_topic_change = False # we load the incident instance incident = incident_service.get(db_session=db_session, incident_id=incident_id) if previous_incident.incident_type.name != incident.incident_type.name: conversation_topic_change = True if previous_incident.incident_priority.name != incident.incident_priority.name: conversation_topic_change = True if previous_incident.status.value != incident.status: conversation_topic_change = True if conversation_topic_change: # we update the conversation topic set_conversation_topic(incident) if notify: send_incident_update_notifications(incident, previous_incident) # we get the incident document incident_document = get_document( db_session=db_session, incident_id=incident_id, resource_type=INCIDENT_RESOURCE_INVESTIGATION_DOCUMENT, ) # we update the external ticket update_incident_ticket( incident.ticket.resource_id, title=incident.title, description=incident.description, incident_type=incident.incident_type.name, priority=incident.incident_priority.name, commander_email=incident.commander.email, conversation_weblink=incident.conversation.weblink, conference_weblink=incident.conference.weblink, document_weblink=incident_document.weblink, storage_weblink=incident.storage.weblink, visibility=incident.visibility, ) log.debug(f"Updated the external ticket {incident.ticket.resource_id}.") # get the incident participants based on incident type and priority individual_participants, team_participants = get_incident_participants( incident, db_session) # lets not attempt to add new participants for non-active incidents (it's confusing) if incident.status == IncidentStatus.active: # we add the individuals as incident participants for individual in individual_participants: incident_add_or_reactivate_participant_flow(individual.email, incident.id, db_session=db_session) # we get the notification group notification_group = group_service.get_by_incident_id_and_resource_type( db_session=db_session, incident_id=incident.id, resource_type=INCIDENT_RESOURCE_NOTIFICATIONS_GROUP, ) team_participant_emails = [x.email for x in team_participants] # we add the team distributions lists to the notifications group group_plugin = plugins.get(INCIDENT_PLUGIN_GROUP_SLUG) group_plugin.add(notification_group.email, team_participant_emails) if previous_incident.status.value != incident.status: if incident.status == IncidentStatus.active: incident_active_flow(incident_id=incident.id, db_session=db_session) elif incident.status == IncidentStatus.stable: incident_stable_flow(incident_id=incident.id, db_session=db_session) elif incident.status == IncidentStatus.closed: if previous_incident.status.value == IncidentStatus.active: incident_stable_flow(incident_id=incident.id, db_session=db_session) incident_closed_flow(incident_id=incident.id, db_session=db_session)
def incident_edit_flow(user_email: str, incident_id: int, action: dict, db_session=None): """Runs the incident edit flow.""" notify = action["submission"]["notify"] incident_title = action["submission"]["title"] incident_description = action["submission"]["description"] incident_type = action["submission"]["type"] incident_priority = action["submission"]["priority"] incident_visibility = action["submission"]["visibility"] conversation_topic_change = False # we load the incident instance incident = incident_service.get(db_session=db_session, incident_id=incident_id) # we update the incident title incident.title = incident_title log.debug(f"Updated the incident title to {incident_title}.") # we update the incident description incident.description = incident_description log.debug(f"Updated the incident description to {incident_description}.") if incident_type != incident.incident_type.name: # we update the incident type incident_type_obj = incident_type_service.get_by_name( db_session=db_session, name=incident_type ) incident.incident_type_id = incident_type_obj.id log.debug(f"Updated the incident type to {incident_type}.") conversation_topic_change = True if incident_priority != incident.incident_priority.name: # we update the incident priority incident_priority_obj = incident_priority_service.get_by_name( db_session=db_session, name=incident_priority ) incident.incident_priority_id = incident_priority_obj.id log.debug(f"Updated the incident priority to {incident_priority}.") conversation_topic_change = True if incident_visibility != incident.visibility: # we update the incident visibility incident.visibility = incident_visibility log.debug(f"Updated the incident visibility to {incident_visibility}.") if notify == "Yes": send_incident_change_notifications( incident, incident_title, incident_type, incident_priority ) # we commit the changes to the incident db_session.add(incident) db_session.commit() if conversation_topic_change: # we update the conversation topic set_conversation_topic(incident) # we get the incident document incident_document = get_document( db_session=db_session, incident_id=incident_id, resource_type=INCIDENT_RESOURCE_INVESTIGATION_DOCUMENT, ) # we update the external ticket update_incident_ticket( incident.ticket.resource_id, title=incident.title, description=incident.description, incident_type=incident_type, priority=incident_priority, commander_email=incident.commander.email, conversation_weblink=incident.conversation.weblink, document_weblink=incident_document.weblink, storage_weblink=incident.storage.weblink, ) log.debug(f"Updated the external ticket {incident.ticket.resource_id}.") # get the incident participants based on incident type and priority individual_participants, team_participants = get_incident_participants( db_session, incident.incident_type, incident.incident_priority, incident.description ) # we add the individuals as incident participants for individual in individual_participants: incident_add_or_reactivate_participant_flow( individual.email, incident.id, db_session=db_session ) # we get the tactical group notification_group = group_service.get_by_incident_id_and_resource_type( db_session=db_session, incident_id=incident.id, resource_type=INCIDENT_RESOURCE_NOTIFICATIONS_GROUP, ) team_participant_emails = [x.email for x in team_participants] # we add the team distributions lists to the notifications group group_plugin = plugins.get(INCIDENT_PLUGIN_GROUP_SLUG) group_plugin.add(notification_group.email, team_participant_emails) log.debug(f"Resolved and added new participants to the incident.")
def incident_closed_flow(incident_id: int, command: Optional[dict] = None, db_session=None): """Runs the incident closed flow.""" # we load the incident instance incident = incident_service.get(db_session=db_session, incident_id=incident_id) if incident.status == IncidentStatus.active: # we run the stable flow and let the user know if command: convo_plugin = plugins.get(INCIDENT_PLUGIN_CONVERSATION_SLUG) convo_plugin.send_ephemeral( command["channel_id"], command["user_id"], "Mark Incident Stable Notification", blocks=[ { "type": "section", "text": {"type": "plain_text", "text": "Marking the incident as stable..."}, } ], ) incident_stable_flow(incident_id, command=command, db_session=db_session) # we update the status of the incident update_incident_status(db_session=db_session, incident=incident, status=IncidentStatus.closed) log.debug(f"We have updated the status of the incident to {IncidentStatus.closed}.") # we update the incident cost incident_cost = incident_service.calculate_cost(incident_id, db_session) log.debug(f"We have updated the cost of the incident.") # we archive the conversation convo_plugin = plugins.get(INCIDENT_PLUGIN_CONVERSATION_SLUG) convo_plugin.archive(incident.conversation.channel_id) log.debug("We have archived the incident conversation.") # we send the closed notifications send_incident_status_notifications(incident, db_session) log.debug("We have sent the incident closed notifications.") # we update the external ticket update_incident_ticket( incident.ticket.resource_id, incident_type=incident.incident_type.name, status=IncidentStatus.closed.lower(), cost=incident_cost, ) log.debug(f"We have updated the status of the external ticket to {IncidentStatus.closed}.") # we archive the artifacts in the storage storage_plugin = plugins.get(INCIDENT_PLUGIN_STORAGE_SLUG) storage_plugin.archive( source_team_drive_id=incident.storage.resource_id, dest_team_drive_id=INCIDENT_STORAGE_ARCHIVAL_FOLDER_ID, folder_name=incident.name, ) log.debug( "We have archived the incident artifacts in the archival folder and re-applied permissions and deleted the source." ) # we get the tactical group tactical_group = group_service.get_by_incident_id_and_resource_type( db_session=db_session, incident_id=incident_id, resource_type=INCIDENT_RESOURCE_TACTICAL_GROUP, ) # we get the notifications group notifications_group = group_service.get_by_incident_id_and_resource_type( db_session=db_session, incident_id=incident_id, resource_type=INCIDENT_RESOURCE_NOTIFICATIONS_GROUP, ) group_plugin = plugins.get(INCIDENT_PLUGIN_GROUP_SLUG) group_plugin.delete(email=tactical_group.email) group_plugin.delete(email=notifications_group.email) log.debug("We have deleted the notification and tactical groups.")
def incident_closed_flow(incident_id: int, command: Optional[dict] = None, db_session=None): """Runs the incident closed flow.""" # we load the incident instance incident = incident_service.get(db_session=db_session, incident_id=incident_id) # we set the closed time incident.closed_at = datetime.utcnow() log.debug(f"We have set the closed time.") # we update the incident cost incident_cost = incident_service.calculate_cost(incident_id, db_session) log.debug(f"We have updated the cost of the incident.") # we archive the conversation convo_plugin = plugins.get(INCIDENT_PLUGIN_CONVERSATION_SLUG) convo_plugin.archive(incident.conversation.channel_id) log.debug("We have archived the incident conversation.") # we update the external ticket update_incident_ticket(incident.ticket.resource_id, status=IncidentStatus.closed.lower(), cost=incident_cost) log.debug( f"We have updated the status of the external ticket to {IncidentStatus.closed}." ) if incident.visibility == Visibility.open: # we archive the artifacts in the storage storage_plugin = plugins.get(INCIDENT_PLUGIN_STORAGE_SLUG) storage_plugin.archive( source_team_drive_id=incident.storage.resource_id, dest_team_drive_id=INCIDENT_STORAGE_ARCHIVAL_FOLDER_ID, folder_name=incident.name, visibility=incident.visibility, ) log.debug( "We have archived the incident artifacts in the archival folder and re-applied permissions and deleted the source." ) # we get the tactical group tactical_group = group_service.get_by_incident_id_and_resource_type( db_session=db_session, incident_id=incident_id, resource_type=INCIDENT_RESOURCE_TACTICAL_GROUP, ) # we get the notifications group notifications_group = group_service.get_by_incident_id_and_resource_type( db_session=db_session, incident_id=incident_id, resource_type=INCIDENT_RESOURCE_NOTIFICATIONS_GROUP, ) group_plugin = plugins.get(INCIDENT_PLUGIN_GROUP_SLUG) group_plugin.delete(email=tactical_group.email) group_plugin.delete(email=notifications_group.email) log.debug("We have deleted the notification and tactical groups.") db_session.add(incident) db_session.commit()