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 data_source(args): import sys if len(args) == 0: usage('data-source') sys.exit(1) from blueware.platform import run run(*args)
def data_source(args): import sys if len(args) == 0: usage('data-source') sys.exit(1) from blueware.platform import run run(*args)
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 license_info(args): import os import sys if len(args) != 0: usage('license-info') sys.exit(1) from blueware import __file__ as package_root package_root = os.path.dirname(package_root) license_file = os.path.join(package_root, 'LICENSE') license = open(license_file, 'r').read() print(license, end='')
def license_info(args): import os import sys if len(args) != 0: usage('license-info') sys.exit(1) from blueware import __file__ as package_root package_root = os.path.dirname(package_root) license_file = os.path.join(package_root, 'LICENSE') license = open(license_file, 'r').read() print(license, end='')
def debug_console(args): import sys if len(args) == 0: usage('debug-console') sys.exit(1) from blueware.console import ClientShell config_file = args[0] log_object = None if len(args) >= 2: log_object = open(args[1], 'w') shell = ClientShell(config_file, log=log_object) shell.cmdloop()
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 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 generate_config(args): import os import sys if len(args) == 0: usage('generate-config') sys.exit(1) from blueware import __file__ as package_root package_root = os.path.dirname(package_root) config_file = os.path.join(package_root, 'blueware.ini') content = open(config_file, 'r').read() if len(args) >= 1: content = content.replace('*** REPLACE ME ***', args[0]) if len(args) >= 2 and args[1] != '-': output_file = open(args[1], 'w') output_file.write(content) output_file.close() else: print(content)
def generate_config(args): import os import sys if len(args) == 0: usage('generate-config') sys.exit(1) from blueware import __file__ as package_root package_root = os.path.dirname(package_root) config_file = os.path.join(package_root, 'blueware.ini') content = open(config_file, 'r').read() if len(args) >= 1: content = content.replace('*** REPLACE ME ***', args[0]) if len(args) >= 2 and args[1] != '-': output_file = open(args[1], 'w') output_file.write(content) output_file.close() else: print(content)
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()
def run_program(args): import os import sys import time if len(args) == 0: usage('run-program') sys.exit(1) startup_debug = os.environ.get('BLUEWARE_STARTUP_DEBUG', 'off').lower() in ('on', 'true', '1') def log_message(text, *args): if startup_debug: text = text % args timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) print('BLUEWARE: %s (%d) - %s' % (timestamp, os.getpid(), text)) log_message('blueware Admin Script (%s)', __file__) log_message('working_directory = %r', os.getcwd()) log_message('current_command = %r', sys.argv) log_message('sys.prefix = %r', os.path.normpath(sys.prefix)) try: log_message('sys.real_prefix = %r', sys.real_prefix) except AttributeError: pass log_message('sys.version_info = %r', sys.version_info) log_message('sys.executable = %r', sys.executable) log_message('sys.flags = %r', sys.flags) log_message('sys.path = %r', sys.path) for name in sorted(os.environ.keys()): if name.startswith('BLUEWARE_') or name.startswith('PYTHON'): log_message('%s = %r', name, os.environ.get(name)) from blueware import version, __file__ as root_directory root_directory = os.path.dirname(root_directory) boot_directory = os.path.join(root_directory, 'bootstrap') log_message('root_directory = %r', root_directory) log_message('boot_directory = %r', boot_directory) python_path = boot_directory if 'PYTHONPATH' in os.environ: path = os.environ['PYTHONPATH'].split(os.path.pathsep) if not boot_directory in path: python_path = "%s%s%s" % (boot_directory, os.path.pathsep, os.environ['PYTHONPATH']) os.environ['PYTHONPATH'] = python_path os.environ['BLUEWARE_ADMIN_COMMAND'] = repr(sys.argv) os.environ['BLUEWARE_PYTHON_PREFIX'] = os.path.realpath( os.path.normpath(sys.prefix)) os.environ['BLUEWARE_PYTHON_VERSION'] = '.'.join( map(str, sys.version_info[:2])) # If not an absolute or relative path, then we need to # see if program can be found in PATH. Note that can # be found in current working directory even though '.' # not in PATH. program_exe_path = args[0] if not os.path.dirname(program_exe_path): program_search_path = os.environ.get('PATH', '').split(os.path.pathsep) for path in program_search_path: path = os.path.join(path, program_exe_path) if os.path.exists(path) and os.access(path, os.X_OK): program_exe_path = path break log_message('program_exe_path = %r', program_exe_path) log_message('execl_arguments = %r', [program_exe_path]+args) os.execl(program_exe_path, *args)