Beispiel #1
0
def update_impact(incident: Incident, user_id: str, message: str):
    # Easy case. No impact currently and one has been provided
    if message and not incident.impact:
        incident.impact = message
        incident.save()
        return True, f"{IMPACT_UPDATED_TITLE}{message}"

    # Either no new impact has been provided, or one already exists
    msg = block_kit.Message()
    msg.add_block(
        block_kit.Section(
            block_id="update",
            text=block_kit.Text(
                f"{CURRENT_TITLE}{incident.impact or NO_IMPACT_TEXT}"),
            accessory=block_kit.Button(CHANGE_BUTTON_TEXT,
                                       UPDATE_CURRENT_IMPACT_ACTION,
                                       value=incident.pk),
        ))

    # if the user has supplied a message, provide the option for them to set it without
    # retyping in the dialog
    if message:
        msg.add_block(
            block_kit.Section(
                block_id=PROPOSED_MESSAGE_BLOCK_ID,
                text=block_kit.Text(f"{PROPOSED_TITLE}{message}"),
                accessory=block_kit.Button(ACCEPT_PROPOSED_TEXT,
                                           SET_NEW_IMPACT_ACTION,
                                           value=incident.pk),
            ))

    comms_channel = CommsChannel.objects.get(incident=incident)
    msg.send(comms_channel.channel_id)
    return True, None
Beispiel #2
0
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, _ = ExternalUser.objects.get_or_create_slack(external_id=assignee,
                                                       display_name=name)
    incident.lead = user
    incident.save()
    return True, None
Beispiel #3
0
def set_incident_lead(incident: Incident, user_id: str, message: str):
    assignee = reference_to_id(message) or user_id
    name = settings.SLACK_CLIENT.get_user_profile(assignee)['name']
    user = GetOrCreateSlackExternalUser(external_id=assignee,
                                        display_name=name)
    incident.lead = user
    incident.save()
    return True, None
Beispiel #4
0
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
Beispiel #5
0
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.lower()) or (sev_id in message.lower()):
            incident.severity = sev_id
            incident.save()
            return add_status_update(
                incident, user_id,
                'Severity updated to ' + incident.severity_text())

    return False, None
Beispiel #6
0
def set_incident_lead(incident: Incident, user_id: str, message: str):
    assignee = get_user_profile_by_name(message)

    name = assignee['name']
    print(name)
    user, _ = ExternalUser.objects.get_or_create_slack(
        external_id=assignee['id'], display_name=name)
    incident.lead = user
    incident.save()
    return add_status_update(incident, user_id,
                             'New lead is ' + incident.lead.full_name)
Beispiel #7
0
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
Beispiel #8
0
def update_impact(incident: Incident, user_id: str, message: str):
    incident.impact = message
    incident.save()
    return True, None
Beispiel #9
0
def update_summary(incident: Incident, user_id: str, message: str):
    incident.summary = message
    incident.save()
    return True, None
Beispiel #10
0
def mitigate_incident(incident: Incident, user_id: str, message: str):
    incident.mitigated = True
    incident.save()
    return add_status_update(incident, user_id,
                             'Status changed to Mitigated - ' + message)