def dispatch(self, request, *args, **kwargs): agente_profile = self.request.user.get_agente_profile() agent_login_manager = AgentActivityAmiManager() agent_login_manager.logout_agent(agente_profile, manage_connection=True) logout(request) return redirect('login')
def post(self, request, *args, **kwargs): agent_login_manager = AgentActivityAmiManager() agente_profile = self.request.user.get_agente_profile() queue_remove_error, insert_astdb_error = agent_login_manager.logout_agent(agente_profile) if insert_astdb_error or queue_remove_error: return Response(data={ 'status': 'ERROR', }) else: return Response(data={ 'status': 'OK', })
def post(self, request): agent_login_manager = AgentActivityAmiManager() agente_profile = self.request.user.get_agente_profile() error = agent_login_manager.login_agent(agente_profile) if error: return Response(data={ 'status': 'ERROR', }) else: return Response(data={ 'status': 'OK', })
def post(self, request): agent_login_manager = AgentActivityAmiManager() pause_id = request.data.get('pause_id') agente_profile = self.request.user.get_agente_profile() queue_pause_error, insert_astdb_error = agent_login_manager.unpause_agent( agente_profile, pause_id) if queue_pause_error or insert_astdb_error: return Response(data={ 'status': 'ERROR', }) else: return Response(data={ 'status': 'OK', })
def post(self, request, *args, **kwargs): agente_profile = self.request.user.get_agente_profile() agent_login_manager = AgentActivityAmiManager() ringing = request.POST.get('ringing') == 'true' insert_redis_error = agent_login_manager.set_agent_ringing( agente_profile, ringing) if insert_redis_error: return Response(data={ 'status': 'ERROR', }) else: return Response(data={ 'status': 'OK', })
def logout_expired_sessions(self): agentes_deslogueados = [] agent_activity = AgentActivityAmiManager() conectado = False hora_actual = now() for agente_profile in AgenteProfile.objects.obtener_activos(): session = None if agente_profile.user.last_session_key: try: session = Session.objects.get( session_key=agente_profile.user.last_session_key) except Session.DoesNotExist: pass if session and session.expire_date < hora_actual: if not conectado: agent_activity.connect_manager() conectado = True agentes_deslogueados.append(str(agente_profile.id)) agente_profile.force_logout() agent_activity.logout_agent(agente_profile, manage_connection=False) if conectado: agent_activity.disconnect_manager() if agentes_deslogueados: logger.info("Expired Sessions detected: " + str(agentes_deslogueados))
def logout_expired_sessions(self): agentes_deslogueados = [] agent_activity = AgentActivityAmiManager() hora_actual = now() for agente_profile in AgenteProfile.objects.all(): session = None if agente_profile.user.last_session_key: try: session = Session.objects.get( session_key=agente_profile.user.last_session_key) except Session.DoesNotExist: pass if session and session.expire_date < hora_actual: agentes_deslogueados.append(str(agente_profile.id)) agente_profile.force_logout() agent_activity.logout_agent(agente_profile) if agentes_deslogueados: logger.info("Expired Sessions detected: " + str(agentes_deslogueados))
def ejecutar_accion_sobre_agente(self, supervisor, agente_id, exten): agente_profile = AgenteProfile.objects.get(id=agente_id) agent_activity = AgentActivityAmiManager() supervisor_activity = SupervisorActivityAmiManager() if exten not in self.EXTENSIONES: return _("La acción indicada no existe") channel = "PJSIP/{0}".format(supervisor.sip_extension) channel_vars = { 'OMLAGENTID': str(agente_id), } originate_data = [channel, exten, 'oml-sup-actions', channel_vars] # Genero la llamada via originate por AMI if exten == "AGENTLOGOUT": agente_profile.force_logout() agent_activity.logout_agent(agente_profile) elif exten == "AGENTPAUSE": agent_activity.pause_agent(agente_profile, '00') elif exten == "AGENTUNPAUSE": agent_activity.unpause_agent(agente_profile, '00') else: supervisor_activity.originate_call(originate_data)
def __init__(self, *args, **kwargs): self.manager = AMIManagerConnector() self.agent_activity = AgentActivityAmiManager()
class SupervisorActivityAmiManager(object): EXTENSIONES = [ "AGENTLOGOUT", "AGENTUNPAUSE", "AGENTPAUSE", "CHANTAKECALL", "CHANSPYWISHPER", "CHANSPY", "CHANCONFER" ] def __init__(self, *args, **kwargs): self.manager = AMIManagerConnector() self.agent_activity = AgentActivityAmiManager() def _originate_call(self, originate_data): self.manager.connect() content = originate_data data_returned = self.manager._ami_manager('originate', content) self.manager.disconnect() return data_returned def obtener_agentes_activos(self): agentes_parseados = AgentesParsing() agentes_activos = [] self.manager.connect() data_returned, error = self.manager._ami_manager( "command", "database show OML/AGENT") self.manager.disconnect() agentes_activos = agentes_parseados._parsear_datos_agentes( data_returned) return agentes_activos def ejecutar_accion_sobre_agente(self, supervisor, agente_id, exten): agente_profile = AgenteProfile.objects.get(id=agente_id) if exten not in self.EXTENSIONES: return _("La acción indicada no existe") channel = "PJSIP/{0}".format(supervisor.sip_extension) channel_vars = { 'OMLAGENTID': str(agente_id), } originate_data = [channel, exten, 'oml-sup-actions', channel_vars] # Genero la llamada via originate por AMI if exten == "AGENTLOGOUT": agente_profile.force_logout() self.agent_activity.logout_agent(agente_profile, manage_connection=True) elif exten == "AGENTPAUSE": self.agent_activity.pause_agent(agente_profile, '00', manage_connection=True) elif exten == "AGENTUNPAUSE": self.agent_activity.unpause_agent(agente_profile, '00', manage_connection=True) else: self._originate_call(originate_data) def escribir_agentes_unavailable_astdb(self): """ Abre una conexion para setear a los agentes como UNAVAILABLE en ASTDB """ self.agent_activity.connect_manager() agentes_profiles = [] # Nota: Accedo al manager del agent_activity para no crear otra conexion user_activity_list, error = self.agent_activity.manager._ami_manager( 'command', 'queue show') for activity_line in user_activity_list.splitlines(): if activity_line.find("Unavailable") != -1: fields_activity = activity_line.split() agente_id = fields_activity[1].split('_')[0] agente_profile = AgenteProfile.objects.get(id=agente_id) if agente_profile not in agentes_profiles: agentes_profiles.append(agente_profile) if agentes_profiles: for agente_profile in agentes_profiles: self.agent_activity.set_agent_as_unavailable( agente_profile, manage_connection=False) self.agent_activity.disconnect_manager()
class SupervisorActivityAmiManager(object): EXTENSIONES = [ "AGENTLOGOUT", "AGENTUNPAUSE", "AGENTPAUSE", "CHANTAKECALL", "CHANSPYWISHPER", "CHANSPY", "CHANCONFER" ] def __init__(self, *args, **kwargs): self.manager = AMIManagerConnector() self.agent_activity = AgentActivityAmiManager() def _originate_call(self, originate_data): self.manager.connect() content = originate_data data_returned = self.manager._ami_manager('originate', content) self.manager.disconnect() return data_returned def obtener_agentes_activos(self): agentes_activos = [] redis_connection = redis.Redis( host=settings.REDIS_HOSTNAME, port=settings.CONSTANCE_REDIS_CONNECTION['port'], decode_responses=True) # TODO: cambiar a usar el metodo 'scan' que es mas eficiente con datos muy grandes # y realiza una especie de paginación keys_agentes = redis_connection.keys('OML:AGENT*') agentes_activos = [] for key in keys_agentes: agente_info = redis_connection.hgetall(key) status = agente_info.get('STATUS', '') id_agente = key.split(':')[-1] if status != '' and len(agente_info) >= LONGITUD_MINIMA_HEADERS: agente_info['nombre'] = agente_info['NAME'] agente_info['status'] = status agente_info['sip'] = agente_info['SIP'] agente_info['pause_id'] = agente_info.get('PAUSE_ID', '') agente_info['campana_llamada'] = agente_info.get( 'CAMPAIGN', '') agente_info['contacto'] = agente_info.get('CONTACT_NUMBER', '') tiempo_actual = int(time()) tiempo_estado = tiempo_actual - int(agente_info['TIMESTAMP']) agente_info['tiempo'] = tiempo_estado del agente_info['NAME'] del agente_info['STATUS'] del agente_info['TIMESTAMP'] del agente_info['SIP'] agente_info['id'] = int(id_agente) agentes_activos.append(agente_info) return agentes_activos def ejecutar_accion_sobre_agente(self, supervisor, agente_id, exten): agente_profile = AgenteProfile.objects.get(id=agente_id) if exten not in self.EXTENSIONES: return _("La acción indicada no existe") channel = "PJSIP/{0}".format(supervisor.sip_extension) channel_vars = { 'OMLAGENTID': str(agente_id), } originate_data = [channel, exten, 'oml-sup-actions', channel_vars] # Genero la llamada via originate por AMI if exten == "AGENTLOGOUT": agente_profile.force_logout() self.agent_activity.logout_agent(agente_profile, manage_connection=True) elif exten == "AGENTPAUSE": self.agent_activity.pause_agent(agente_profile, '00', manage_connection=True) elif exten == "AGENTUNPAUSE": self.agent_activity.unpause_agent(agente_profile, '00', manage_connection=True) else: self._originate_call(originate_data) def escribir_estado_agentes_unavailable(self): """ Busca en el queue de Asterisk si hay agentes Unavailable para reportarlo en Redis""" self.manager.connect() user_activity_list, error = self.manager._ami_manager( 'command', 'queue show') self.manager.disconnect() agentes_profiles = [] for activity_line in user_activity_list.splitlines(): if activity_line.find("Unavailable") != -1: fields_activity = activity_line.split() agente_id = fields_activity[1].split('_')[0] agente_profile = AgenteProfile.objects.get(id=agente_id) if agente_profile not in agentes_profiles: agentes_profiles.append(agente_profile) if agentes_profiles: for agente_profile in agentes_profiles: self.agent_activity.set_agent_as_unavailable(agente_profile)