def close_incident(incident: Incident, user_id: str, message: str): comms_channel = CommsChannel.objects.get(incident=incident) action_list = Action.objects.filter(incident=incident) if incident.is_closed(): comms_channel.post_in_channel( f"This incident was already closed at {incident.end_time.strftime('%Y-%m-%d %H:%M:%S')}" ) return True, None incident.end_time = datetime.now() incident.save() comms_channel.post_in_channel( f"This incident has been closed! 📖 -> 📕") if action_list.exists(): get_action(incident, user_id, message) else: comms_channel.post_in_channel( f"There are no actions for this incident.\n You can still add one by using `@Incident Bot action ...`" ) comms_channel.archive_button(comms_channel.channel_id) return True, None
def update_summary(incident: Incident, user_id: str, message: str): comms_channel = CommsChannel.objects.get(incident=incident) previous_summary = incident.summary incident.summary = message incident.save() comms_channel.post_in_channel( f"The description has been updated to *{incident.summary}*") return True, None
def set_squad(incident: Incident, user_id: str, message: str): for squad_id, squad_name in Incident.SQUADS: if (squad_name in message) or (squad_id in message): incident.squad = squad_name incident.save() return True, None return False, None
def set_incident_lead(incident: Incident, user_id: str, message: str): assignee = reference_to_id(message) or user_id name = get_user_profile(assignee)['name'] user = GetOrCreateSlackExternalUser(external_id=assignee, display_name=name) incident.lead = user incident.save() return True, None
def update_impact(incident: Incident, user_id: str, message: str): comms_channel = CommsChannel.objects.get(incident=incident) previous_impact = incident.impact incident.impact = message incident.save() comms_channel.post_in_channel( f"Impact changed from *{previous_impact}* to *{incident.impact}*") return True, None
def set_severity(incident: Incident, user_id: str, message: str): for sev_id, sev_name in Incident.SEVERITIES: # look for sev name (e.g. critical) or sev id (1) if (sev_name in message) or (sev_id in message): incident.severity = sev_id incident.save() return True, None return False, None
def set_incident_lead(incident: Incident, user_id: str, message: str): comms_channel = CommsChannel.objects.get(incident=incident) assignee = reference_to_id(message) or user_id name = get_user_profile(assignee)['name'] user = GetOrCreateSlackExternalUser(external_id=assignee, display_name=name) incident.lead = user incident.save() comms_channel.post_in_channel( f"The incident lead has been changed to {name}") return True, None
def set_severity(incident: Incident, user_id: str, message: str): comms_channel = CommsChannel.objects.get(incident=incident) for sev_id, sev_name in Incident.SEVERITIES: # look for sev name (e.g. critical) or sev id (1) if (sev_name in message) or (sev_id in message): incident.severity = sev_id incident.save() comms_channel.post_in_channel( f"The incident severity has been changed to {sev_name}") return True, None return False, None
def remind_close_incident(incident: Incident): try: comms_channel = CommsChannel.objects.get(incident=incident) if not incident.is_closed(): comms_channel.post_in_channel( ":timer_clock: This incident has been running a long time. Can it be closed now?" ) elif incident.is_closed(): comms_channel.post_in_channel( ":timer_clock: This incident has been closed for a long time. Can the channel be archived?" ) except CommsChannel.DoesNotExist: pass
def remind_close_incident(incident: Incident): try: comms_channel = CommsChannel.objects.get(incident=incident) if not incident.is_closed(): comms_channel.post_in_channel(":timer_clock: This incident has been running a long time. Can it be closed now? Remember to pin important messages in order to create the timeline.") except CommsChannel.DoesNotExist: pass
def close_incident(incident: Incident, user_id: str, message: str): comms_channel = CommsChannel.objects.get(incident=incident) if incident.is_closed(): comms_channel.post_in_channel( f"This incident was already closed at {incident.end_time.strftime('%Y-%m-%d %H:%M:%S')}" ) return True, None incident.end_time = datetime.now() incident.save() comms_channel.post_in_channel( f"This incident has been closed! 📖 -> 📕") return True, None
def set_severity(incident: Incident, user_id: str, message: str): duration = incident.duration() comms_channel = CommsChannel.objects.get(incident=incident) comms_channel.post_in_channel(f"The incident has been running for {duration}") return True, None
def remind_client_comms(incident: Incident): try: comms_channel = CommsChannel.objects.get(incident=incident) if not incident.is_closed() and incident.severity < "4": comms_channel.post_in_channel( "Has the client been updated? :shrug:") except CommsChannel.DoesNotExist: pass
def remind_status_page(incident: Incident): try: comms_channel = CommsChannel.objects.get(incident=incident) if not incident.is_closed() and incident.severity < "4": comms_channel.post_in_channel( ":statuspage: Do we need to put up a statuspage? To do so, use the command `@Incident Bot statuspage`" ) except CommsChannel.DoesNotExist: pass
def set_incident_lead(incident: Incident, user_id: str, message: str): assignee = reference_to_id(message) incident.lead = assignee or user_id incident.save() return True, None
def update_impact(incident: Incident, user_id: str, message: str): incident.impact = message incident.save() return True, None
def update_summary(incident: Incident, user_id: str, message: str): incident.summary = message incident.save() return True, None