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 remind_update_status(incident: Incident): try: comms_channel = CommsChannel.objects.get(incident=incident) if not incident.is_closed(): user_to_notify = incident.lead or incident.reporter comms_channel.post_in_channel( f":timer_clock: <@{user_to_notify.external_id}>, this incident has been running a long time." " Have you updated the proper notification channels? Remember to notify status updates in twitter and status page" ) 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 remind_close_incident(incident: Incident): # Only remind on weekdays (weekday returns an ordinal indexed from 0 on Monday) if datetime.now().weekday() in (5, 6): return try: comms_channel = CommsChannel.objects.get(incident=incident) if not incident.is_closed(): user_to_notify = incident.lead or incident.reporter comms_channel.post_in_channel( f":timer_clock: <@{user_to_notify.external_id}>, 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 prompt_incident_report(sender, instance: Incident, **kwargs): """ Prompt incident lead to complete a report when an incident is closed. """ try: prev_state = Incident.objects.get(pk=instance.pk) except Incident.DoesNotExist: # Incident hasn't been saved yet, nothing to do here. return if instance.is_closed() and not prev_state.is_closed(): user_to_notify = instance.lead or instance.reporter doc_url = urljoin( settings.SITE_URL, reverse('incident_doc', kwargs={'incident_id': instance.pk}) ) settings.SLACK_CLIENT.send_message( user_to_notify.external_id, f"👋 Don't forget to fill out an incident report here: {doc_url}")
def prompt_incident_report(sender, instance: Incident, **kwargs): """ Prompt incident lead to complete a report when an incident is closed. """ try: prev_state = Incident.objects.get(pk=instance.pk) except Incident.DoesNotExist: # Incident hasn't been saved yet, nothing to do here. return if instance.is_closed() and not prev_state.is_closed(): user_to_notify = instance.lead or instance.reporter doc_url = urljoin( settings.SITE_URL, reverse("incident_doc", kwargs={"incident_id": instance.pk}), ) settings.SLACK_CLIENT.send_message( user_to_notify.external_id, f"👋 Don't forget to fill out an incident report <https://signal-ai.getoutline.com/doc/incident-logbook-wL5JK4hyTr|on the wiki>. The <{doc_url}|incident doc> may help with that.", )
def remind_update(incident: Incident): update = StatusUpdate.objects.filter( incident=incident).order_by("timestamp").first() if update is not None: if update.timestamp < datetime.datetime.now() - datetime.timedelta( minutes=60): logger.info("The last update was over 1h ago") try: comms_channel = CommsChannel.objects.get(incident=incident) if not incident.is_closed(): user_to_notify = incident.lead settings.SLACK_CLIENT.send_ephemeral_message( comms_channel.channel_id, user_to_notify.external_id, "The last update was over 1h ago. To provide a new update use the command:\n `/%s update [text]`" % settings.SLACK_SLASH_COMMAND, ) except CommsChannel.DoesNotExist: pass else: logger.info("The last update is not older than 60 minutes")