本文整理汇总了Python中utils.platform.get_os函数的典型用法代码示例。如果您正苦于以下问题:Python get_os函数的具体用法?Python get_os怎么用?Python get_os使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_os函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_check
def load_check(name, config, agentConfig):
if not _is_sdk():
checksd_path = agentConfig.get('additional_checksd', get_checksd_path(get_os()))
# find (in checksd_path) and load the check module
fd, filename, desc = imp.find_module(name, [checksd_path])
check_module = imp.load_module(name, fd, filename, desc)
else:
check_module = _load_sdk_module(name) # parent module
check_class = None
classes = inspect.getmembers(check_module, inspect.isclass)
for _, clsmember in classes:
if clsmember == AgentCheck:
continue
if issubclass(clsmember, AgentCheck):
check_class = clsmember
if AgentCheck in clsmember.__bases__:
continue
else:
break
if check_class is None:
raise Exception("Unable to import check %s. Missing a class that inherits AgentCheck" % name)
init_config = config.get('init_config', {})
instances = config.get('instances')
agentConfig['checksd_hostname'] = get_hostname(agentConfig)
# init the check class
try:
return check_class(name, init_config, agentConfig, instances=instances)
except TypeError as e:
raise Exception("Check is using old API, {0}".format(e))
except Exception:
raise
示例2: run_check
def run_check(name, path=None):
"""
Test custom checks on Windows.
"""
# Read the config file
confd_path = path or os.path.join(get_confd_path(get_os()), '%s.yaml' % name)
try:
f = open(confd_path)
except IOError:
raise Exception('Unable to open configuration at %s' % confd_path)
config_str = f.read()
f.close()
# Run the check
check, instances = get_check(name, config_str)
if not instances:
raise Exception('YAML configuration returned no instances.')
for instance in instances:
check.check(instance)
if check.has_events():
print "Events:\n"
pprint(check.get_events(), indent=4)
print "Metrics:\n"
pprint(check.get_metrics(), indent=4)
示例3: get_config_path
def get_config_path(cfg_path=None, os_name=None):
# Check if there's an override and if it exists
if cfg_path is not None and os.path.exists(cfg_path):
return cfg_path
# Check if there's a config stored in the current agent directory
try:
path = os.path.realpath(__file__)
path = os.path.dirname(path)
return _config_path(path)
except PathNotFound as e:
pass
if os_name is None:
os_name = get_os()
# Check for an OS-specific path, continue on not-found exceptions
bad_path = ''
try:
if os_name == 'windows':
return _windows_config_path()
elif os_name == 'mac':
return _mac_config_path()
else:
return _unix_config_path()
except PathNotFound as e:
if len(e.args) > 0:
bad_path = e.args[0]
# If all searches fail, exit the agent with an error
sys.stderr.write("Please supply a configuration file at %s or in the directory where "
"the Agent is currently deployed.\n" % bad_path)
sys.exit(3)
示例4: load_check
def load_check(agentConfig, hostname, checkname):
"""Same logic as load_check_directory except it loads one specific check"""
agentConfig['checksd_hostname'] = hostname
osname = get_os()
checks_places = get_checks_places(osname, agentConfig)
for config_path in _file_configs_paths(osname, agentConfig):
check_name = _conf_path_to_check_name(config_path)
if check_name == checkname:
conf_is_valid, check_config, invalid_check = _load_file_config(config_path, check_name, agentConfig)
if invalid_check and not conf_is_valid:
return invalid_check
# try to load the check and return the result
load_success, load_failure = load_check_from_places(check_config, check_name, checks_places, agentConfig)
return load_success.values()[0] or load_failure
# the check was not found, try with service discovery
for check_name, service_disco_check_config in _service_disco_configs(agentConfig).iteritems():
if check_name == checkname:
sd_init_config, sd_instances = service_disco_check_config
check_config = {'init_config': sd_init_config, 'instances': sd_instances}
# try to load the check and return the result
load_success, load_failure = load_check_from_places(check_config, check_name, checks_places, agentConfig)
return load_success.values()[0] or load_failure
return None
示例5: get_checksd_path
def get_checksd_path(osname=None):
if not osname:
osname = get_os()
if osname == 'windows':
return _windows_checksd_path()
elif osname == 'mac':
return _mac_checksd_path()
else:
return _unix_checksd_path()
示例6: get_sdk_integrations_path
def get_sdk_integrations_path(osname=None):
if not osname:
osname = get_os()
if osname in ['windows', 'mac']:
raise PathNotFound()
cur_path = os.path.dirname(os.path.realpath(__file__))
path = os.path.join(cur_path, '..', SDK_INTEGRATIONS_DIR)
if os.path.exists(path):
return path
raise PathNotFound(path)
示例7: get_config
def get_config(parse_args=True, cfg_path=None, options=None):
if parse_args:
options, _ = get_parsed_args()
# General config
agentConfig = {
'version': AGENT_VERSION,
'recv_port':8225,
'hostname': None,
'utf8_decoding': False,
'check_freq': DEFAULT_CHECK_FREQUENCY,
'run_plugins':[]
}
# Find the right config file
path = os.path.realpath(__file__)
path = os.path.dirname(path)
config_path = get_config_path(cfg_path, os_name=get_os())
config = ConfigParser.ConfigParser()
config.readfp(skip_leading_wsp(open(config_path)))
# bulk import
for option in config.options('Main'):
agentConfig[option] = config.get('Main', option)
# Allow an override with the --profile option
if options is not None and options.profile:
agentConfig['developer_mode'] = True
# Core config
# ap
if not config.has_option('Main', 'api_key'):
log.warning(u"No API key was found. Aborting.")
sys.exit(2)
if not config.has_option('Main', 'secret_key'):
log.warning(u"No SECRET key was found. Aborting.")
sys.exit(2)
if not config.has_option('Main', 'linklog_url'):
log.warning(u"No linklog_url was found. Aborting.")
sys.exit(2)
if config.has_option('Main', 'check_freq'):
try:
agentConfig['check_freq'] = int(config.get('Main', 'check_freq'))
except Exception:
pass
if config.has_option('Main', 'run_plugins'):
try:
agentConfig['run_plugins'] = config.get('Main', 'run_plugins').split(',')
except Exception:
pass
return agentConfig
示例8: load_class
def load_class(check_name, class_name):
"""
Retrieve a class with the given name within the given check module.
"""
checksd_path = get_checksd_path(get_os())
if checksd_path not in sys.path:
sys.path.append(checksd_path)
check_module = __import__(check_name)
classes = inspect.getmembers(check_module, inspect.isclass)
for name, clsmember in classes:
if name == class_name:
return clsmember
raise Exception(u"Unable to import class {0} from the check module.".format(class_name))
示例9: _get_logging_config
def _get_logging_config(cfg_path=None):
levels = {
'CRITICAL': logging.CRITICAL,
'DEBUG': logging.DEBUG,
'ERROR': logging.ERROR,
'FATAL': logging.FATAL,
'INFO': logging.INFO,
'WARN': logging.WARN,
'WARNING': logging.WARNING,
}
config_path = get_config_path(cfg_path, os_name=get_os())
config = ConfigParser.ConfigParser()
config.readfp(skip_leading_wsp(open(config_path)))
logging_config = {
'log_level': logging.INFO,
}
if config.has_option('Main', 'log_level'):
logging_config['log_level'] = levels.get(config.get('Main', 'log_level'))
if config.has_option('Main', 'disable_file_logging'):
logging_config['disable_file_logging'] = config.get('Main', 'disable_file_logging').strip().lower() in ['yes', 'true', 1]
else:
logging_config['disable_file_logging'] = False
system_os = get_os()
global BASE_LOG_DIR
if system_os != 'windows' and not logging_config['disable_file_logging']:
if not os.access(BASE_LOG_DIR, os.R_OK | os.W_OK):
print("{0} dir is not writeable, so change it to local".format(BASE_LOG_DIR))
BASE_LOG_DIR = "logs"
logging_config['collector_log_file'] = '{0}/collector.log'.format(BASE_LOG_DIR)
logging_config['forwarder_log_file'] = '{0}/forwarder.log'.format(BASE_LOG_DIR)
logging_config['{0}_log_file'.format(__name__)] = '{0}/monitor.log'.format(BASE_LOG_DIR)
return logging_config
示例10: get_check_class
def get_check_class(name):
checksd_path = get_checksd_path(get_os())
if checksd_path not in sys.path:
sys.path.append(checksd_path)
check_module = __import__(name)
check_class = None
classes = inspect.getmembers(check_module, inspect.isclass)
for _, clsmember in classes:
if clsmember == AgentCheck:
continue
if issubclass(clsmember, AgentCheck):
check_class = clsmember
if AgentCheck in clsmember.__bases__:
continue
else:
break
return check_class
示例11: _load_sdk_module
def _load_sdk_module(name):
sdk_path = get_sdk_integrations_path(get_os())
module_path = os.path.join(sdk_path, name)
sdk_module_name = "_{}".format(name)
if sdk_module_name in sys.modules:
return sys.modules[sdk_module_name]
if sdk_path not in sys.path:
sys.path.append(sdk_path)
if module_path not in sys.path:
sys.path.append(module_path)
fd, filename, desc = imp.find_module('check', [module_path])
module = imp.load_module("_{}".format(name), fd, filename, desc)
if fd:
fd.close()
# module = __import__(module_name, fromlist=['check'])
return module
示例12: get_confd_path
def get_confd_path(osname=None):
try:
cur_path = os.path.dirname(os.path.realpath(__file__))
return _confd_path(cur_path)
except PathNotFound as e:
pass
if not osname:
osname = get_os()
bad_path = ''
try:
if osname == 'windows':
return _windows_confd_path()
elif osname == 'mac':
return _mac_confd_path()
else:
return _unix_confd_path()
except PathNotFound as e:
if len(e.args) > 0:
bad_path = e.args[0]
raise PathNotFound(bad_path)
示例13: _load_sdk_module
def _load_sdk_module(name):
try:
# see whether the check was installed as a wheel package
return import_module("datadog_checks.{}".format(name))
except ImportError:
sdk_path = get_sdk_integrations_path(get_os())
module_path = os.path.join(sdk_path, name)
sdk_module_name = "_{}".format(name)
if sdk_module_name in sys.modules:
return sys.modules[sdk_module_name]
if sdk_path not in sys.path:
sys.path.append(sdk_path)
if module_path not in sys.path:
sys.path.append(module_path)
fd, filename, desc = imp.find_module('check', [module_path])
module = imp.load_module("_{}".format(name), fd, filename, desc)
if fd:
fd.close()
# module = __import__(module_name, fromlist=['check'])
return module
示例14: get_check
def get_check(name, config_str):
from checks import AgentCheck
checksd_path = get_checksd_path(get_os())
if checksd_path not in sys.path:
sys.path.append(checksd_path)
check_module = __import__(name)
check_class = None
classes = inspect.getmembers(check_module, inspect.isclass)
for name, clsmember in classes:
if issubclass(clsmember, AgentCheck) and clsmember != AgentCheck:
check_class = clsmember
break
if check_class is None:
raise Exception("Unable to import check %s. Missing a class that inherits AgentCheck" % name)
agentConfig = {
'version': '0.1',
'api_key': 'tota'
}
return check_class.from_yaml(yaml_text=config_str, check_name=name,
agentConfig=agentConfig)
示例15: get_sdk_integrations_path
def get_sdk_integrations_path(osname=None):
if not osname:
osname = get_os()
if os.environ.get('INTEGRATIONS_DIR'):
if os.environ.get('TRAVIS'):
path = os.environ['TRAVIS_BUILD_DIR']
elif os.environ.get('CIRCLECI'):
path = os.path.join(
os.environ['HOME'],
os.environ['CIRCLE_PROJECT_REPONAME']
)
elif os.environ.get('APPVEYOR'):
path = os.environ['APPVEYOR_BUILD_FOLDER']
else:
cur_path = os.environ['INTEGRATIONS_DIR']
path = os.path.join(cur_path, '..') # might need tweaking in the future.
else:
cur_path = os.path.dirname(os.path.realpath(__file__))
path = os.path.join(cur_path, '..', SDK_INTEGRATIONS_DIR)
if os.path.exists(path):
return path
raise PathNotFound(path)