Beispiel #1
0
 def add_member(self, e):
     """Add a new member to the conference"""
     self.last_event = e
     self.conf_size = int(getUnquotedHeader(e, 'Conference-Size')) # Adjust the conference size
     confObj = Session.query(Conference).get(getUnquotedHeader(self.last_event, 'Conference-Unique-ID'))
     if confObj is None:
         try:
             owner = Session.query(ModeratorPin).get(self.conf_name)
         except Exception, err:
             self.log.exception("Could not obtain owner.")
             Session.remove()
             return
         if owner is None:
             self.log.warning('Error because we could not get owner.')
             Session.remove()
             return
         self.log.debug('Conference does not exist, we must create one.')
         self.log.info('Creating a new conference for conference id: %s' % self.conf_uuid)
         confObj = Conference(self.conf_uuid, parseEventDate(e), unicode(self.conf_name), unicode(self.conf_profile))
         owner.conferences.append(confObj)
         Session.add(confObj)
         Session.commit()
         Session.remove()
         self.addAction(e)
         self.log.debug('Conference %s has been created. Assigning the pointer.' % self.conf_name)
         return
Beispiel #2
0
 def del_member(self, e):
     """Remove members from the conference"""
     self.last_event = e
     self.conf_size = int(getUnquotedHeader(e, 'Conference-Size')) # Adjust the conference size
     self.addAction(e)
     confObj = Session.query(Conference).get(getUnquotedHeader(e, 'Conference-Unique-ID'))
     if confObj is None:
         self.log.debug('Conference does not exist on DB, we must create one.')
         owner = Session.query(ModeratorPin).get(getUnquotedHeader(e, 'Conference-Name'))
         if owner is None:
             self.log.warning('Error because we could not get owner.')
             Session.remove()
             return
         
         self.log.info('Creating a new conference for conference id: %s' % getUnquotedHeader(last_event, 'Conference-Unique-ID'))
         confObj = Conference(getUnquotedHeader(last_event, 'Conference-Unique-ID'), parseEventDate(last_event), unicode(getUnquotedHeader(last_event, 'Conference-Name')), unicode(getUnquotedHeader(last_event, 'Conference-Profile-Name')))
         owner.conferences.append(confObj)
         Session.add(confObj)
         Session.flush()
     if self.conf_size == 0:
         confObj.ended = parseEventDate(e)
         try:
             self.log.debug("Conference %s has ended. Removing session %s." % (self.conf_name, Session))
             Session.commit()
         except Exception, e:
             Session.rollback()
             Session.remove()
             self.log.exception('Could not commit to the DB.')
             return
Beispiel #3
0
def main(config):
    configureLogging(config)
    log = logging.getLogger('main')
    log.info('Starting conf_tracker version %s.', pkg_resources.require('conf_tracker')[0].version)
    if config.getboolean('daemon', 'daemon'):
        pidfile = config.get('daemon', 'pidfile')
        daemonize(pidfile)
        
    
    pw = config.get('host', 'password')
    h = config.get('host', 'host')
    p = config.get('host', 'port')
    
    #Setting up the DB connection
    log.info('Connecting to DB on: %s ' % (config.get('database', 'url')))

    if ("sqlite" in config.get('database', 'url')):
        engine = create_engine( config.get('database', 'url'), poolclass=NullPool )
        log.warning('You are using SQLite and we will use NullPool as pooling engine.')
    else:
        engine = create_engine( config.get('database', 'url'), pool_recycle=3600 )


    #meta.Session = sessionmaker( autoflush=False, autocommit=False, bind=engine)
    meta.Session.configure(bind=engine)
    
    con = connect(h, p, pw)
    conferences = {}
    while True:
        while not con.connected():
            log.warning("On main loop retrying...")
            con = connect(h, p, pw)
            
        e = con.recvEventTimed(5000)

        if e is None:
            continue

        conf_uuid = getUnquotedHeader(e, 'Conference-Unique-ID')
        action = getUnquotedHeader(e, 'Action')
        conf_size = getUnquotedHeader(e, 'Conference-Size')
        
        if action == 'stop-recording':
            try:
                TrackerConference.stop_recording(e, config)
                continue
            except Exception, e:
                log.exception('An error has occurred while executing stop-recording!')
                continue
        
        if conf_uuid not in conferences.keys():
            try:
                conf = TrackerConference(e, config)
                conferences[conf_uuid] = conf
            except Exception, e:
                log.exception('An error occured creating a new conference object! Continuing...')
                continue
Beispiel #4
0
def main(config):
            
    configureLogging(config)
    log = logging.getLogger('main')
    
    if config.getboolean('daemon', 'daemon'):
        pidfile = config.get('daemon', 'pidfile')
        daemonize(pidfile)
        
    
    pw = config.get('host', 'password')
    h = config.get('host', 'host')
    p = config.get('host', 'port')
    
    #Setting up the DB connection
    log.info('Connecting to DB on: %s ' % (config.get('database', 'url')))

    if ("sqlite" in config.get('database', 'url')):
        engine = create_engine( config.get('database', 'url'), poolclass=NullPool )
        log.warning('You are using SQLite and we will use NullPool as pooling engine.')
    else:
        engine = create_engine( config.get('database', 'url'), pool_recycle=3600 )


    Session = sessionmaker( autoflush=False, autocommit=False, bind=engine)
    
    log.info('Connecting to: %s:%s ' % (h, p))
    con = ESLconnection(h, p, pw)
    con.events('plain', 'CUSTOM conference::maintenance')
    conferences = {}
    while con.connected():
        e = con.recvEvent()

        if e is None:
            continue
            

        conf_uuid = getUnquotedHeader(e, 'Conference-Unique-ID')
        action = getUnquotedHeader(e, 'Action')
        conf_size = getUnquotedHeader(e, 'Conference-Size')
        
        if action == 'stop-recording':
            try:
                TrackerConference.stop_recording(e, config, Session())
                continue
            except Exception, e:
                log.critical('An error has occurred while executing stop-recording!\n%s' % traceback.format_exc())
                continue
        
        if conf_uuid not in conferences.keys():
            try:
                conf = TrackerConference(e, config, Session())
                conferences[conf_uuid] = conf
            except Exception, e:
                log.warning('An error occured creating a new conference object! Continuing... \n%s' % e)
                continue
Beispiel #5
0
 def __init__(self, last_event, config):
     self.log = logging.getLogger('Conference')
     self.last_event = last_event
     self.config = config
     self.conf_size = getUnquotedHeader(self.last_event, 'Conference-Size')
     self.conf_name = getUnquotedHeader(self.last_event, 'Conference-Name')
     self.conf_profile = getUnquotedHeader(self.last_event, 'Conference-Profile-Name')
     self.conf_uuid = getUnquotedHeader(self.last_event, 'Conference-Unique-ID')
                 
     self.confObj = Session.query(Conference).get(getUnquotedHeader(self.last_event, 'Conference-Unique-ID'))
     if self.confObj is None:
         self.log.debug('Conference does not exist on DB, we must create one.')
         owner = Session.query(ModeratorPin).get(getUnquotedHeader(last_event, 'Conference-Name'))
         if owner is None:
             self.log.warning('Error because we could not get owner.')
             Session.remove()
             return
         
         self.log.info('Creating a new conference for conference id: %s' % getUnquotedHeader(last_event, 'Conference-Unique-ID'))
         confObj = Conference(getUnquotedHeader(last_event, 'Conference-Unique-ID'), parseEventDate(last_event), unicode(getUnquotedHeader(last_event, 'Conference-Name')), unicode(getUnquotedHeader(last_event, 'Conference-Profile-Name')))
         owner.conferences.append(confObj)
         Session.add(confObj)
         Session.flush()
     
     Session.remove()    
Beispiel #6
0
 def addAction(self, e):
     """Create and add a new action to the DB"""
     self.log.debug('Action taken on %s. %s' % (self.conf_name, getUnquotedHeader(e, 'Action')))
     confObj = Session.query(Conference).get(getUnquotedHeader(self.last_event, 'Conference-Unique-ID'))
     if confObj is None:
         self.log.warning("Conference does not exist, so we can't add this action to the DB.")
         return
         
     actionObj = ConferenceAction(getUnquotedHeader(e, 'Action'), 
                                 getUnquotedHeader(e, 'Caller-Caller-ID-Name'),
                                 getUnquotedHeader(e, 'Caller-Caller-ID-Number'),
                                 self.conf_size,
                                 getUnquotedHeader(e, 'Member-Type'),
                                 parseEventDate(e),
                                 self.conf_uuid)
     confObj.actions.append(actionObj)
     Session.add(actionObj)
     Session.commit()
     Session.remove()
Beispiel #7
0
 def stop_recording(e, config):
     """Process the process of recording being stopped"""
     log = logging.getLogger('Conference')
     
     owner = Session.query(ModeratorPin).get(getUnquotedHeader(e, 'Conference-Name'))
     if owner is None:
         log.warning('Error because we could not get owner.')
         Session.remove()
         return
     
     confObj = Session.query(Conference).get(getUnquotedHeader(e, 'Conference-Unique-ID'))
     if confObj is None:
         log.info('Creating a new conference for conference id: %s' % getUnquotedHeader(e, 'Conference-Unique-ID'))
         confObj = Conference(getUnquotedHeader(e, 'Conference-Unique-ID'), parseEventDate(e), unicode(getUnquotedHeader(e, 'Conference-Name')), unicode(getUnquotedHeader(e, 'Conference-Profile-Name')))
         owner.conferences.append(confObj)
         Session.add(confObj)
         Session.flush()
         actionObj = ConferenceAction(unicode(getUnquotedHeader(e, 'Action')), 
                                     unicode(getUnquotedHeader(e, 'Caller-Caller-ID-Name')),
                                     unicode(getUnquotedHeader(e, 'Caller-Caller-ID-Number')),
                                     unicode(getUnquotedHeader(e, 'Conference-Size')),
                                     unicode(getUnquotedHeader(e, 'Member-Type')),
                                     parseEventDate(e),
                                     confObj.id)
         confObj.actions.append(actionObj)
         Session.add(actionObj)
         log.debug('Conference %s has been created. Assigning the pointer.' % getUnquotedHeader(e, 'Conference-Name'))
         
     confObj.recording = os.path.join(config.get('mp3', 'store_to'), getUnquotedHeader(e, 'Path').split('/').pop()[:-3] + 'mp3')
     host = unicode(getUnquotedHeader(e, 'FreeSWITCH-IPv4'))
         
     try:
         try:
             t = Thread(target=postRecordingThread, args=(config, getUnquotedHeader(e, 'Path'), confObj, host, owner))
             t.start()
         except:
             log.exception('Could not run thread and commit to database!')
             Session.remove()
             return
     finally:
         try:
             sendEmail(config, getUnquotedHeader(e, 'Path'), confObj, owner)
             Session.commit()
             Session.remove()
         except Exception, e:
             log.exception('Could not commit to database!')
             Session.rollback()
             Session.remove()
             return