Пример #1
0
def incident_stable_status_flow(incident: Incident, db_session=None):
    """Runs the incident stable flow."""
    # we set the stable time
    incident.stable_at = datetime.utcnow()

    # set time immediately
    db_session.add(incident)
    db_session.commit()

    if incident.incident_review_document:
        log.debug("Incident review document already created... skipping creation.")
        return

    storage_plugin = plugin_service.get_active(db_session=db_session, plugin_type="storage")
    if not storage_plugin:
        log.warning("Incident review document not created, no storage plugin enabled.")
        return

    # we create a copy of the incident review document template and we move it to the incident storage
    incident_review_document_name = f"{incident.name} - Post Incident Review Document"
    template = document_service.get_incident_review_template(db_session=db_session)

    # incident review document is optional
    if not template:
        log.warning("No incident review template specificed.")
        return

    incident_review_document = storage_plugin.instance.copy_file(
        folder_id=incident.storage.resource_id,
        file_id=template.resource_id,
        name=incident_review_document_name,
    )

    incident_review_document.update(
        {
            "name": incident_review_document_name,
            "resource_type": INCIDENT_RESOURCE_INCIDENT_REVIEW_DOCUMENT,
        }
    )

    storage_plugin.instance.move_file(
        new_folder_id=incident.storage.resource_id,
        file_id=incident_review_document["id"],
    )

    event_service.log(
        db_session=db_session,
        source=storage_plugin.title,
        description="Incident review document added to storage",
        incident_id=incident.id,
    )

    document_in = DocumentCreate(
        name=incident_review_document["name"],
        resource_id=incident_review_document["id"],
        resource_type=incident_review_document["resource_type"],
        weblink=incident_review_document["weblink"],
    )
    incident.documents.append(
        document_service.create(db_session=db_session, document_in=document_in)
    )

    event_service.log(
        db_session=db_session,
        source="Dispatch Core App",
        description="Incident review document added to incident",
        incident_id=incident.id,
    )

    # we update the incident review document
    document_plugin = plugin_service.get_active(db_session=db_session, plugin_type="document")
    if document_plugin:
        document_plugin.instance.update(
            incident.incident_review_document.resource_id,
            name=incident.name,
            priority=incident.incident_priority.name,
            status=incident.status,
            type=incident.incident_type.name,
            title=incident.title,
            description=incident.description,
            commander_fullname=incident.commander.name,
            conversation_weblink=resolve_attr(incident, "conversation.weblink"),
            document_weblink=resolve_attr(incident, "incident_document.weblink"),
            storage_weblink=resolve_attr(incident, "storage.weblink"),
            ticket_weblink=resolve_attr(incident, "ticket.weblink"),
            conference_weblink=resolve_attr(incident, "conference.weblink"),
            conference_challenge=resolve_attr(incident, "conference.challendge"),
        )
    else:
        log.warning("No document plugin enabled, could not update template.")

    # we send a notification about the incident review document to the conversation
    send_incident_review_document_notification(
        incident.conversation.channel_id,
        incident.incident_review_document.weblink,
        db_session,
    )

    db_session.add(incident)
    db_session.commit()
Пример #2
0
def incident_stable_flow(incident_id: int,
                         command: Optional[dict] = None,
                         db_session=None):
    """Runs the incident stable flow."""
    # we load the incident instance
    incident = incident_service.get(db_session=db_session,
                                    incident_id=incident_id)

    # we set the stable time
    incident.stable_at = datetime.utcnow()

    # we remind the incident commander to write a tactical report
    send_incident_report_reminder(incident, ReportTypes.tactical_report)

    # we update the external ticket
    update_external_incident_ticket(incident, db_session)

    if not incident.incident_review_document:
        storage_plugin = plugins.get(INCIDENT_PLUGIN_STORAGE_SLUG)

        # we create a copy of the incident review document template and we move it to the incident storage
        incident_review_document_name = f"{incident.name} - Post Incident Review Document"
        template = document_service.get_incident_review_template(
            db_session=db_session)

        # incident review document is optional
        if template:
            incident_review_document = storage_plugin.copy_file(
                folder_id=incident.storage.resource_id,
                file_id=template.resource_id,
                name=incident_review_document_name,
            )

            incident_review_document.update({
                "name":
                incident_review_document_name,
                "resource_type":
                INCIDENT_RESOURCE_INCIDENT_REVIEW_DOCUMENT,
            })

            storage_plugin.move_file(
                new_folder_id=incident.storage.resource_id,
                file_id=incident_review_document["id"],
            )

            event_service.log(
                db_session=db_session,
                source=storage_plugin.title,
                description="Incident review document added to storage",
                incident_id=incident.id,
            )

            document_in = DocumentCreate(
                name=incident_review_document["name"],
                resource_id=incident_review_document["id"],
                resource_type=incident_review_document["resource_type"],
                weblink=incident_review_document["weblink"],
            )
            incident.documents.append(
                document_service.create(db_session=db_session,
                                        document_in=document_in))

            event_service.log(
                db_session=db_session,
                source="Dispatch Core App",
                description="Incident review document added to incident",
                incident_id=incident.id,
            )

            # we update the incident review document
            update_document(
                incident_review_document["id"],
                incident.name,
                incident.incident_priority.name,
                incident.status,
                incident.incident_type.name,
                incident.title,
                incident.description,
                incident.commander.name,
                incident.conversation.weblink,
                incident.incident_document.weblink,
                incident.storage.weblink,
                incident.ticket.weblink,
            )

            # we send a notification about the incident review document to the conversation
            send_incident_review_document_notification(
                incident.conversation.channel_id,
                incident_review_document["weblink"])

    db_session.add(incident)
    db_session.commit()