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)
def get( self, incident: Incident, db_session=None, ): """Fetches documents from Dispatch.""" recommendation = route_service.get(db_session=db_session, incident=incident, models=[(Document, DocumentRead)]) return recommendation.matches
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)
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
def get( self, incident: Incident, db_session=None, ): """Fetches participants from Dispatch.""" models = [ (IndividualContact, IndividualContactRead), (Service, ServiceRead), (TeamContact, TeamContactRead), ] recommendation = route_service.get(db_session=db_session, incident=incident, models=models) log.debug(f"Recommendation: {recommendation}") individual_contacts = [] team_contacts = [] for match in recommendation.matches: if match.resource_type == TeamContact.__name__: team = team_service.get_or_create( db_session=db_session, email=match.resource_state["email"], incident=incident) team_contacts.append(team) if match.resource_type == IndividualContact.__name__: individual = individual_service.get_or_create( db_session=db_session, email=match.resource_state["email"], incident=incident) individual_contacts.append((individual, None)) # we need to do more work when we have a service if match.resource_type == Service.__name__: plugin_instance = plugin_service.get_active_instance_by_slug( db_session=db_session, slug=match.resource_state["type"], project_id=incident.project.id, ) if plugin_instance: if plugin_instance.enabled: log.debug( f"Resolving service contact. ServiceContact: {match.resource_state}" ) # ensure that service is enabled service = service_service.get_by_external_id_and_project_id( db_session=db_session, external_id=match.resource_state["external_id"], project_id=incident.project_id, ) if service.is_active: individual_email = plugin_instance.instance.get( match.resource_state["external_id"]) individual = individual_service.get_or_create( db_session=db_session, email=individual_email, incident=incident) individual_contacts.append( (individual, match.resource_state["id"])) else: log.warning( f"Skipping service contact. Service: {match.resource_state['name']} Reason: Associated service plugin not enabled." ) else: log.warning( f"Skipping service contact. Service: {match.resource_state['name']} Reason: Associated service plugin not found." ) db_session.commit() return individual_contacts, team_contacts