Exemple #1
0
    def __init__(self, config=None):
        """
        """
        console.info("Start python agent with version %s",
                     global_settings().agent_version)
        self._last_harvest = 0.0

        self._harvest_thread = threading.Thread(target=self._harvest_loop,
                                                name="TingYunHarvestThread")
        self._harvest_thread.setDaemon(True)  # should take caution to the doc
        self._harvest_shutdown = threading.Event()

        self._config = config if config is not None else global_settings()
        self._lock = threading.Lock()
        self._process_shutdown = False
        self._applications = {}  # used to store the actived applications
        self.__max_tracker = 5000
        self.__data_sampler = []

        if self._config.enabled:
            atexit.register(self._atexit_shutdown)

            # Register our exit event to the uwsgi shutdown hooks.
            if 'uwsgi' in sys.modules:
                import uwsgi
                uwsgi_original_atexit_callback = getattr(uwsgi, 'atexit', None)

                def uwsgi_atexit_callback():
                    self._atexit_shutdown()
                    if uwsgi_original_atexit_callback:
                        uwsgi_original_atexit_callback()

                uwsgi.atexit = uwsgi_atexit_callback
    def traced_exception(self):
        """处理捕获到的异常数据, 获取该数据必须在slowAction后面执行,因为slowAction最后一段数据需要统计exception和错误的总数
        :return:
        """
        # 如果异常引发错误,丢掉异常
        if self.errors:
            return

        http_status = 0
        settings = global_settings()
        max_msg = settings.exception.max_msg_character

        for ex in self.exception:
            filter_key = '%s_|%s_|%s' % (self.path.replace(
                '%2F', '/'), ex.class_name, ex.message[:max_msg])
            stack_detail = self.format_stack_trace(ex.stack_trace)
            exception_item = [
                ex.exception_time, self.path, http_status, ex.class_name,
                ex.message, 1, self.request_uri,
                json.dumps({"stacktrace": stack_detail}), self.trace_guid
            ]

            yield TracedException(filter_key=filter_key,
                                  trace_data=exception_item,
                                  tracker_type=ex.tracker_type)
Exemple #3
0
    def trace_node(self, root):
        """
        :param root: the root node of the tracker
        :return:
        """
        dbtype = r" %s" % self.dbtype
        params = {"sql": "", "explainPlan": {}, "stacktrace": []}
        children = []
        call_count = 1
        class_name = ""
        root.trace_node_count += 1
        start_time = node_start_time(root, self)
        end_time = node_end_time(root, self)
        operation = str(self.operation).upper() or 'CALL'
        method_name = '%s.%s' % (self.dbtype, operation)
        metric_name = "Database%s/%s:%s%%2F%s%%2FUnknown/%s" % (
            dbtype, self.host, self.port, self.db_name, operation)
        call_url = ""
        host, port, db_name = self.host, self.port, self.db_name
        sql = self.formatted or ''
        # Note, use local setting only.
        _settings = global_settings()

        # exception不存在,不能加入该key值
        if self.exception:
            params['exception'] = root.parse_exception_detail(self.exception)

        if self.table:
            metric_name = "Database %s/%s:%s%%2F%s%%2F%s/%s" % (
                dbtype, host, port, db_name, self.table, operation)
        else:
            console.debug("Can not get table for operate `%s` to `%s`",
                          operation, dbtype)

        if self.formatted:
            params['sql'] = sql

            if _settings.action_tracer.log_sql:
                console.info(
                    "Log sql is opened. sql upload is disabled, sql sentence is %s",
                    self.formatted)
                params['sql'] = ""

            if self.explain_plan:
                params['explainPlan'] = self.explain_plan

            if self.stack_trace:
                params['stacktrace'] = root.format_stack_trace(
                    self.stack_trace)

        return [
            start_time, end_time, metric_name, call_url, call_count,
            class_name, method_name, params, children
        ]
    def trace_node(self, root):
        """
        :param root: the root node of the tracker
        :return:
        """
        dbtype = r" %s" % self.dbtype
        params = {"sql": "", "explainPlan": {}, "stacktrace": []}
        children = []
        call_count = 1
        class_name = ""
        root.trace_node_count += 1
        start_time = node_start_time(root, self)
        end_time = node_end_time(root, self)
        operation = str(self.operation).upper() or 'CALL'
        method_name = '%s.%s' % (self.dbtype, operation)
        metric_name = "Database%s/%s:%s%%2F%s%%2FUnknown/%s" % (
            dbtype, self.host, self.port, self.db_name, operation)
        call_url = ""
        host, port, db_name = self.host, self.port, self.db_name

        if self.table:
            metric_name = "Database %s/%s:%s%%2F%s%%2F%s/%s" % (
                dbtype, host, port, db_name, self.table, operation)
        else:
            console.debug("Can not get table for operate `%s` to `%s`",
                          operation, dbtype)

        if self.formatted:
            # Note, use local setting only.
            _settings = global_settings()
            params['sql'] = self.formatted

            if _settings.action_tracer.log_sql:
                console.info(
                    "Log sql is opened. sql upload is disabled, sql sentence is %s",
                    self.formatted)
                params['sql'] = ""

            if self.explain_plan:
                params['explainPlan'] = self.explain_plan

            if self.stack_trace:
                for line in self.stack_trace:
                    line = [line.filename, line.lineno, line.name, line.locals]
                    if len(line) >= 4 and 'tingyun' not in line[0]:
                        params['stacktrace'].append(
                            "%s(%s:%s)" % (line[2], line[0], line[1]))

        return [
            start_time, end_time, metric_name, call_url, call_count,
            class_name, method_name, params, children
        ]
 def __init__(self, profile_id):
     """
     """
     self.profile_id = profile_id
     self.start_time = int(time.time() * 1000)
     self.end_time = 0
     self.final_data = {"Web": {"cpuTime": 0, "threadTraces": []}, "Background": {"cpuTime": 0, "threadTraces": []},
                        "Agent": {"cpuTime": 0, "threadTraces": []}, "Other": {"cpuTime": 0, "threadTraces": []}}
     self.sample_count = 0
     self.thread_count = 0
     self.total_runnable_count = 0
     self.stacktraces = {}
     self.max_retrieve_depth = global_settings().max_profile_depth  # avoid reaching python max recursion depth.
     self.retrieve_depth = 0
    def test_create_connection(self):
        """
        """
        settings = global_settings()
        settings.license_key = "999-999-999"
        test_log = os.path.join(os.path.dirname(__file__), "test.log")
        initialize_logging(test_log, logging.DEBUG)

        session = create_connection("999-999-999", "Python App Test", [],
                                    env_config(), settings)
        self.assertTrue(isinstance(session, Engine), "")

        if os.path.isfile(test_log):
            os.remove(test_log)
Exemple #7
0
    def __init__(self, url, config, license_key, redirect_host):
        self.url = url
        self.config = config
        self.license_key = license_key
        self.local_setting = global_settings()
        self.merged_settings = config
        self.redirect_host = redirect_host

        self._session = None
        self.request_param = {
            "licenseKey": self.license_key,
            "version": self.local_setting.data_version,
            "appSessionKey": self.config.appSessionKey,
        }
    def __init__(self):
        """we provide local setting switch, just used when exception occurred in user environment.
        enable parameter will be removed in the future.
        :return:
        """
        self.enable = global_settings().enable_profile
        self.current_profile = None

        self._profile_shutdown = threading.Event()
        self.profile_thread_running = False  # not running
        self.profile_thread = None
        self.cmd_info = {}
        self.finished_profiles = []
        self.cmd_stop_status = False
        self.generated_data = None
Exemple #9
0
    def connect_to_headquarters(self):
        """Performs the actual registration of the application to server, get server config and set the current app
        settings.
        :return:
        """
        # ensure the main thread get to run first
        time.sleep(0.01)

        while not self._active_session:
            self.retry_upload_times = 0
            settings = global_settings()

            try:
                active_session = create_connection(None, self._app_name,
                                                   self._linked_app,
                                                   env_config(), settings)
            except InvalidLicenseException as _:
                console.warning(
                    "Invalid license in configuration, agent will stop to work please fix license and"
                    "restart agent again")

                self._is_license_valid = False
                self._connect_event.wait(self.connect_retry_time)
                continue
            except Exception:
                # use the harvest controller signal to control the connection
                console.exception(
                    "Connect to agent server failed, Connection will try again in 1 min."
                )
                self._connect_event.wait(self.connect_retry_time)
                continue
            finally:
                if self._connect_event.isSet():
                    console.info(
                        "Agent is shutting down, stop the connection to server now."
                    )
                    return

            if active_session:
                self._is_license_valid = True
                self._connect_event.set()
                self.start_sampler()

                # set the application settings to data engine
                with self._packets_lock:
                    self._active_session = active_session
                    self._packager.reset_packets(self._active_session.config)
Exemple #10
0
def connect_url(action, host=None, with_port=False):
    """
    :param action: the uploader actually intention
    :return: ruled url, the suitable url according to headquarters strategy
    """
    settings = global_settings()
    scheme = settings.ssl and 'https' or 'http'
    url_reg = "%s://%s/%s"

    if host is None:
        host = settings.host

    url = url_reg % (scheme, host, action)
    if with_port and settings.port:
        url_reg = "%s://%s:%s/%s"
        url = url_reg % (scheme, host, settings.port, action)

    return url
Exemple #11
0
    def __init__(self, dispatcher, app_name, link_app_name=None):
        """
        :param dispatcher:
        :param app_name:
        :return:
        """
        self.enabled = True
        self._app_name = app_name
        self._link_app_name = link_app_name if link_app_name else []

        if not app_name:
            self._app_name = global_settings().app_name

        if not dispatcher:
            dispatcher = dispatcher_instance()
            console.debug("init application with new dispatcher.")

        self._dispatcher = dispatcher
Exemple #12
0
def parse_proxy():
    """
    :return: {'http': 'xxx', 'https': 'xxx'}
    """
    settings = global_settings()

    # Proxy schema set in configure file,then use it
    # Else use `ssl` configure to decide 'http' or 'https'
    host = settings.proxy_host or ''
    port = settings.proxy_port or ''
    user = settings.proxy_user or ''
    scheme = settings.proxy_scheme or 'http'
    password = settings.proxy_pwd or ''

    # we support `http://user:password@host` format, so just checkout host
    if not host:
        return

    # urlparse will return <scheme>://<netloc>/<path>
    # (scheme, netloc, path, params, query, fragment)
    sections = urlparse.urlparse(host)
    if (not sections.scheme or sections.scheme not in ('http', 'https')) and not port:
        return

    path = ''
    netloc = host
    if sections.scheme:  # config the  host with <scheme>://<netloc>/<path> in settings
        scheme = sections.scheme
        netloc = sections.netloc
        path = sections.path
    elif sections.path:  # urlparse parse the netloc to path
        netloc = sections.path

    if port:
        netloc = "%s:%s" % (netloc, port)

    if user:
        if password:
            netloc = '%s:%s@%s' % (user, password, netloc)
        else:
            netloc = '%s@%s' % (user, netloc)

    full_url = '%s://%s%s' % (scheme, netloc, path)
    return {'http': full_url, 'https': full_url}
Exemple #13
0
    def test_private(self):
        """
        :return:
        """
        settings = global_settings()
        settings.license_key = "999-999-999"
        settings.log_file = os.path.join(os.path.dirname(__file__), "test.log")
        settings.host = '192.168.2.81'
        settings.port = 8081

        url = connect_url("getRedirectHost", with_port=True)
        self.assertEqual(url, 'https://192.168.2.81:8081/getRedirectHost')

        url = connect_url("getRedirectHost",
                          host='192.168.2.82:8081',
                          with_port=False)
        self.assertEqual(url, 'https://192.168.2.82:8081/getRedirectHost')

        # recovery the default settings
        settings.host = 'redirect.networkbench.com'
Exemple #14
0
    def __init__(self, config_file):
        """
        :param config_file:
        :return:
        """
        self.config_file = config_file
        self.is_embattled = False
        self.valid_embattle = True
        self._config_parser = ConfigParser.RawConfigParser()
        self._settings = global_settings()
        self._inspect_lock = threading.Lock()

        if not config_file:
            self.config_file = os.environ.get(ENV_CONFIG_FILE, None)

        if not self.config_file:
            log_bootstrap(
                'Agent config file is not found, agent start failed.')
            self.valid_embattle = False

        log_bootstrap("get config file %s" % self.config_file)
Exemple #15
0
    def singleton_instance():
        """
        :return: singleton instance
        """
        if Dispatcher._instance:
            return Dispatcher._instance

        instance = None
        with Dispatcher._instance_lock:
            if not Dispatcher._instance:
                instance = Dispatcher(global_settings())
                Dispatcher._instance = instance

                console.info('Creating instance of agent dispatcher')

        if instance:
            instance.register_data_sampler(memory_usage_sampler,
                                           ('memory.usage', ))
            instance.register_data_sampler(cpu_usage_sampler, ('cpu.usage', ))
            instance.active_dispatcher()

        return instance
Exemple #16
0
    def singleton_instance(name):
        """one application according to name
        """
        if not name:
            name = global_settings().app_name

        names = str(name).split(';')
        app_name = names[0]
        link_name = names[1:]

        controller = dispatcher_instance()
        instance = Proxy._instances.get(app_name, None)

        if not instance:
            with Proxy._lock:
                instance = Proxy._instances.get(app_name, None)
                if not instance:
                    instance = Proxy(controller, app_name, link_name)
                    Proxy._instances[app_name] = instance

                    console.info("Create new proxy with application name: %s", name)

        return instance
Exemple #17
0
    def execute(self, args):
        """
        :param args:
        :return:
        """
        errors = []
        warnings = []
        config_file = os.environ.get(ENV_CONFIG_FILE, "")

        if (len(args) > 0) and len(args) != 1:
            raise CommandlineParametersException()

        if 1 == len(args):
            config_file = args[0]

        env_msg = ''
        if 0 == len(args):
            env_msg = "please set the environment variable(%s) for agent config file." % ENV_CONFIG_FILE

        if not os.path.exists(config_file):
            errors.append("Config file is not specified. Or " + env_msg)
            self.internal_tips(errors)
            raise CommandlineParametersException()

        if not _config_parser.read(config_file):
            errors.append(
                "Errors: unable to read the config file. please check the file permission."
            )
            self.internal_tips(errors)
            raise CommandlineParametersException()

        # check the config detail.
        print("Use config file: %s" % config_file)
        default_settings = global_settings()
        multi_attr = {
            "action_tracer.log_sql": default_settings.action_tracer.log_sql
        }
        for item in CONFIG_ITEM:
            ret = self._process_setting(item["section"], item["key"], 'get',
                                        item["mapper"])
            if ret[0] < 0:
                errors.append(ret[2])
                break

            if 0 == ret[0] and 'log_file' != item[
                    "key"] and 'license_key' != item["key"]:
                if item["key"] in multi_attr:
                    v = multi_attr[item["key"]]
                else:
                    v = getattr(
                        default_settings, item["key"]
                    ) if 'log_level' != item["key"] else "logging.DEBUG"
                warnings.append(ret[2] +
                                " Use default value [%s] instead." % v)
                continue

            if 'log_file' == item["key"] and not ret[1]:
                warnings.append(
                    "config option <log_file> is not defined, agent log will output to stderr."
                )
                continue

            if 'log_file' == item["key"] and ret[1]:
                try:
                    with open(ret[1], "a+") as fd:
                        fd.write(
                            "agent check log file config input message.\n")
                except Exception as _:
                    warnings.append(
                        "Current user[%s] not allowed to access the log file[%s]."
                        % (os.environ["USER"], ret[1]))

            if 'license_key' == item["key"] and not ret[1]:
                errors.append(
                    "config option <license_key> is not defined, agent will not work well."
                )
                continue

        if warnings:
            self.internal_tips(warnings, "Warning")

        if errors:
            self.internal_tips(errors)
            raise CommandlineParametersException()

        if not errors:
            print("\nValidate agent config file success!!")
Exemple #18
0
 def global_settings(self):
     """get the global settings or server settings
     :return:
     """
     return global_settings()
Exemple #19
0
def transmitter(session, url, action, payload={}, param={}, audit_mode=False):
    """
    :param session: the request session to server
    :param url: the address witch data send to
    :param action: the send actually intention
    :param payload: request data
    :return: None
    """
    console.debug("Send request with url %s, action %s param %s", url, action, param)
    settings = global_settings()
    start_time = time.time()
    headers = {
        "User-Agent": USER_AGENT,
        "Content-Type": "application/octet-stream",
        "connection": "close",
        "Accept-Encoding": "deflate",
    }

    try:
        data = json.dumps(payload)
    except Exception as err:
        console.error("Encoding json for payload failed, url %s action %s param %s payload %s err %s",
                      url, action, param, payload, err)
        raise DiscardDataForRequest(str(sys.exc_info()[1]))

    if len(data) > COMPRESS_MINIMUM_SIZE:
        headers['Content-Encoding'] = 'deflate'
        level = (len(data) < 2000000) and 1 or 9
        data = zlib.compress(six.b(data), level)

    auto_close_session = False
    if not session:
        session = requests.session()
        auto_close_session = True

    content = ""
    try:
        # because of the root license use the sha1 encryption, the version of the certifi new than 2015.4.28
        # which used sha256 encryption, will cause the ssl verify failed, so no mater what kind of agent work
        # mode(private deploy or public use), we do not verify the ssl license now.

        verify_ssl = False if settings.port else settings.verify_certification
        timeout = settings.data_report_timeout
        proxy = parse_proxy()
        ret = session.post(url, data=data, params=param, headers=headers, timeout=timeout, verify=verify_ssl,
                           proxies=proxy)
        content = ret.content
    except requests.RequestException:
        console.error('Agent server is not attachable. if the error continues, please report to networkbench.'
                      'The error raised was %s. response content is %s.', sys.exc_info()[1], content)
        raise RetryDataForRequest(str(sys.exc_info()[1]))
    finally:
        duration = time.time() - start_time
        if auto_close_session:
            session.close()

    if audit_mode:
        console.info("Use %ss to upload data return value %r", duration, content)

    if ret.status_code == 400:
        console.error("Bad request has been submitted for url %s, please report this to us, thank u.", url)
        raise DiscardDataForRequest()
    elif ret.status_code == 503:
        console.error("Agent server is unavailable. This can be a transient issue because of the server or our core"
                      " application being restarted. if this error continues, please report to us. thank u.")
        raise DiscardDataForRequest()
    elif ret.status_code == 502:
        console.error("Agent server error, our engineer has caution this error, thanks for your support")
        raise ServerIsUnavailable("service unavailable, get status code 502")
    elif ret.status_code != 200:
        console.warning("We got none 200 status code %s, this maybe some network/server error, if this error continues,"
                        "please report to us . thanks for your support. return content %s", ret.status_code, ret)
        raise DiscardDataForRequest()

    try:
        if six.PY3:
            content = content.decode('UTF-8')

        result = json.loads(content)
    except Exception as err:
        console.warning("Decoding data for Json error. please contact us for further investigation. %s", err)
        raise DiscardDataForRequest(str(sys.exc_info()[1]))
    else:
        # successful exchange with server
        if result["status"] == "success":
            return result["result"] if "result" in result else []

    console.info("get unexpected return,  there maybe some issue. %s", result)
    server_status = int(result["result"]["errorCode"])

    if server_status == 460:
        console.warning("Invalid license key, Please contact to networkbench for more help.")
        raise InvalidLicenseException("Invalid license key")
    elif server_status == 462:
        console.warning("Invalid data format, maybe something get wrong when json encoding.")
        raise DiscardDataForRequest(content)
    elif server_status == 461:
        console.warning("Invalid data token, if this error continues, please report to networkbench support for further"
                        " investigation")
        raise InvalidDataTokenException()
    elif server_status == -1:
        console.warning("Agent server error, our engineer has caution this error, thanks for your support.")
        raise ServerIsUnavailable()
    elif server_status == 470:
        console.info("Configuration is out of date, server configuration will be obtain again")
        raise OutOfDateConfigException()

    return []
Exemple #20
0
try:
    import urlparse
except ImportError:
    import urllib.parse as urlparse

from tingyun.logistics.exceptions import DiscardDataForRequest, RetryDataForRequest, InvalidLicenseException
from tingyun.logistics.exceptions import InvalidDataTokenException, OutOfDateConfigException, ServerIsUnavailable
from tingyun.config.settings import global_settings
from tingyun.packages import six, requests

console = logging.getLogger(__name__)

# 10kbi
COMPRESS_MINIMUM_SIZE = 10 * 1024
USER_AGENT = ' NBS Newlens Agent/%s (python %s; %s)' % (global_settings().agent_version, sys.version.split()[0],
                                                        sys.platform)


def parse_proxy():
    """
    :return: {'http': 'xxx', 'https': 'xxx'}
    """
    settings = global_settings()

    # Proxy schema set in configure file,then use it
    # Else use `ssl` configure to decide 'http' or 'https'
    host = settings.proxy_host or ''
    port = settings.proxy_port or ''
    user = settings.proxy_user or ''
    scheme = settings.proxy_scheme or 'http'
Exemple #21
0
def defined_repertoire():
    """
    :return:
    """
    hookers = {
        "memcached": [
            {"target": "memcache", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.database_memcached'},
        ],

        "pymemcache": [
            {"target": "pymemcache.client", 'hook_func': "detect_base_client",
             'hook_module': 'tingyun.armoury.database_pymemcache'},
            {"target": "pymemcache.client", 'hook_func': "detect_pooled_client",
             'hook_module': 'tingyun.armoury.database_pymemcache'},
            {"target": "pymemcache.client.hash", 'hook_func': "detect_has_client",
             'hook_module': 'tingyun.armoury.database_pymemcache'},
        ],
        "bmemcached": [
            {"target": "bmemcached.client", 'hook_func': "detect_client",
             'hook_module': 'tingyun.armoury.database_bmemcache'},
        ],

        # mysql db
        "mysql": [
            {"target": "MySQLdb", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.database_dbapi2'},
        ],
        "pymysql": [
            {"target": "pymysql", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.database_dbapi2'},
        ],
        "oursql": [
            {"target": "oursql", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.database_dbapi2'},
        ],

        # oracle
        "oracle": [
            {"target": "cx_Oracle", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.database_dbapi2'},
        ],

        # postgres SQL
        "postgresql": [
            {"target": "postgresql.interface.proboscis.dbapi2", 'hook_func': 'detect',
             'hook_module': 'tingyun.armoury.database_dbapi2'},
        ],
        # postgres SQL
        "psycopg2": [
            {"target": "psycopg2", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.database_dbapi2'},
        ],
        "psycopg2ct": [
            {"target": "psycopg2ct", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.database_dbapi2'},
        ],
        "psycopg2cffi": [
            {"target": "psycopg2cffi", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.database_dbapi2'},
        ],

        # ODBC A Python DB API 2 module for ODBC
        "pyodbc": [
            {"target": "pyodbc", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.database_dbapi2'},
        ],

        # nosql mongodb
        "mongodb": [
            {"target": "pymongo.mongo_client", 'hook_func': 'detect_mongo_client',
             'hook_module': 'tingyun.armoury.database_mongo'},
            {"target": "pymongo.connection", 'hook_func': 'detect_connection',
             'hook_module': 'tingyun.armoury.database_mongo'},
            {"target": "pymongo.collection", 'hook_func': 'detect_collection',
             'hook_module': 'tingyun.armoury.database_mongo'},
        ],

        # nosql redis
        "redis": [
            {"target": "redis.client", 'hook_func': 'detect_client_operation',
             'hook_module': 'tingyun.armoury.database_redis'},
        ],

        # external call
        "urllib": [
            {"target": "urllib", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.external_urllib'},
        ],
        "urllib2": [
            {"target": "urllib2", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.external_urllib2'},
        ],
        # v1.6-v1.14
        "urllib3": [
            {"target": "urllib3.poolmanager", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.external_urllib3'},
        ],
        # 0.8.0-0.9.3
        "thrift": [
            {"target": "thrift.transport.TSocket", 'hook_func': 'detect_tsocket',
             'hook_module': 'tingyun.armoury.external_thrift'},
            {"target": "thrift.transport.TSSLSocket", 'hook_func': 'detect_tsslsocket',
             'hook_module': 'tingyun.armoury.external_thrift'},
        ],

        # 2.0.0-2.10.0
        "requests": [
            {"target": "requests.sessions", 'hook_func': 'detect_requests_sessions',
             'hook_module': 'tingyun.armoury.external_requests'},
        ],
        # 0.7.5-0.9.2
        "httplib2": [
            {"target": "httplib2", 'hook_func': 'detect_httplib2_http',
             'hook_module': 'tingyun.armoury.external_httplib2'},
            {"target": "httplib2", 'hook_func': 'detect_http_connect_with_timeout',
             'hook_module': 'tingyun.armoury.external_httplib2'},
            {"target": "httplib2", 'hook_func': 'detect_https_connect_with_timeout',
             'hook_module': 'tingyun.armoury.external_httplib2'},
        ],

        # django, this weapon must not be removed.
        "django": [
            {"target": "django.core.handlers.base", 'hook_func': 'detect_middleware',
             'hook_module': 'tingyun.armoury.framework_django'},
            {"target": "django.core.handlers.wsgi", 'hook_func': 'detect_wsgi_entrance',
             'hook_module': 'tingyun.armoury.framework_django'},
            {"target": "django.core.urlresolvers", 'hook_func': 'detect_urlresolvers',
             'hook_module': 'tingyun.armoury.framework_django'},
            {"target": "django.views.generic.base", 'hook_func': 'detect_views_dispatch',
             'hook_module': 'tingyun.armoury.framework_django'},

            {"target": "django.template.loader_tags", 'hook_func': 'detect_template_block_render',
             'hook_module': 'tingyun.armoury.framework_django'},
            {"target": "django.template.base", 'hook_func': 'detect_django_template',
             'hook_module': 'tingyun.armoury.framework_django'},

            {"target": "django.http.multipartparser", 'hook_func': 'detect_http_multipartparser',
             'hook_module': 'tingyun.armoury.framework_django'},

            {"target": "django.core.mail", 'hook_func': 'detect_core_mail',
             'hook_module': 'tingyun.armoury.framework_django'},
            {"target": "django.core.mail.message", 'hook_func': 'detect_core_mail_message',
             'hook_module': 'tingyun.armoury.framework_django'},
        ],

        # django-piston, 0.2.2.1-0.2.3
        "piston": [
            {"target": "piston.resource", 'hook_func': 'detect_piston_resource',
             'hook_module': 'tingyun.armoury.ammunition.piston'},
        ],

        # flask, 0.6-1.0
        "flask": [
            {"target": "flask.app", 'hook_func': 'detect_wsgi_entrance',
             'hook_module': 'tingyun.armoury.framework_flask'},
            {"target": "flask.app", 'hook_func': 'detect_app_entrance',
             'hook_module': 'tingyun.armoury.framework_flask'},
            {"target": "flask.blueprints", 'hook_func': 'detect_app_blueprint_entrance',
             'hook_module': 'tingyun.armoury.framework_flask'},
            {"target": "flask.templating", 'hook_func': 'detect_templates',
             'hook_module': 'tingyun.armoury.framework_flask'},
        ],

        # jinja2 2.3-2.8
        'jinja2': [
            {"target": "jinja2.loaders", 'hook_func': 'detect_template_loader',
             'hook_module': 'tingyun.armoury.template_jinja2'},
            {"target": "jinja2.environment", 'hook_func': 'detect_jinja2',
             'hook_module': 'tingyun.armoury.template_jinja2'},
            ],

        # version 2.8.1-2.12.x
        'web2py': [
            {"target": "gluon.main", 'hook_func': 'detect_wsgi_entrance',
             'hook_module': 'tingyun.armoury.framework_web2py'},
            {"target": "gluon.compileapp", 'hook_func': 'detect_compileapp',
             'hook_module': 'tingyun.armoury.framework_web2py'},
            {"target": "gluon.template", 'hook_func': 'detect_template',
             'hook_module': 'tingyun.armoury.framework_web2py'},
        ],

        # version 0.3.x
        'webpy': [
            {"target": "web.application", 'hook_func': 'detect_wsgi_entrance',
             'hook_module': 'tingyun.armoury.framework_webpy'},

            {"target": "web.application", 'hook_func': 'detect_application',
             'hook_module': 'tingyun.armoury.framework_webpy'},
        ],

        # version 4.x.x
        # when tornado only use as wsgi application, do not detect tornado component
        "tornado4": [
            {"target": "tornado.web", 'hook_func': 'detect_web',
             'hook_module': 'tingyun.armoury.ammunition.tornado.web'},

            {"target": "tornado.httputil", 'hook_func': 'detect_tracker_entrance',
             'hook_module': 'tingyun.armoury.ammunition.tornado_4.http_util'},
            {"target": "tornado.httpserver", 'hook_func': 'detect_tracker_export',
             'hook_module': 'tingyun.armoury.ammunition.tornado_4.http_server'},
            {"target": "tornado.httpclient", 'hook_func': 'detect_http_client',
             'hook_module': 'tingyun.armoury.ammunition.tornado_4.http_client'},
            {"target": "tornado.gen", 'hook_func': 'detect_gen',
             'hook_module': 'tingyun.armoury.ammunition.tornado_4.gen'},
            {"target": "tornado.ioloop", 'hook_func': 'detect_ioloop',
             'hook_module': 'tingyun.armoury.ammunition.tornado_4.ioloop'},
            {"target": "tornado.concurrent", 'hook_func': 'detect_concurrent',
             'hook_module': 'tingyun.armoury.ammunition.tornado_4.concurrent'},
            {"target": "concurrent.futures", 'hook_func': 'detect_concurrent',
             'hook_module': 'tingyun.armoury.ammunition.tornado_4.concurrent'},
            {"target": "tornado.stack_context", 'hook_func': 'detect_stack_context',
             'hook_module': 'tingyun.armoury.ammunition.tornado_4.stack_context'},
        ]if "4." in tornado_version and not global_settings().tornado_wsgi_adapter_mode else [],

        "tornado-wsgi-adapter-mode": [
            {"target": "tornado.web", 'hook_func': 'detect_handlers',
             'hook_module': 'tingyun.armoury.ammunition.tornado_4.wsgi_mode.web'},
            {"target": "tornado.httpclient", 'hook_func': 'detect_http_client',
             'hook_module': 'tingyun.armoury.ammunition.tornado_4.wsgi_mode.http_client'},
            {"target": "tornado.wsgi", 'hook_func': 'detect_wsgi_entrance',
             'hook_module': 'tingyun.armoury.ammunition.tornado_4.wsgi_mode.wsgi'},
        ]if "4." in tornado_version and global_settings().tornado_wsgi_adapter_mode else [],

        # mako v0.7.x-v1.0.x
        "mako": [
            {"target": "mako.template", 'hook_func': 'detect_template',
             'hook_module': 'tingyun.armoury.template_mako'},
        ],

        # 0.13.0-1.0.2
        "gevent": [
            {"target": "gevent.pywsgi", 'hook_func': 'detect_wsgi',
             'hook_module': 'tingyun.armoury.matrix.t_gevent'},
            {"target": "gevent.wsgi", 'hook_func': 'detect_pywsgi',
             'hook_module': 'tingyun.armoury.matrix.t_gevent'},
        ],

        # openstack-nova
        'openstack-nova': [
            # nova.api.openstack.wsgi
            {"target": "nova.api.openstack.wsgi", 'hook_func': 'resource_wsgi_entrance',
             'hook_module': 'tingyun.armoury.nova.api_openstack_wsgi'},

            # nova.wsgi
            {"target": "nova.wsgi", 'hook_func': 'middleware_wsgi_entrance',
             'hook_module': 'tingyun.armoury.nova.wsgi'},
            {"target": "nova.wsgi", 'hook_func': 'router_wsgi_entrance',
             'hook_module': 'tingyun.armoury.nova.wsgi'},

            # nova.api.auth
            {"target": "nova.api.auth", 'hook_func': 'keystone_context_wsgi_entrance',
             'hook_module': 'tingyun.armoury.nova.api_auth'},

            # nova.api.ec2
            {"target": "nova.api.ec2", 'hook_func': 'ec2_keystone_wsgi_entrance',
             'hook_module': 'tingyun.armoury.nova.api_ec2'},
            {"target": "nova.api.ec2", 'hook_func': 'requestify_wsgi_entrance',
             'hook_module': 'tingyun.armoury.nova.api_ec2'},
            {"target": "nova.api.ec2", 'hook_func': 'authorizer_wsgi_entrance',
             'hook_module': 'tingyun.armoury.nova.api_ec2'},
            {"target": "nova.api.ec2", 'hook_func': 'executor_wsgi_entrance',
             'hook_module': 'tingyun.armoury.nova.api_ec2'},

            # webob.client
            {"target": "webob.client", 'hook_func': 'send_request_wsgi_entrance',
             'hook_module': 'tingyun.armoury.webob.client'},
            {"target": "webob.response", 'hook_func': 'response_wsgi_entrance',
             'hook_module': 'tingyun.armoury.webob.response'},
        ],
        # bottle 0.10.x-0.12.x
        "bottle": [
            {"target": "bottle", 'hook_func': 'detect_wsgi_entrance',
             'hook_module': 'tingyun.armoury.framework_bottle'},
            {"target": "bottle", 'hook_func': 'detect_templates',
             'hook_module': 'tingyun.armoury.framework_bottle'},
            {"target": "bottle", 'hook_func': 'detect_app_components',
             'hook_module': 'tingyun.armoury.framework_bottle'},
        ],

        # RabbitMQ pika0.10.x-
        "pika": [
            {"target": "pika.adapters.blocking_connection", 'hook_func': 'detect_block_channel',
             'hook_module': 'tingyun.armoury.mq.mq_pika'},
            {"target": "pika.channel", 'hook_func': 'detect_channel',
             'hook_module': 'tingyun.armoury.mq.mq_pika'},
            {"target": "pika.connection", 'hook_func': 'detect_connection',
             'hook_module': 'tingyun.armoury.mq.mq_pika'},
        ]
    }

    return hookers
Exemple #22
0
def defined_repertoire():
    """
    :return:
    """
    hookers = {
        "memcached_1.58.0": [
            {
                "target": "public.packages.pythonmemcached.v1580.memcache",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.database_memcached'
            },
        ],
        "memcached_1.47.0": [
            {
                "target": "public.packages.pythonmemcached.v1470.memcache",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.database_memcached'
            },
        ],
        "pymemcache_1.4.0": [
            {
                "target": "public.packages.pymemcache.v140.pymemcache.client",
                'hook_func': "detect_base_client",
                'hook_module': 'tingyun.armoury.database_pymemcache'
            },
            {
                "target": "public.packages.pymemcache.v140.pymemcache.client",
                'hook_func': "detect_pooled_client",
                'hook_module': 'tingyun.armoury.database_pymemcache'
            },
            {
                "target":
                "public.packages.pymemcache.v140.pymemcache.client.hash",
                'hook_func': "detect_has_client",
                'hook_module': 'tingyun.armoury.database_pymemcache'
            },
        ],
        "pymemcache_1.3.0": [
            {
                "target": "public.packages.pymemcache.v130.pymemcache.client",
                'hook_func': "detect_base_client",
                'hook_module': 'tingyun.armoury.database_pymemcache'
            },
            {
                "target": "public.packages.pymemcache.v130.pymemcache.client",
                'hook_func': "detect_pooled_client",
                'hook_module': 'tingyun.armoury.database_pymemcache'
            },
            {
                "target":
                "public.packages.pymemcache.v130.pymemcache.client.hash",
                'hook_func': "detect_has_client",
                'hook_module': 'tingyun.armoury.database_pymemcache'
            },
        ],
        "pymemcache_1.2.0": [
            {
                "target": "public.packages.pymemcache.v120.pymemcache.client",
                'hook_func': "detect_base_client",
                'hook_module': 'tingyun.armoury.database_pymemcache'
            },
            {
                "target": "public.packages.pymemcache.v120.pymemcache.client",
                'hook_func': "detect_pooled_client",
                'hook_module': 'tingyun.armoury.database_pymemcache'
            },
            {
                "target":
                "public.packages.pymemcache.v120.pymemcache.client.hash",
                'hook_func': "detect_has_client",
                'hook_module': 'tingyun.armoury.database_pymemcache'
            },
        ],
        "bmemcached_0.25.0": [
            {
                "target": "public.packages.bmemcached.v0250.bmemcached.client",
                'hook_func': "detect_client",
                'hook_module': 'tingyun.armoury.database_bmemcache'
            },
        ],
        "bmemcached_0.24": [
            {
                "target": "public.packages.bmemcached.v0240.bmemcached.client",
                'hook_func': "detect_client",
                'hook_module': 'tingyun.armoury.database_bmemcache'
            },
        ],
        "bmemcached_0.23": [
            {
                "target": "public.packages.bmemcached.v0230.bmemcached.client",
                'hook_func': "detect_client",
                'hook_module': 'tingyun.armoury.database_bmemcache'
            },
        ],
        "bmemcached_0.22": [
            {
                "target": "public.packages.bmemcached.v0220.bmemcached.client",
                'hook_func': "detect_client",
                'hook_module': 'tingyun.armoury.database_bmemcache'
            },
        ],
        "bmemcached_0.21": [
            {
                "target": "public.packages.bmemcached.v0210.bmemcached.client",
                'hook_func': "detect_client",
                'hook_module': 'tingyun.armoury.database_bmemcache'
            },
        ],
        "bmemcached_0.20": [
            {
                "target": "public.packages.bmemcached.v0200.bmemcached.client",
                'hook_func': "detect_client",
                'hook_module': 'tingyun.armoury.database_bmemcache'
            },
        ],

        # mysql db
        "mysql": [
            {
                "target": "MySQLdb",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.database_dbapi2'
            },
        ],
        "pymysql": [
            {
                "target": "pymysql",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.database_dbapi2'
            },
        ],
        "oursql": [
            {
                "target": "oursql",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.database_dbapi2'
            },
        ],

        # oracle
        "oracle": [
            {
                "target": "cx_Oracle",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.database_dbapi2'
            },
        ],

        # postgres SQL
        "postgresql": [
            {
                "target": "postgresql.interface.proboscis.dbapi2",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.database_dbapi2'
            },
        ],
        # postgres SQL
        "psycopg2": [
            {
                "target": "psycopg2",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.database_dbapi2'
            },
        ],
        "psycopg2ct": [
            {
                "target": "psycopg2ct",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.database_dbapi2'
            },
        ],
        "psycopg2cffi": [
            {
                "target": "psycopg2cffi",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.database_dbapi2'
            },
        ],

        # ODBC A Python DB API 2 module for ODBC
        "pyodbc": [
            {
                "target": "pyodbc",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.database_dbapi2'
            },
        ],

        # nosql mongodb
        "mongodb_3.4.0": [
            {
                "target": "public.packages.pymongo.v34.pymongo.mongo_client",
                'hook_func': 'detect_mongo_client',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
            {
                "target": "public.packages.pymongo.v34.pymongo.connection",
                'hook_func': 'detect_connection',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
            {
                "target": "public.packages.pymongo.v34.pymongo.collection",
                'hook_func': 'detect_collection',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
        ],
        "mongodb_3.3.0": [
            {
                "target": "public.packages.pymongo.v33.pymongo.mongo_client",
                'hook_func': 'detect_mongo_client',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
            {
                "target": "public.packages.pymongo.v33.pymongo.connection",
                'hook_func': 'detect_connection',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
            {
                "target": "public.packages.pymongo.v33.pymongo.collection",
                'hook_func': 'detect_collection',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
        ],
        "mongodb_3.2.2": [
            {
                "target": "public.packages.pymongo.v32.pymongo.mongo_client",
                'hook_func': 'detect_mongo_client',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
            {
                "target": "public.packages.pymongo.v32.pymongo.connection",
                'hook_func': 'detect_connection',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
            {
                "target": "public.packages.pymongo.v32.pymongo.collection",
                'hook_func': 'detect_collection',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
        ],
        "mongodb_3.1": [
            {
                "target": "public.packages.pymongo.v31.pymongo.mongo_client",
                'hook_func': 'detect_mongo_client',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
            {
                "target": "public.packages.pymongo.v31.pymongo.connection",
                'hook_func': 'detect_connection',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
            {
                "target": "public.packages.pymongo.v31.pymongo.collection",
                'hook_func': 'detect_collection',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
        ],
        "mongodb_3.0": [
            {
                "target": "public.packages.pymongo.v30.pymongo.mongo_client",
                'hook_func': 'detect_mongo_client',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
            {
                "target": "public.packages.pymongo.v30.pymongo.connection",
                'hook_func': 'detect_connection',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
            {
                "target": "public.packages.pymongo.v30.pymongo.collection",
                'hook_func': 'detect_collection',
                'hook_module': 'tingyun.armoury.database_mongo'
            },
        ],

        # nosql redis
        "redis_2.10.5": [
            {
                "target": "public.packages.redis.v2105.redis.connection",
                'hook_func': 'detect_connection',
                'hook_module': 'tingyun.armoury.database_redis'
            },
            {
                "target": "public.packages.redis.v2105.redis.client",
                'hook_func': 'detect_client_operation',
                'hook_module': 'tingyun.armoury.database_redis'
            },
        ],
        "redis_2.9.0": [
            {
                "target": "public.packages.redis.v290.redis.connection",
                'hook_func': 'detect_connection',
                'hook_module': 'tingyun.armoury.database_redis'
            },
            {
                "target": "public.packages.redis.v290.redis.client",
                'hook_func': 'detect_client_operation',
                'hook_module': 'tingyun.armoury.database_redis'
            },
        ],
        "redis_2.8.0": [
            {
                "target": "public.packages.redis.v280.redis.connection",
                'hook_func': 'detect_connection',
                'hook_module': 'tingyun.armoury.database_redis'
            },
            {
                "target": "public.packages.redis.v280.redis.client",
                'hook_func': 'detect_client_operation',
                'hook_module': 'tingyun.armoury.database_redis'
            },
        ],
        "redis_2.7.0": [
            {
                "target": "public.packages.redis.v270.redis.connection",
                'hook_func': 'detect_connection',
                'hook_module': 'tingyun.armoury.database_redis'
            },
            {
                "target": "public.packages.redis.v270.redis.client",
                'hook_func': 'detect_client_operation',
                'hook_module': 'tingyun.armoury.database_redis'
            },
        ],
        "redis_2.6.0": [
            {
                "target": "public.packages.redis.v260.redis.connection",
                'hook_func': 'detect_connection',
                'hook_module': 'tingyun.armoury.database_redis'
            },
            {
                "target": "public.packages.redis.v260.redis.client",
                'hook_func': 'detect_client_operation',
                'hook_module': 'tingyun.armoury.database_redis'
            },
        ],

        # external call
        "urllib": [
            {
                "target": "urllib",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib'
            },
        ],
        "urllib2": [
            {
                "target": "urllib2",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib2'
            },
        ],
        # v1.6-v1.14
        # "urllib3": [
        #     {"target": "urllib3.poolmanager", 'hook_func': 'detect', 'hook_module': 'tingyun.armoury.external_urllib3'},
        # ],
        "urllib3_1.17": [
            {
                "target":
                "public.packages.ex_urllib3.v117.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],
        "urllib3_1.16": [
            {
                "target":
                "public.packages.ex_urllib3.v116.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],
        "urllib3_1.15": [
            {
                "target":
                "public.packages.ex_urllib3.v115.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],
        "urllib3_1.14": [
            {
                "target":
                "public.packages.ex_urllib3.v114.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],
        "urllib3_1.13": [
            {
                "target":
                "public.packages.ex_urllib3.v113.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],
        "urllib3_1.12": [
            {
                "target":
                "public.packages.ex_urllib3.v112.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],
        "urllib3_1.11": [
            {
                "target":
                "public.packages.ex_urllib3.v111.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],
        "urllib3_1.10": [
            {
                "target":
                "public.packages.ex_urllib3.v110.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],
        "urllib3_1.9": [
            {
                "target":
                "public.packages.ex_urllib3.v109.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],
        "urllib3_1.8": [
            {
                "target":
                "public.packages.ex_urllib3.v108.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],
        "urllib3_1.7": [
            {
                "target":
                "public.packages.ex_urllib3.v107.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],
        "urllib3_1.6": [
            {
                "target":
                "public.packages.ex_urllib3.v106.urllib3.poolmanager",
                'hook_func': 'detect',
                'hook_module': 'tingyun.armoury.external_urllib3'
            },
        ],

        # 0.8.0-0.9.3
        # "thrift": [
        #     {"target": "thrift.transport.TSocket", 'hook_func': 'detect_tsocket',
        #      'hook_module': 'tingyun.armoury.external_thrift'},
        #     {"target": "thrift.transport.TSSLSocket", 'hook_func': 'detect_tsslsocket',
        #      'hook_module': 'tingyun.armoury.external_thrift'},
        # ],
        "thrift_0.9.3": [
            {
                "target":
                "public.packages.ex_thrift.v093.thrift.transport.TSocket",
                'hook_func': 'detect_tsocket',
                'hook_module': 'tingyun.armoury.external_thrift'
            },
            {
                "target":
                "public.packages.ex_thrift.v093.thrift.transport.TSSLSocket",
                'hook_func': 'detect_tsslsocket',
                'hook_module': 'tingyun.armoury.external_thrift'
            },
        ],
        "thrift_0.8.0": [
            {
                "target":
                "public.packages.ex_thrift.v080.thrift.transport.TSocket",
                'hook_func': 'detect_tsocket',
                'hook_module': 'tingyun.armoury.external_thrift'
            },
            {
                "target":
                "public.packages.ex_thrift.v080.thrift.transport.TSSLSocket",
                'hook_func': 'detect_tsslsocket',
                'hook_module': 'tingyun.armoury.external_thrift'
            },
        ],

        # 2.0.0-2.10.0
        # "requests": [
        #     {"target": "requests.sessions", 'hook_func': 'detect_requests_sessions',
        #     'hook_module': 'tingyun.armoury.external_requests'},
        # ],
        "requests_2.10.0": [
            {
                "target":
                "public.packages.ex_requests.v2100.requests.sessions",
                'hook_func': 'detect_requests_sessions',
                'hook_module': 'tingyun.armoury.external_requests'
            },
        ],
        "requests_2.9.0": [
            {
                "target": "public.packages.ex_requests.v290.requests.sessions",
                'hook_func': 'detect_requests_sessions',
                'hook_module': 'tingyun.armoury.external_requests'
            },
        ],
        "requests_2.8.0": [
            {
                "target": "public.packages.ex_requests.v280.requests.sessions",
                'hook_func': 'detect_requests_sessions',
                'hook_module': 'tingyun.armoury.external_requests'
            },
        ],
        "requests_2.7.0": [
            {
                "target": "public.packages.ex_requests.v270.requests.sessions",
                'hook_func': 'detect_requests_sessions',
                'hook_module': 'tingyun.armoury.external_requests'
            },
        ],
        "requests_2.6.0": [
            {
                "target": "public.packages.ex_requests.v260.requests.sessions",
                'hook_func': 'detect_requests_sessions',
                'hook_module': 'tingyun.armoury.external_requests'
            },
        ],
        "requests_2.5.0": [
            {
                "target": "public.packages.ex_requests.v250.requests.sessions",
                'hook_func': 'detect_requests_sessions',
                'hook_module': 'tingyun.armoury.external_requests'
            },
        ],
        "requests_2.4.0": [
            {
                "target": "public.packages.ex_requests.v240.requests.sessions",
                'hook_func': 'detect_requests_sessions',
                'hook_module': 'tingyun.armoury.external_requests'
            },
        ],
        "requests_2.3.0": [
            {
                "target": "public.packages.ex_requests.v230.requests.sessions",
                'hook_func': 'detect_requests_sessions',
                'hook_module': 'tingyun.armoury.external_requests'
            },
        ],
        "requests_2.2.0": [
            {
                "target": "public.packages.ex_requests.v220.requests.sessions",
                'hook_func': 'detect_requests_sessions',
                'hook_module': 'tingyun.armoury.external_requests'
            },
        ],
        "requests_2.1.0": [
            {
                "target": "public.packages.ex_requests.v210.requests.sessions",
                'hook_func': 'detect_requests_sessions',
                'hook_module': 'tingyun.armoury.external_requests'
            },
        ],
        "requests_2.0.0": [
            {
                "target": "public.packages.ex_requests.v200.requests.sessions",
                'hook_func': 'detect_requests_sessions',
                'hook_module': 'tingyun.armoury.external_requests'
            },
        ],

        # 0.7.5-0.9.2
        # "httplib2": [
        #     {"target": "httplib2", 'hook_func': 'detect_httplib2_http',
        #      'hook_module': 'tingyun.armoury.external_httplib2'},
        #     {"target": "httplib2", 'hook_func': 'detect_http_connect_with_timeout',
        #      'hook_module': 'tingyun.armoury.external_httplib2'},
        #     {"target": "httplib2", 'hook_func': 'detect_https_connect_with_timeout',
        #      'hook_module': 'tingyun.armoury.external_httplib2'},
        # ],
        "httplib2_0.9.2": [
            {
                "target": "public.packages.ex_httplib2.v092.httplib2",
                'hook_func': 'detect_httplib2_http',
                'hook_module': 'tingyun.armoury.external_httplib2'
            },
            {
                "target": "public.packages.ex_httplib2.v092.httplib2",
                'hook_func': 'detect_http_connect_with_timeout',
                'hook_module': 'tingyun.armoury.external_httplib2'
            },
            {
                "target": "public.packages.ex_httplib2.v092.httplib2",
                'hook_func': 'detect_https_connect_with_timeout',
                'hook_module': 'tingyun.armoury.external_httplib2'
            },
        ],
        "httplib2_0.8": [
            {
                "target": "public.packages.ex_httplib2.v080.httplib2",
                'hook_func': 'detect_httplib2_http',
                'hook_module': 'tingyun.armoury.external_httplib2'
            },
            {
                "target": "public.packages.ex_httplib2.v080.httplib2",
                'hook_func': 'detect_http_connect_with_timeout',
                'hook_module': 'tingyun.armoury.external_httplib2'
            },
            {
                "target": "public.packages.ex_httplib2.v080.httplib2",
                'hook_func': 'detect_https_connect_with_timeout',
                'hook_module': 'tingyun.armoury.external_httplib2'
            },
        ],
        "httplib2_0.7.5": [
            {
                "target": "public.packages.ex_httplib2.v075.httplib2",
                'hook_func': 'detect_httplib2_http',
                'hook_module': 'tingyun.armoury.external_httplib2'
            },
            {
                "target": "public.packages.ex_httplib2.v075.httplib2",
                'hook_func': 'detect_http_connect_with_timeout',
                'hook_module': 'tingyun.armoury.external_httplib2'
            },
            {
                "target": "public.packages.ex_httplib2.v075.httplib2",
                'hook_func': 'detect_https_connect_with_timeout',
                'hook_module': 'tingyun.armoury.external_httplib2'
            },
        ],

        # django, this weapon must not be removed.
        "django": [
            {
                "target": "django.core.handlers.base",
                'hook_func': 'detect_middleware',
                'hook_module': 'tingyun.armoury.framework_django'
            },
            {
                "target": "django.core.handlers.wsgi",
                'hook_func': 'detect_wsgi_entrance',
                'hook_module': 'tingyun.armoury.framework_django'
            },
            {
                "target": "django.core.urlresolvers",
                'hook_func': 'detect_urlresolvers',
                'hook_module': 'tingyun.armoury.framework_django'
            },
            {
                "target": "django.views.generic.base",
                'hook_func': 'detect_views_dispatch',
                'hook_module': 'tingyun.armoury.framework_django'
            },
            {
                "target": "django.template.loader_tags",
                'hook_func': 'detect_template_block_render',
                'hook_module': 'tingyun.armoury.framework_django'
            },
            {
                "target": "django.template.base",
                'hook_func': 'detect_django_template',
                'hook_module': 'tingyun.armoury.framework_django'
            },
            {
                "target": "django.http.multipartparser",
                'hook_func': 'detect_http_multipartparser',
                'hook_module': 'tingyun.armoury.framework_django'
            },
            {
                "target": "django.core.mail",
                'hook_func': 'detect_core_mail',
                'hook_module': 'tingyun.armoury.framework_django'
            },
            {
                "target": "django.core.mail.message",
                'hook_func': 'detect_core_mail_message',
                'hook_module': 'tingyun.armoury.framework_django'
            },
        ],

        # django-piston, 0.2.2.1-0.2.3
        "piston": [
            {
                "target": "piston.resource",
                'hook_func': 'detect_piston_resource',
                'hook_module': 'tingyun.armoury.ammunition.piston'
            },
        ],

        # flask, 0.6-1.0
        "flask": [
            {
                "target": "flask.app",
                'hook_func': 'detect_wsgi_entrance',
                'hook_module': 'tingyun.armoury.framework_flask'
            },
            {
                "target": "flask.app",
                'hook_func': 'detect_app_entrance',
                'hook_module': 'tingyun.armoury.framework_flask'
            },
            {
                "target": "flask.blueprints",
                'hook_func': 'detect_app_blueprint_entrance',
                'hook_module': 'tingyun.armoury.framework_flask'
            },
            {
                "target": "flask.templating",
                'hook_func': 'detect_templates',
                'hook_module': 'tingyun.armoury.framework_flask'
            },
        ],

        # jinja2 2.3-2.8
        'jinja2': [
            {
                "target": "jinja2.loaders",
                'hook_func': 'detect_template_loader',
                'hook_module': 'tingyun.armoury.template_jinja2'
            },
            {
                "target": "jinja2.environment",
                'hook_func': 'detect_jinja2',
                'hook_module': 'tingyun.armoury.template_jinja2'
            },
        ],

        # version 2.8.1-2.12.x
        'web2py': [
            {
                "target": "gluon.main",
                'hook_func': 'detect_wsgi_entrance',
                'hook_module': 'tingyun.armoury.framework_web2py'
            },
            {
                "target": "gluon.compileapp",
                'hook_func': 'detect_compileapp',
                'hook_module': 'tingyun.armoury.framework_web2py'
            },
            {
                "target": "gluon.template",
                'hook_func': 'detect_template',
                'hook_module': 'tingyun.armoury.framework_web2py'
            },
        ],

        # version 0.3.x
        'webpy': [
            {
                "target": "web.application",
                'hook_func': 'detect_wsgi_entrance',
                'hook_module': 'tingyun.armoury.framework_webpy'
            },
            {
                "target": "web.application",
                'hook_func': 'detect_application',
                'hook_module': 'tingyun.armoury.framework_webpy'
            },
        ],

        # version 3.x.x
        # "tornado3": [
        #     {"target": "tornado.wsgi", 'hook_func': 'detect_wsgi_server_entrance',
        #      'hook_module': 'tingyun.armoury.framework_tornado'},
        #     {"target": "tornado.httpserver", 'hook_func': 'detect_tornado_main_process',
        #      'hook_module': 'tingyun.armoury.framework_tornado'},
        #     {"target": "tornado.web", 'hook_func': 'detect_wsgi_app_entrance',
        #      'hook_module': 'tingyun.armoury.framework_tornado'},
        #     {"target": "tornado.web", 'hook_func': 'detect_iostream',
        #      'hook_module': 'tingyun.armoury.framework_tornado'},
        #     {"target": "tornado.simple_httpclient", 'hook_func': 'detect_simple_httpclient',
        #      'hook_module': 'tingyun.armoury.framework_tornado'},
        #     {"target": "tornado.curl_httpclient", 'hook_func': 'detect_curl_httpclient',
        #      'hook_module': 'tingyun.armoury.framework_tornado'},
        # ] if "3." in tornado_version else [],

        # version 4.x.x
        # when tornado only use as wsgi application, do not detect tornado component
        "tornado4": [
            {
                "target": "tornado.web",
                'hook_func': 'detect_handlers',
                'hook_module': 'tingyun.armoury.ammunition.tornado_4.web'
            },
            {
                "target": "tornado.httputil",
                'hook_func': 'detect_tracker_entrance',
                'hook_module': 'tingyun.armoury.ammunition.tornado_4.http_util'
            },
            {
                "target": "tornado.httpserver",
                'hook_func': 'detect_tracker_export',
                'hook_module':
                'tingyun.armoury.ammunition.tornado_4.http_server'
            },
            {
                "target": "tornado.httpclient",
                'hook_func': 'detect_http_client',
                'hook_module':
                'tingyun.armoury.ammunition.tornado_4.http_client'
            },
            {
                "target": "tornado.gen",
                'hook_func': 'detect_gen',
                'hook_module': 'tingyun.armoury.ammunition.tornado_4.gen'
            },
            {
                "target": "tornado.ioloop",
                'hook_func': 'detect_ioloop',
                'hook_module': 'tingyun.armoury.ammunition.tornado_4.ioloop'
            },
            {
                "target": "tornado.concurrent",
                'hook_func': 'detect_concurrent',
                'hook_module':
                'tingyun.armoury.ammunition.tornado_4.concurrent'
            },
            {
                "target": "concurrent.futures",
                'hook_func': 'detect_concurrent',
                'hook_module':
                'tingyun.armoury.ammunition.tornado_4.concurrent'
            },
            {
                "target": "tornado.stack_context",
                'hook_func': 'detect_stack_context',
                'hook_module':
                'tingyun.armoury.ammunition.tornado_4.stack_context'
            },
        ] if "4." in tornado_version
        and not global_settings().tornado_wsgi_adapter_mode else [],
        "tornado-wsgi-adapter-mode": [
            {
                "target": "tornado.web",
                'hook_func': 'detect_handlers',
                'hook_module':
                'tingyun.armoury.ammunition.tornado_4.wsgi_mode.web'
            },
            {
                "target":
                "tornado.httpclient",
                'hook_func':
                'detect_http_client',
                'hook_module':
                'tingyun.armoury.ammunition.tornado_4.wsgi_mode.http_client'
            },
            {
                "target":
                "tornado.wsgi",
                'hook_func':
                'detect_wsgi_entrance',
                'hook_module':
                'tingyun.armoury.ammunition.tornado_4.wsgi_mode.wsgi'
            },
        ] if global_settings().tornado_wsgi_adapter_mode else [],

        # mako v0.7.x-v1.0.x
        "mako": [
            {
                "target": "mako.template",
                'hook_func': 'detect_template',
                'hook_module': 'tingyun.armoury.template_mako'
            },
        ],

        # 0.13.0-1.0.2
        "gevent": [
            {
                "target": "gevent.pywsgi",
                'hook_func': 'detect_wsgi',
                'hook_module': 'tingyun.armoury.matrix.t_gevent'
            },
            {
                "target": "gevent.wsgi",
                'hook_func': 'detect_pywsgi',
                'hook_module': 'tingyun.armoury.matrix.t_gevent'
            },
        ],

        # openstack-nova
        'openstack-nova': [
            # nova.api.openstack.wsgi
            {
                "target": "nova.api.openstack.wsgi",
                'hook_func': 'resource_wsgi_entrance',
                'hook_module': 'tingyun.armoury.nova.api_openstack_wsgi'
            },

            # nova.wsgi
            {
                "target": "nova.wsgi",
                'hook_func': 'middleware_wsgi_entrance',
                'hook_module': 'tingyun.armoury.nova.wsgi'
            },
            {
                "target": "nova.wsgi",
                'hook_func': 'router_wsgi_entrance',
                'hook_module': 'tingyun.armoury.nova.wsgi'
            },

            # nova.api.auth
            {
                "target": "nova.api.auth",
                'hook_func': 'keystone_context_wsgi_entrance',
                'hook_module': 'tingyun.armoury.nova.api_auth'
            },

            # nova.api.ec2
            {
                "target": "nova.api.ec2",
                'hook_func': 'ec2_keystone_wsgi_entrance',
                'hook_module': 'tingyun.armoury.nova.api_ec2'
            },
            {
                "target": "nova.api.ec2",
                'hook_func': 'requestify_wsgi_entrance',
                'hook_module': 'tingyun.armoury.nova.api_ec2'
            },
            {
                "target": "nova.api.ec2",
                'hook_func': 'authorizer_wsgi_entrance',
                'hook_module': 'tingyun.armoury.nova.api_ec2'
            },
            {
                "target": "nova.api.ec2",
                'hook_func': 'executor_wsgi_entrance',
                'hook_module': 'tingyun.armoury.nova.api_ec2'
            },

            # webob.client
            {
                "target": "webob.client",
                'hook_func': 'send_request_wsgi_entrance',
                'hook_module': 'tingyun.armoury.webob.client'
            },
            {
                "target": "webob.response",
                'hook_func': 'response_wsgi_entrance',
                'hook_module': 'tingyun.armoury.webob.response'
            },
        ],
        # bottle 0.10.x-0.12.x
        "bottle": [
            {
                "target": "bottle",
                'hook_func': 'detect_wsgi_entrance',
                'hook_module': 'tingyun.armoury.framework_bottle'
            },
            {
                "target": "bottle",
                'hook_func': 'detect_templates',
                'hook_module': 'tingyun.armoury.framework_bottle'
            },
            {
                "target": "bottle",
                'hook_func': 'detect_app_components',
                'hook_module': 'tingyun.armoury.framework_bottle'
            },
        ]
    }

    return hookers
Exemple #23
0
 def global_settings(self):
     """
     :return:
     """
     return global_settings()