def license_key(args): import os import sys import logging if len(args) == 0: usage('license-key') sys.exit(1) from blueware.agent import global_settings, initialize if len(args) >= 2: log_file = args[1] else: log_file = '/tmp/python-agent-test.log' log_level = logging.DEBUG try: os.unlink(log_file) except Exception: pass config_file = args[0] environment = os.environ.get('BLUEWARE_ENVIRONMENT') if config_file == '-': config_file = os.environ.get('BLUEWARE_CONFIG_FILE') initialize(config_file, environment, ignore_errors=False, log_file=log_file, log_level=log_level) _settings = global_settings() print('license_key = %r' % _settings.license_key)
def server_config(args): import os import sys import logging import time if len(args) == 0: usage('server-config') sys.exit(1) from blueware.agent import initialize, register_application if len(args) >= 2: log_file = args[1] else: log_file = '/tmp/python-agent-test.log' log_level = logging.DEBUG try: os.unlink(log_file) except Exception: pass config_file = args[0] environment = os.environ.get('BLUEWARE_ENVIRONMENT') if config_file == '-': config_file = os.environ.get('BLUEWARE_CONFIG_FILE') initialize(config_file, environment, ignore_errors=False, log_file=log_file, log_level=log_level) _timeout = 30.0 _start = time.time() _application = register_application(timeout=_timeout) _end = time.time() _duration = _end - _start _logger = logging.getLogger(__name__) if not _application.active: _logger.error('Unable to register application for test, ' 'connection could not be established within %s seconds.', _timeout) return _logger.debug('Registration took %s seconds.', _duration) for key, value in sorted(_application.settings): print('%s = %r' % (key, value))
def network_config(args): import os import sys import logging if len(args) == 0: usage('network-config') sys.exit(1) from blueware.agent import global_settings, initialize if len(args) >= 2: log_file = args[1] else: log_file = '/tmp/python-agent-test.log' log_level = logging.DEBUG try: os.unlink(log_file) except Exception: pass config_file = args[0] environment = os.environ.get('BLUEWARE_ENVIRONMENT') if config_file == '-': config_file = os.environ.get('BLUEWARE_CONFIG_FILE') initialize(config_file, environment, ignore_errors=False, log_file=log_file, log_level=log_level) _settings = global_settings() print('host = %r' % _settings.host) print('port = %r' % _settings.port) print('proxy_scheme = %r' % _settings.proxy_host) print('proxy_host = %r' % _settings.proxy_host) print('proxy_port = %r' % _settings.proxy_port) print('proxy_user = %r' % _settings.proxy_user) print('proxy_pass = %r' % _settings.proxy_pass) print('ssl = %r' % _settings.ssl)
def validate_config(args): import os import sys import logging import time if len(args) == 0: usage('validate-config') sys.exit(1) from blueware.agent import (global_settings, initialize, register_application) if len(args) >= 2: log_file = args[1] else: log_file = '/tmp/python-agent-test.log' log_level = logging.DEBUG try: os.unlink(log_file) except Exception: pass config_file = args[0] environment = os.environ.get('BLUEWARE_ENVIRONMENT') if config_file == '-': config_file = os.environ.get('BLUEWARE_CONFIG_FILE') initialize(config_file, environment, ignore_errors=False, log_file=log_file, log_level=log_level) _logger = logging.getLogger(__name__) _logger.debug('Starting agent validation.') _settings = global_settings() app_name = os.environ.get('BLUEWARE_TEST_APP_NAME', 'Python Agent Test') _settings.app_name = app_name _settings.transaction_tracer.transaction_threshold = 0 _settings.shutdown_timeout = 30.0 _settings.debug.log_malformed_json_data = True _settings.debug.log_data_collector_payloads = True _settings.debug.log_transaction_trace_payload = True print(_user_message % dict(app_name=app_name, log_file=log_file)) _logger.debug('Register test application.') _logger.debug('Collector host is %r.', _settings.host) _logger.debug('Collector port is %r.', _settings.port) _logger.debug('Proxy scheme is %r.', _settings.proxy_scheme) _logger.debug('Proxy host is %r.', _settings.proxy_host) _logger.debug('Proxy port is %r.', _settings.proxy_port) _logger.debug('Proxy user is %r.', _settings.proxy_user) _logger.debug('SSL enabled is %r.', _settings.ssl) _logger.debug('License key is %r.', _settings.license_key) _timeout = 30.0 _start = time.time() _application = register_application(timeout=_timeout) _end = time.time() _duration = _end - _start if not _application.active: _logger.error('Unable to register application for test, ' 'connection could not be established within %s seconds.', _timeout) return if hasattr(_application.settings, 'messages'): for message in _application.settings.messages: if message['message'].startswith('Reporting to:'): parts = message['message'].split('Reporting to:') url = parts[1].strip() print('Registration successful. Reporting to:') print() print(' %s' % url) print() break _logger.debug('Registration took %s seconds.', _duration) _logger.debug('Run the validation test.') _run_validation_test()