Beispiel #1
0
def build_tag_models(db_session=None):
    """Builds the intensive tag recommandation models."""
    # incident model
    incidents = incident_service.get_all(db_session=db_session).all()
    log.debug("Starting to build the incident/tag model...")
    build_model(incidents, "incident")
    log.debug("Successfully built the incident/tag model.")
Beispiel #2
0
def build_tag_models(db_session: SessionLocal, project: Project):
    """Builds the intensive tag recommendation models."""
    # incident model
    incidents = incident_service.get_all(db_session=db_session,
                                         project_id=project.id).all()
    log.debug("Starting to build the incident/tag model for ...")
    build_model(incidents, project.organization.slug, project.slug, "incident")
    log.debug("Successfully built the incident/tag model.")
Beispiel #3
0
def calculate_incidents_response_cost(db_session=None):
    """
    Calculates and saves the response cost for all incidents.
    """
    for project in project_service.get_all(db_session=db_session):
        response_cost_type = incident_cost_type_service.get_default(
            db_session=db_session, project_id=project.id)
        if response_cost_type is None:
            log.warning(
                f"A default cost type for response cost does not exist in the {project.name} project. Response costs won't be calculated."
            )
            continue

        # we want to update the response cost of all incidents, all the time
        incidents = incident_service.get_all(db_session=db_session,
                                             project_id=project.id)
        for incident in incidents:
            try:
                # we get the response cost for the given incident
                incident_response_cost = get_by_incident_id_and_incident_cost_type_id(
                    db_session=db_session,
                    incident_id=incident.id,
                    incident_cost_type_id=response_cost_type.id,
                )

                if incident_response_cost is None:
                    # we create the response cost if it doesn't exist
                    incident_cost_type = IncidentCostTypeRead.from_orm(
                        response_cost_type)
                    incident_cost_in = IncidentCostCreate(
                        incident_cost_type=incident_cost_type, project=project)
                    incident_response_cost = create(
                        db_session=db_session,
                        incident_cost_in=incident_cost_in)

                # we calculate the response cost amount
                amount = calculate_incident_response_cost(
                    incident.id, db_session)

                # we don't need to update the cost amount if it hasn't changed
                if incident_response_cost.amount == amount:
                    continue

                # we save the new incident cost amount
                incident_response_cost.amount = amount
                incident.incident_costs.append(incident_response_cost)
                db_session.add(incident)
                db_session.commit()

                log.debug(
                    f"Response cost amount for {incident.name} incident has been updated in the database."
                )

            except Exception as e:
                # we shouldn't fail to update all incidents when one fails
                log.exception(e)
Beispiel #4
0
def daily_sync_workflow(db_session: SessionLocal, project: Project):
    """Syncs all incident workflows daily."""
    workflow_plugin = plugin_service.get_active_instance(
        db_session=db_session, project_id=project.id, plugin_type="workflow")
    if not workflow_plugin:
        log.warning(f"No workflow plugin is enabled. ProjectId: {project.id}")
        return

    incidents = incident_service.get_all(db_session=db_session,
                                         project_id=project.id).all()
    sync_workflows(db_session,
                   project,
                   workflow_plugin,
                   incidents,
                   notify=False)
Beispiel #5
0
def daily_sync_task(db_session: SessionLocal, project: Project):
    """Syncs all incident tasks daily."""
    incidents = incident_service.get_all(db_session=db_session,
                                         project_id=project.id).all()
    task_plugin = plugin_service.get_active_instance(db_session=db_session,
                                                     project_id=project.id,
                                                     plugin_type="task")

    if not task_plugin:
        log.warning(
            f"Skipping task sync no task plugin enabled. ProjectId: {project.id}"
        )
        return

    lookback = 60 * 60 * 24  # 24hrs
    sync_tasks(db_session,
               task_plugin,
               incidents,
               lookback=lookback,
               notify=False)
Beispiel #6
0
def daily_sync_workflow(db_session=None):
    """Syncs all incident workflows daily."""
    incidents = incident_service.get_all(db_session=db_session).all()
    sync_workflows(db_session, incidents, notify=False)
Beispiel #7
0
def daily_sync_task(db_session=None):
    """Syncs all incident tasks daily."""
    incidents = incident_service.get_all(db_session=db_session).all()
    sync_tasks(db_session, incidents, notify=False)
Beispiel #8
0
def daily_sync_workflow(db_session=None):
    """Syncs all incident workflows daily."""
    for project in project_service.get_all(db_session=db_session):
        incidents = incident_service.get_all(db_session=db_session,
                                             project_id=project.id).all()
        sync_workflows(db_session, incidents, notify=False)