示例#1
0
 def test_login_success(self):
     isock = InboundEventSocket('127.0.0.1',
                                18021,
                                'ClueCon',
                                eventjson=False)
     try:
         isock.connect()
     except socket.error, se:
         self.fail("socket error: %s" % str(se))
示例#2
0
 def __init__(self,
              host,
              port,
              password,
              filter="ALL",
              log=None,
              cdr_conn=None):
     InboundEventSocket.__init__(self, host, port, password, filter)
     self.log = log
     self.conn = cdr_conn
示例#3
0
def api(cmd, bg=False, ok_check=True):
    global inbound_event_listener
    data = {}
    if not inbound_event_listener:
        inbound_event_listener = InboundEventSocket(conf['host'],
                                                    conf['port'],
                                                    conf['pwd'],
                                                    filter="BACKGROUND_JOB")
    if not inbound_event_listener.connected:
        try:
            inbound_event_listener.connect()
        except ConnectError, e:
            log.error("connect failed: %s" % str(e))
            return {'code': -9, 'msg': 'connect failed !', 'data': data}
示例#4
0
 def __init__(
     self, host, port, password, outbound_address="", auth_id="", auth_token="", log=None, default_http_method="POST"
 ):
     InboundEventSocket.__init__(self, host, port, password, filter=EVENT_FILTER)
     self.fs_outbound_address = outbound_address
     self.log = log
     self.auth_id = auth_id
     self.auth_token = auth_token
     # Mapping of Key: job-uuid - Value: request_uuid
     self.bk_jobs = {}
     # Transfer jobs: call_uuid - Value: inline dptools to execute
     self.xfer_jobs = {}
     # Call Requests
     self.call_requests = {}
     self.default_http_method = default_http_method
示例#5
0
 def __init__(self, host, port, password, 
              outbound_address='', 
              auth_id='', auth_token='', 
              filter="ALL", log=None):
     InboundEventSocket.__init__(self, host, port, password, filter)
     self.fs_outbound_address = outbound_address
     self.log = log
     self.auth_id = auth_id
     self.auth_token = auth_token
     # Mapping of Key: job-uuid - Value: request_uuid
     self.bk_jobs = {}
     # Transfer jobs: call_uuid - Value: where to transfer
     self.xfer_jobs = {}
     # Call Requests 
     self.call_requests = {}
示例#6
0
 def __init__(self,
              host,
              port,
              password,
              filter='ALL',
              pool_size=500,
              connect_timeout=5):
     InboundEventSocket.__init__(self,
                                 host,
                                 port,
                                 password,
                                 filter,
                                 pool_size=pool_size,
                                 connect_timeout=connect_timeout,
                                 eventjson=False)
     self.heartbeat_events = []
     self.re_schedule_events = []
    def __init__(self, server):
        self.server = server
        self.log = self.server.log
        self.cache = self.server.get_cache()

        InboundEventSocket.__init__(self, self.get_server().fs_host,
                                    self.get_server().fs_port,
                                    self.get_server().fs_password,
                                    filter=EVENT_FILTER,
                                    trace=self.get_server()._trace)
        # Mapping of Key: job-uuid - Value: request_uuid
        self.bk_jobs = {}
        # Transfer jobs: call_uuid - Value: inline dptools to execute
        self.xfer_jobs = {}
        # Conference sync jobs
        self.conf_sync_jobs = {}
        # Call Requests
        self.call_requests = {}
    def __init__(self, server):
        self.server = server
        self.log = self.server.log
        self.cache = self.server.get_cache()

        InboundEventSocket.__init__(self, self.get_server().fs_host,
                                    self.get_server().fs_port,
                                    self.get_server().fs_password,
                                    filter=EVENT_FILTER,
                                    trace=self.get_server()._trace)
        # Mapping of Key: job-uuid - Value: request_uuid
        self.bk_jobs = {}
        # Transfer jobs: call_uuid - Value: inline dptools to execute
        self.xfer_jobs = {}
        # Conference sync jobs
        self.conf_sync_jobs = {}
        # Call Requests
        self.call_requests = {}
示例#9
0
 def __init__(self, configfile):
     os.environ['PLIVO_REST_CONFIG'] = configfile
     # create flask app
     self.app = Flask(self.name)
     # load config into flask app
     self.app.config.from_envvar('PLIVO_REST_CONFIG')
     # init logger
     self._init_logger()
     # create rest server
     fs_host, fs_port = self.app.config['FS_INBOUND_ADDRESS'].split(':', 1)
     fs_port = int(fs_port)
     fs_password = self.app.config['FS_PASSWORD']
     InboundEventSocket.__init__(self, fs_host, fs_port, fs_password, filter='ALL')
     # expose api functions to flask app
     for path, func_desc in urls.URLS.iteritems():
         func, methods = func_desc
         fn = getattr(self, func.__name__)
         self.app.add_url_rule(path, func.__name__, fn, methods=methods)
     # create wsgi server
     http_host, http_port = self.app.config['HTTP_ADDRESS'].split(':', 1)
     http_port = int(http_port)
     self.http_server = WSGIServer((http_host, http_port), self.app, log=self.logger)
示例#10
0
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Plivo Team. See LICENSE for details.

from plivo.core.freeswitch.inboundsocket import InboundEventSocket
from plivo.core.errors import ConnectError
from plivo.utils.logger import StdoutLogger

if __name__ == '__main__':
    log = StdoutLogger()
    try:
        inbound_event_listener = InboundEventSocket('127.0.0.1', 8021, 'ClueCon', filter="ALL")
        try:
            inbound_event_listener.connect()
        except ConnectError, e:
            log.error("connect failed: %s" % str(e))
            raise SystemExit('exit')

        filter_response = inbound_event_listener.filter("Event-Name CHANNEL_ANSWER")
        log.info(str(filter_response))
        if not filter_response.is_success():
            log.error("filter failed with response %s" % filter_response.get_response())
            raise SystemExit('exit')

        log.info("filter success with response %s" % filter_response.get_response())

    except (SystemExit, KeyboardInterrupt): pass

    log.info("exit")
# Copyright (c) 2011 Plivo Team. See LICENSE for details.

from plivo.core.freeswitch.inboundsocket import InboundEventSocket
from plivo.core.errors import ConnectError
from plivo.utils.logger import StdoutLogger
import gevent

def stop(inbound_event_listener, log):
    log.info("stopping now !")
    inbound_event_listener.disconnect()
    log.info("stopped !")

if __name__ == '__main__':
    log = StdoutLogger()
    try:
        inbound_event_listener = InboundEventSocket('127.0.0.1', 8021, 'ClueCon', filter="ALL")
        try:
            inbound_event_listener.connect()
        except ConnectError, e:
            log.error("connect failed: %s" % str(e))
            raise SystemExit('exit')

        log.info("stopping in 5 seconds !")
        gevent.spawn_later(5, stop, inbound_event_listener, log)

        inbound_event_listener.serve_forever()

    except (SystemExit, KeyboardInterrupt): pass

    log.info("exit")
示例#12
0
 def __init__(self, host, port, password, filter, log=None):
     InboundEventSocket.__init__(self, host, port, password, filter)
     self.log = log
     self.jobqueue = gevent.event.AsyncResult()
示例#13
0
 def test_login_failure(self):
     isock = InboundEventSocket('127.0.0.1', 23333, 'ClueCon')
     self.assertRaises(ConnectError, isock.connect)
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Plivo Team. See LICENSE for details.

from plivo.core.freeswitch.inboundsocket import InboundEventSocket
from plivo.core.errors import ConnectError
from plivo.utils.logger import StdoutLogger

if __name__ == '__main__':
    log = StdoutLogger()
    try:
        inbound_event_listener = InboundEventSocket('127.0.0.1', 8021, 'ClueCon', filter="ALL")
        try:
            inbound_event_listener.connect()
        except ConnectError, e:
            log.error("connect failed: %s" % str(e))
            raise SystemExit('exit')

        api_response = inbound_event_listener.api("FALSECOMMAND")
        log.info(str(api_response))
        if not api_response.is_success():
            log.error("api failed with response %s" % api_response.get_response())
            raise SystemExit('exit')

        log.info("api success with response %s" % api_response.get_response())

    except (SystemExit, KeyboardInterrupt): pass

    log.info("exit")
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Plivo Team. See LICENSE for details.

import traceback
from plivo.core.freeswitch.inboundsocket import InboundEventSocket
from plivo.utils.logger import StdoutLogger

if __name__ == '__main__':
    log = StdoutLogger()

    log.info('#' * 60)
    log.info("Connect with bad host")
    try:
        inbound_event_listener = InboundEventSocket('falsehost', 8021,
                                                    'ClueCon')
        inbound_event_listener.connect()
    except:
        [log.info(line) for line in traceback.format_exc().splitlines()]
    log.info('#' * 60 + '\n')

    log.info('#' * 60)
    log.info("Connect with bad port")
    try:
        inbound_event_listener = InboundEventSocket('127.0.0.1', 9999999,
                                                    'ClueCon')
        inbound_event_listener.connect()
    except:
        [log.info(line) for line in traceback.format_exc().splitlines()]
    log.info('#' * 60 + '\n')

    log.info('#' * 60)
示例#16
0
文件: cdr.py 项目: IPsafe/safebilling
 def __init__(self, host, port, password, filter="ALL", log=None, cdr_conn=None):
     InboundEventSocket.__init__(self, host, port, password, filter)
     self.log = log
     self.conn = cdr_conn
 def __init__(self, host, port, password, filter='ALL', pool_size=500, connect_timeout=5):
     InboundEventSocket.__init__(self, host, port, password, filter, pool_size=pool_size,
                                     connect_timeout=connect_timeout, eventjson=False)
     self.heartbeat_events = []
     self.re_schedule_events = []
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Plivo Team. See LICENSE for details.

from plivo.core.freeswitch.inboundsocket import InboundEventSocket
from plivo.core.errors import ConnectError
from plivo.utils.logger import StdoutLogger

if __name__ == '__main__':
    log = StdoutLogger()
    try:
        inbound_event_listener = InboundEventSocket('127.0.0.1', 8021, 'ClueCon', filter="BACKGROUND_JOB")
        try:
            inbound_event_listener.connect()
        except ConnectError, e:
            log.error("connect failed: %s" % str(e))
            raise SystemExit('exit')

        fs_bg_api_string = "originate user/1000 &playback(/usr/local/freeswitch/sounds/en/us/callie/base256/8000/liberty.wav)"
        bg_api_response = inbound_event_listener.bgapi(fs_bg_api_string)
        log.info(str(bg_api_response))
        log.info(bg_api_response.get_response())
        if not bg_api_response.is_success():
            log.error("bgapi failed !")
            raise SystemExit('exit')

        job_uuid = bg_api_response.get_job_uuid()
        if not job_uuid:
            log.error("bgapi jobuuid not found !")
            raise SystemExit('exit')

        log.info("bgapi success with Job-UUID " + job_uuid)
 def __init__(self, host, port, password, filter, log=None):
     InboundEventSocket.__init__(self, host, port, password, filter)
     self.log = log
     self.jobqueue = gevent.event.AsyncResult()
 def __init__(self, host, port, password, filter="ALL", pool_size=500, connect_timeout=5):
     InboundEventSocket.__init__(self, host, port, password, filter, pool_size, connect_timeout)
     self.log = StdoutLogger()
示例#21
0
from plivo.core.errors import ConnectError
from plivo.utils.logger import StdoutLogger
import gevent


def stop(inbound_event_listener, log):
    log.info("stopping now !")
    inbound_event_listener.disconnect()
    log.info("stopped !")


if __name__ == '__main__':
    log = StdoutLogger()
    try:
        inbound_event_listener = InboundEventSocket('127.0.0.1',
                                                    8021,
                                                    'ClueCon',
                                                    filter="ALL")
        try:
            inbound_event_listener.connect()
        except ConnectError, e:
            log.error("connect failed: %s" % str(e))
            raise SystemExit('exit')

        log.info("stopping in 5 seconds !")
        gevent.spawn_later(5, stop, inbound_event_listener, log)

        inbound_event_listener.serve_forever()

    except (SystemExit, KeyboardInterrupt):
        pass
示例#22
0
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Plivo Team. See LICENSE for details.

from plivo.core.freeswitch.inboundsocket import InboundEventSocket
from plivo.core.errors import ConnectError
from plivo.utils.logger import StdoutLogger

if __name__ == '__main__':
    log = StdoutLogger()
    try:
        inbound_event_listener = InboundEventSocket('127.0.0.1',
                                                    8021,
                                                    'ClueCon',
                                                    filter="BACKGROUND_JOB")
        try:
            inbound_event_listener.connect()
        except ConnectError, e:
            log.error("connect failed: %s" % str(e))
            raise SystemExit('exit')

        fs_bg_api_string = "originate user/1000 &playback(/usr/local/freeswitch/sounds/en/us/callie/base256/8000/liberty.wav)"
        bg_api_response = inbound_event_listener.bgapi(fs_bg_api_string)
        log.info(str(bg_api_response))
        log.info(bg_api_response.get_response())
        if not bg_api_response.is_success():
            log.error("bgapi failed !")
            raise SystemExit('exit')

        job_uuid = bg_api_response.get_job_uuid()
        if not job_uuid:
            log.error("bgapi jobuuid not found !")
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Plivo Team. See LICENSE for details.

import traceback
from plivo.core.freeswitch.inboundsocket import InboundEventSocket
from plivo.utils.logger import StdoutLogger

if __name__ == '__main__':
    log = StdoutLogger()

    log.info('#'*60)
    log.info("Connect with bad host")
    try:
        inbound_event_listener = InboundEventSocket('falsehost', 8021, 'ClueCon')
        inbound_event_listener.connect()
    except:
        [ log.info(line) for line in traceback.format_exc().splitlines() ]
    log.info('#'*60 + '\n')

    log.info('#'*60)
    log.info("Connect with bad port")
    try:
        inbound_event_listener = InboundEventSocket('127.0.0.1', 9999999, 'ClueCon')
        inbound_event_listener.connect()
    except:
        [ log.info(line) for line in traceback.format_exc().splitlines() ]
    log.info('#'*60 + '\n')

    log.info('#'*60)
    log.info("Connect with bad password")
    try:
 def __init__(self, host, port, password, filter="ALL", log=None):
     InboundEventSocket.__init__(self, host, port, password, filter)
     self.log = log
     self.jobs = {}
示例#25
0
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Plivo Team. See LICENSE for details.

from plivo.core.freeswitch.inboundsocket import InboundEventSocket
from plivo.core.errors import ConnectError
from plivo.utils.logger import StdoutLogger

if __name__ == '__main__':
    log = StdoutLogger()
    try:
        inbound_event_listener = InboundEventSocket('127.0.0.1', 8021, 'ClueCon', filter="ALL")
        try:
            inbound_event_listener.connect()
        except ConnectError, e:
            log.error("connect failed: %s" % str(e))
            raise SystemExit('exit')

        fs_api_string = "originate user/1000 &playback(/usr/local/freeswitch/sounds/en/us/callie/base256/8000/liberty.wav)"
        api_response = inbound_event_listener.api(fs_api_string)
        log.info(str(api_response))
        if not api_response.is_success():
            log.error("api failed with response %s" % api_response.get_response())
            raise SystemExit('exit')

        log.info("api success with response %s" % api_response.get_response())

    except (SystemExit, KeyboardInterrupt): pass

    log.info("exit")
示例#26
0
 def test_login_success(self):
     isock = InboundEventSocket('127.0.0.1', 18021, 'ClueCon')
     try:
         self.assertTrue(isock.connect())
     except socket.error, se:
         self.fail("socket error: %s" % str(se))
 def test_login_success(self):
     isock = InboundEventSocket('127.0.0.1', 18021, 'ClueCon', eventjson=False)
     try:
         isock.connect()
     except socket.error, se:
         self.fail("socket error: %s" % str(se))
示例#28
0
 def __init__(self, host, port, password, filter="ALL", log=None):
     InboundEventSocket.__init__(self, host, port, password, filter)
     self.log = log or StdoutLogger()