コード例 #1
0
def create_connection(license_key, app_name, linked_applications, machine_env,
                      settings):
    """
    :return:
    """
    start_time = time.time()

    if not license_key:
        license_key = settings.license_key

    if not license_key:
        console.error(
            "license key should be provided in tingyun.ini config file, agent may can not started."
        )

    try:
        console.info(
            "init app with license: %s, app: %s, link app: %s, env: %s, settings: %s, upload settings: %s",
            license_key, app_name, linked_applications, machine_env, settings,
            get_upload_settings())

        # when private the agent. we should get redirect with port set in settings
        url = connect_url("getRedirectHost", with_port=True)
        param = {"licenseKey": license_key, "version": settings.data_version}
        redirect_host = transmitter(None, url, "getRedirectHost", {}, param)
        local_conf = {
            "host": socket.gethostname(),
            "appName": [app_name] + linked_applications,
            "language": "Python",
            "agentVersion": settings.agent_version,
            "config": get_upload_settings(),
            "env": machine_env
        }

        # At second step. we need not the port with url. because the returned redirect url take it or has default 80.
        url = connect_url("initAgentApp", redirect_host, with_port=False)
        server_conf = transmitter(None, url, "initAgentApp", local_conf,
                                  {"licenseKey": license_key})
        app_config = merge_settings(server_conf)
    except Exception as err:
        console.error("errors when connect to server %s", err)
        raise RetryDataForRequest(
            "Errors occurred, when create session with server. %s" % err)
    else:
        console.info(
            "Successful register application to agent server with name: %s, use time: %ss",
            app_name,
            time.time() - start_time)

        url = connect_url("upload", redirect_host)
        return Engine(url, app_config, license_key, redirect_host)
コード例 #2
0
    def send_sql_trace(self, sql_trace):
        """
        """
        if not sql_trace:
            return

        return transmitter(self.session, self.url, "send_sql_trace", sql_trace,
                           self.request_param, self.config.audit_mode)
コード例 #3
0
    def send_external_error_trace(self, external_error_trace):
        """
        """
        if not external_error_trace:
            return

        return transmitter(self.session, self.url, "send_external_error_trace",
                           external_error_trace, self.request_param,
                           self.config.audit_mode)
コード例 #4
0
    def request_agent_commands(self):
        """
        """
        url = connect_url("getAgentCommands", self.redirect_host)
        audit_mode = self.config.audit_mode
        result = transmitter(self.session, url, "get_agent_commands", {},
                             self.request_param, audit_mode)

        return result
コード例 #5
0
    def send_profile_data(self, data):
        """it allow to send empty data.
        """
        audit_mode = self.config.audit_mode
        url = connect_url("uploadAgentCommands", self.redirect_host)
        if not data:
            return

        return transmitter(self.session, url, "send_profile_data", data,
                           self.request_param, audit_mode)
コード例 #6
0
    def send_exception_trace(self, ex):
        """
        :param ex:
        :return:
        """
        if not ex:
            return

        return transmitter(self.session, self.url, "send_exception_trace", ex,
                           self.request_param, self.config.audit_mode)
コード例 #7
0
ファイル: test_transportation.py プロジェクト: xuning992/tfty
    def test_transmitter(self):
        """
        """
        # prepare the log environment for test
        test_log = os.path.join(os.path.dirname(__file__), "test.log")
        initialize_logging(test_log, logging.DEBUG)

        url = connect_url("getRedirectHost")
        # redirect_url = transmitter(None, url, "getRedirectHost", param={"licenseKey": "999-999-999"})
        # self.assertTrue(redirect_url, "get url error.")

        try:
            host = transmitter(None,
                               url,
                               "getRedirectHost",
                               param={"licenseKey": "8sadf8-8fsd8-fds88"})
        except Exception as _:
            host = ""
        # self.assertTrue(host in redirect_hosts, "")

        local_conf = {
            "host": "dev.agent.com",
            "appName": [
                "PythonApp",
            ],
            "language": "Python",
            "agentVersion": "1.0",
            "config": {
                "nbs.enabled": "true"
            },
            "env": {
                "Os": "linux"
            }
        }

        # url = connect_url("initAgentApp", host, with_port=False)
        # server_conf = transmitter(None, url, "initAgentApp", local_conf, {"licenseKey": "999-999-999"})
        #
        # self.assertTrue("config" in server_conf, "")
        # self.assertTrue(isinstance(server_conf["config"], dict), "")
        #
        # self.assertTrue("applicationId" in server_conf, "")
        # self.assertTrue("enabled" in server_conf, "")
        # self.assertTrue("appSessionKey" in server_conf, "")
        # self.assertTrue("dataSentInterval" in server_conf, "")
        # self.assertTrue("apdex_t" in server_conf, "")

        if os.path.isfile(test_log):
            os.remove(test_log)
コード例 #8
0
 def send_performance_metric(self, metric_data):
     """
     """
     return transmitter(self.session, self.url, "send_collect_data",
                        metric_data, self.request_param,
                        self.config.audit_mode)