Example #1
0
    def get(self,
            incident_type: str,
            incident_priority: str,
            incident_description: str,
            db_session=None):
        """Fetches participants from Dispatch."""
        route_in = {
            "text": incident_description,
            "context": {
                "incident_priorities": [incident_priority.__dict__],
                "incident_types": [incident_type.__dict__],
                "terms": [],
            },
        }

        route_in = RouteRequest(**route_in)
        recommendation = route_service.get(db_session=db_session,
                                           route_in=route_in)

        log.debug(f"Recommendation: {recommendation}")
        # we need to resolve our service contacts to individuals
        for s in recommendation.service_contacts:
            p = plugins.get(s.type)
            log.debug(f"Resolving service contact. ServiceContact: {s}")
            individual_email = p.get(s.external_id)

            individual = individual_service.get_or_create(
                db_session=db_session, email=individual_email)
            recommendation.individual_contacts.append(individual)

        db_session.commit()
        return list(recommendation.individual_contacts), list(
            recommendation.team_contacts)
Example #2
0
    def get(
        self,
        incident_type: IncidentType,
        incident_priority: IncidentPriority,
        incident_description: str,
        project: Project,
        db_session=None,
    ):
        """Fetches participants from Dispatch."""
        route_in = {
            "text": incident_description,
            "context": {
                "incident_priorities": [incident_priority],
                "incident_types": [incident_type],
                "terms": [],
                "project": project,
            },
        }

        route_in = RouteRequest(**route_in)
        recommendation = route_service.get(db_session=db_session,
                                           route_in=route_in)

        log.debug(f"Recommendation: {recommendation}")
        individual_contacts = [(x, None)
                               for x in recommendation.individual_contacts]
        # we need to resolve our service contacts to individuals
        for s in recommendation.service_contacts:
            plugin_instance = plugin_service.get_active_instance_by_slug(
                db_session=db_session, slug=s.type, project_id=project.id)

            if plugin_instance:
                if plugin_instance.enabled:
                    log.debug(
                        f"Resolving service contact. ServiceContact: {s}")
                    individual_email = plugin_instance.instance.get(
                        s.external_id)

                    individual = individual_service.get_or_create(
                        db_session=db_session, email=individual_email)
                    individual_contacts.append((individual, s))
                    recommendation.individual_contacts.append(individual)
                else:
                    log.warning(
                        f"Skipping service contact. Service: {s.name} Reason: Associated service plugin not enabled."
                    )
            else:
                log.warning(
                    f"Skipping service contact. Service: {s.name} Reason: Associated service plugin not found."
                )

        db_session.commit()
        return list(individual_contacts), list(recommendation.team_contacts)
Example #3
0
    def get(self,
            incident_type: str,
            incident_priority: str,
            incident_description: str,
            db_session=None):
        """Fetches documents from Dispatch."""
        route_in = {
            "text": incident_description,
            "context": {
                "incident_priorities": [incident_priority],
                "incident_types": [incident_type],
                "terms": [],
            },
        }

        route_in = RouteRequest(**route_in)
        recommendation = route_service.get(db_session=db_session,
                                           route_in=route_in)
        return recommendation.documents