Exemple #1
0
def report_incident(user_id: str, channel_id: str, submission: json,
                    response_url: str, state: json):
    report = submission['report']
    summary = submission['summary']
    impact = submission['impact']
    lead_id = submission['lead']
    severity = submission['severity']

    name = get_user_profile(user_id)['name']
    reporter = GetOrCreateSlackExternalUser(external_id=user_id,
                                            display_name=name)

    lead = None
    if lead_id:
        lead_name = get_user_profile(lead_id)['name']
        lead = GetOrCreateSlackExternalUser(external_id=lead_id,
                                            display_name=lead_name)

    Incident.objects.create_incident(
        report=report,
        reporter=reporter,
        report_time=datetime.now(),
        summary=summary,
        impact=impact,
        lead=lead,
        severity=severity,
    )

    incidents_channel_ref = channel_reference(settings.INCIDENT_CHANNEL_ID)
    text = f"Thanks for raising the incident 🙏\n\nHead over to {incidents_channel_ref} to complete the report and/or help deal with the issue"
    send_ephemeral_message(channel_id, user_id, text)
Exemple #2
0
def set_action(incident: Incident, user_id: str, message: str):
    comms_channel = CommsChannel.objects.get(incident=incident)
    name = get_user_profile(user_id)['name']
    action_reporter = GetOrCreateSlackExternalUser(external_id=user_id,
                                                   display_name=name)
    Action(incident=incident, details=message, user=action_reporter).save()
    return True, None
Exemple #3
0
def edit_incident(user_id: str, channel_id: str, submission: json,
                  response_url: str, state: json):
    report = submission['report']
    summary = submission['summary']
    impact = submission['impact']
    lead_id = submission['lead']
    severity = submission['severity']

    lead = None
    if lead_id:
        lead_name = get_user_profile(lead_id)['name']
        lead = GetOrCreateSlackExternalUser(external_id=lead_id,
                                            display_name=lead_name)

    try:
        incident = Incident.objects.get(pk=state)

        # deliberately update in this way the post_save signal gets sent
        # (required for the headline post to auto update)
        incident.report = report
        incident.summary = summary
        incident.impact = impact
        incident.lead = lead
        incident.severity = severity
        incident.save()

    except Incident.DoesNotExist:
        logger.error(f"No incident found for pk {state}")
Exemple #4
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 = GetOrCreateSlackExternalUser(external_id=assignee,
                                        display_name=name)
    incident.lead = user
    incident.save()
    return True, None
Exemple #5
0
    def increment_message_count(incident, user_id):
        name = get_user_profile(user_id)['name']
        user = GetOrCreateSlackExternalUser(external_id=user_id, display_name=name)

        user_stats, created = UserStats.objects.get_or_create(incident=incident, user=user)

        if created:
            user_stats.join_time = datetime.now()

        user_stats.message_count += 1
        user_stats.save()
Exemple #6
0
    def add_pin(self, incident, message_ts, author_id, text):
        name = get_user_profile(author_id)['name']
        author = GetOrCreateSlackExternalUser(external_id=author_id,
                                              display_name=name)

        PinnedMessage.objects.get_or_create(incident=incident,
                                            message_ts=message_ts,
                                            defaults={
                                                'author':
                                                author,
                                                'text':
                                                text,
                                                'timestamp':
                                                datetime.fromtimestamp(
                                                    float(message_ts)),
                                            })
Exemple #7
0
def PopulateExternalUser(apps, schema_editor):
    Incident = apps.get_model('core', 'Incident')
    ExternalUser = apps.get_model('core', 'ExternalUser')

    UserStats = apps.get_model('slack', 'UserStats')
    PinnedMessage = apps.get_model('slack', 'PinnedMessage')

    user_id_list = [ x['userid'] for x in Incident.objects.all().values(userid=F('reporter'))
                  .union(Incident.objects.all().values(userid=F('lead')))
                  .union(UserStats.objects.all().values(userid=F('user_id')))
                  .union(PinnedMessage.objects.all().values(userid=F('author_id'))) if x['userid'] ]

    for user_id in user_id_list:
        ExternalID, created = ExternalUser.objects.get_or_create(app_id='slack',
                                                                   external_id=user_id,
                                                                   display_name=get_user_profile(user_id)['name'])
        ExternalID.save()
Exemple #8
0
def slack_id_to_fullname(value):
    profile = get_user_profile(value)
    if profile:
        return profile['fullname']