• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.check_yaml函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中util.check_yaml函数的典型用法代码示例。如果您正苦于以下问题:Python check_yaml函数的具体用法?Python check_yaml怎么用?Python check_yaml使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了check_yaml函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self):
        self.docker_util = DockerUtil()
        try:
            config_file_path = get_conf_path(KUBERNETES_CHECK_NAME)
            check_config = check_yaml(config_file_path)
            instance = check_config['instances'][0]
        # kubernetes.yaml was not found
        except IOError as ex:
            log.error(ex.message)
            instance = {}
        except Exception:
            log.error('Kubernetes configuration file is invalid. '
                      'Trying connecting to kubelet with default settings anyway...')
            instance = {}

        self.method = instance.get('method', KubeUtil.DEFAULT_METHOD)
        self.host = instance.get("host") or self.docker_util.get_hostname()

        self.cadvisor_port = instance.get('port', KubeUtil.DEFAULT_CADVISOR_PORT)
        self.kubelet_port = instance.get('kubelet_port', KubeUtil.DEFAULT_KUBELET_PORT)

        self.metrics_url = urljoin(
            '%s://%s:%d' % (self.method, self.host, self.cadvisor_port), KubeUtil.METRICS_PATH)
        self.pods_list_url = urljoin(
            '%s://%s:%d' % (self.method, self.host, self.kubelet_port), KubeUtil.PODS_LIST_PATH)

        self.kube_health_url = '%s://%s:%d/healthz' % (self.method, self.host, self.kubelet_port)
开发者ID:DylanFrese,项目名称:dd-agent,代码行数:27,代码来源:kubeutil.py


示例2: get_auto_conf_images

def get_auto_conf_images(agentConfig):
    """Walk through the auto_config folder and build a dict of auto-configurable images."""
    from config import PathNotFound, get_auto_confd_path
    auto_conf_images = {
        # image_name: check_name
    }

    try:
        auto_confd_path = get_auto_confd_path()
    except PathNotFound:
        log.error("Couldn't find the check auto-configuration folder, no auto configuration will be used.")
        return None

    # walk through the auto-config dir
    for yaml_file in os.listdir(auto_confd_path):
        check_name = yaml_file.split('.')[0]
        try:
            # load the config file
            auto_conf = check_yaml(urljoin(auto_confd_path, yaml_file))
        except Exception as e:
            log.error("Enable to load the auto-config, yaml file.\n%s" % str(e))
            auto_conf = {}
        # extract the supported image list
        images = auto_conf.get('docker_images', [])
        for image in images:
            auto_conf_images[image] = check_name
    return auto_conf_images
开发者ID:abhilash07,项目名称:dd-agent,代码行数:27,代码来源:checkfiles.py


示例3: get_check_config

    def get_check_config(self):
        """Read the config from docker_daemon.yaml"""
        from util import check_yaml
        from utils.checkfiles import get_conf_path
        init_config, instances = {}, []
        try:
            conf_path = get_conf_path(CHECK_NAME)
        except IOError as ex:
            log.debug(ex.message)
            return init_config, {}

        if conf_path is not None and os.path.exists(conf_path):
            try:
                check_config = check_yaml(conf_path)
                init_config, instances = check_config.get('init_config', {}), check_config['instances']
                init_config = {} if init_config is None else init_config
            except Exception:
                log.exception('Docker check configuration file is invalid. The docker check and '
                              'other Docker related components will not work.')
                init_config, instances = {}, []

        if len(instances) > 0:
            instance = instances[0]
        else:
            instance = {}
            log.error('No instance was found in the docker check configuration.'
                      ' Docker related collection will not work.')
        return init_config, instance
开发者ID:MinerKasch,项目名称:dd-agent,代码行数:28,代码来源:dockerutil.py


示例4: __init__

    def __init__(self, instance=None):
        self.docker_util = DockerUtil()
        if instance is None:
            try:
                config_file_path = get_conf_path(KUBERNETES_CHECK_NAME)
                check_config = check_yaml(config_file_path)
                instance = check_config['instances'][0]
            # kubernetes.yaml was not found
            except IOError as ex:
                log.error(ex.message)
                instance = {}
            except Exception:
                log.error('Kubernetes configuration file is invalid. '
                          'Trying connecting to kubelet with default settings anyway...')
                instance = {}

        self.method = instance.get('method', KubeUtil.DEFAULT_METHOD)
        self.host = instance.get("host") or self.docker_util.get_hostname()
        self._node_ip = self._node_name = None  # lazy evaluation
        self.host_name = os.environ.get('HOSTNAME')

        self.cadvisor_port = instance.get('port', KubeUtil.DEFAULT_CADVISOR_PORT)
        self.kubelet_port = instance.get('kubelet_port', KubeUtil.DEFAULT_KUBELET_PORT)

        self.kubelet_api_url = '%s://%s:%d' % (self.method, self.host, self.kubelet_port)
        self.cadvisor_url = '%s://%s:%d' % (self.method, self.host, self.cadvisor_port)
        self.kubernetes_api_url = 'https://%s/api/v1' % (os.environ.get('KUBERNETES_SERVICE_HOST') or self.DEFAULT_MASTER_NAME)

        self.metrics_url = urljoin(self.cadvisor_url, KubeUtil.METRICS_PATH)
        self.pods_list_url = urljoin(self.kubelet_api_url, KubeUtil.PODS_LIST_PATH)
        self.kube_health_url = urljoin(self.kubelet_api_url, 'healthz')

        # keep track of the latest k8s event we collected and posted
        # default value is 0 but TTL for k8s events is one hour anyways
        self.last_event_collection_ts = defaultdict(int)
开发者ID:AltSchool,项目名称:dd-agent,代码行数:35,代码来源:kubeutil.py


示例5: __init__

    def __init__(self):
        config_file_path = get_conf_path(KUBERNETES_CHECK_NAME)
        try:
            check_config = check_yaml(config_file_path)
            instance = check_config['instances'][0]
        except Exception:
            log.error('Kubernetes configuration file is invalid. '
                      'Trying connecting to kubelet with default settings anyway...')
            instance = {}

        self.method = instance.get('method', KubeUtil.DEFAULT_METHOD)
        self.host = instance.get("host") or self._get_default_router()
        self.master_host = instance.get('master_host', self.host)

        self.cadvisor_port = instance.get('port', KubeUtil.DEFAULT_CADVISOR_PORT)
        self.kubelet_port = instance.get('kubelet_port', KubeUtil.DEFAULT_KUBELET_PORT)
        self.master_port = instance.get('master_port', KubeUtil.DEFAULT_MASTER_PORT)

        self.metrics_url = urljoin(
            '%s://%s:%d' % (self.method, self.host, self.cadvisor_port), KubeUtil.METRICS_PATH)
        self.pods_list_url = urljoin(
            '%s://%s:%d' % (self.method, self.host, self.kubelet_port), KubeUtil.PODS_LIST_PATH)

        self.master_url_nodes = '%s://%s:%d/api/v1/nodes' % (self.method, self.master_host, self.master_port)
        self.kube_health_url = '%s://%s:%d/healthz' % (self.method, self.host, self.kubelet_port)
开发者ID:jsh2134,项目名称:dd-agent,代码行数:25,代码来源:kubeutil.py


示例6: configcheck

def configcheck():
    all_valid = True
    for conf_path in glob.glob(os.path.join(get_confd_path(), "*.yaml")):
        basename = os.path.basename(conf_path)
        try:
            check_yaml(conf_path)
        except NoInstancesFound as e:
            print "%s contains warning:\n    %s" % (basename, e)
        except Exception as e:
            all_valid = False
            print "%s contains errors:\n    %s" % (basename, e)
        else:
            print "%s is valid" % basename
    if all_valid:
        print "All yaml files passed. You can now run the ServerDensity agent."
        return 0
    else:
        print("Fix the invalid yaml files above in order to start the sd-agent. "
              "A useful external tool for yaml parsing can be found at "
              "http://yaml-online-parser.appspot.com/")
        return 1
开发者ID:serverdensity,项目名称:sd-agent,代码行数:21,代码来源:configcheck.py


示例7: _load_file_config

def _load_file_config(config_path, check_name, agentConfig):
    if config_path == 'deprecated/nagios':
        log.warning("Configuring Nagios in datadog.conf is deprecated "
                    "and will be removed in a future version. "
                    "Please use conf.d")
        check_config = {'instances': [dict((key, value) for (key, value) in agentConfig.iteritems() if key in NAGIOS_OLD_CONF_KEYS)]}
        return True, check_config, {}

    try:
        check_config = check_yaml(config_path)
    except Exception, e:
        log.exception("Unable to parse yaml config in %s" % config_path)
        traceback_message = traceback.format_exc()
        return False, None, {check_name: {'error': str(e), 'traceback': traceback_message}}
开发者ID:awasilyev,项目名称:dd-agent,代码行数:14,代码来源:config.py


示例8: detect_is_k8s

def detect_is_k8s():
    """
    Logic for DockerUtil to detect whether to enable Kubernetes code paths
    It check whether we have a KUBERNETES_PORT environment variable (running
    in a pod) or a valid kubernetes.yaml conf file
    """
    if 'KUBERNETES_PORT' in os.environ:
        return True
    else:
        try:
            k8_config_file_path = get_conf_path(KUBERNETES_CHECK_NAME)
            k8_check_config = check_yaml(k8_config_file_path)
            return len(k8_check_config['instances']) > 0
        except Exception as err:
            log.debug("Error detecting kubernetes: %s" % str(err))
            return False
开发者ID:DataDog,项目名称:dd-agent,代码行数:16,代码来源:kubeutil.py


示例9: get_auto_conf_images

def get_auto_conf_images(full_tpl=False):
    """Walk through the auto_config folder and build a dict of auto-configurable images."""
    from config import PathNotFound, get_auto_confd_path
    auto_conf_images = {
        # image_name: [check_names] or [[check_names], [init_tpls], [instance_tpls]]
    }

    try:
        auto_confd_path = get_auto_confd_path()
    except PathNotFound:
        log.error("Couldn't find the check auto-configuration folder, no auto configuration will be used.")
        return None

    # walk through the auto-config dir
    for yaml_file in os.listdir(auto_confd_path):
        # Ignore files that do not end in .yaml
        extension = yaml_file.split('.')[-1]
        if extension != 'yaml':
            continue
        else:
            check_name = yaml_file.split('.')[0]
            try:
                # load the config file
                auto_conf = check_yaml(urljoin(auto_confd_path, yaml_file))
            except Exception as e:
                log.error("Unable to load the auto-config, yaml file.\n%s" % str(e))
                auto_conf = {}
            # extract the supported image list
            images = auto_conf.get('docker_images', [])
            for image in images:
                if full_tpl:
                    init_tpl = auto_conf.get('init_config') or {}
                    instance_tpl = auto_conf.get('instances', [])
                    if image not in auto_conf_images:
                        auto_conf_images[image] = [[check_name], [init_tpl], [instance_tpl]]
                    else:
                        for idx, item in enumerate([check_name, init_tpl, instance_tpl]):
                            auto_conf_images[image][idx].append(item)
                else:
                    if image in auto_conf_images:
                        auto_conf_images[image].append(check_name)
                    else:
                        auto_conf_images[image] = [check_name]

    return auto_conf_images
开发者ID:alq666,项目名称:dd-agent,代码行数:45,代码来源:checkfiles.py


示例10: __init__

    def __init__(self, config=None):
        try:
            if config:
                ntp_config = config
            else:
                ntp_config = check_yaml(os.path.join(get_confd_path(), 'ntp.yaml'))
            settings = ntp_config['instances'][0]
        except Exception:
            settings = {}

        self.host = settings.get('host') or "{0}.datadog.pool.ntp.org".format(random.randint(0, 3))
        self.version = int(settings.get("version") or NTPUtil.DEFAULT_VERSION)
        self.port = settings.get('port') or NTPUtil.DEFAULT_PORT
        self.timeout = float(settings.get('timeout') or NTPUtil.DEFAULT_TIMEOUT)

        self.args = {
            'host':    self.host,
            'port':    self.port,
            'version': self.version,
            'timeout': self.timeout,
        }
开发者ID:7040210,项目名称:dd-agent,代码行数:21,代码来源:ntp.py


示例11: get_auto_conf

def get_auto_conf(check_name):
    """Return the yaml auto_config dict for a check name (None if it doesn't exist)."""
    from config import PathNotFound, get_auto_confd_path

    try:
        auto_confd_path = get_auto_confd_path()
    except PathNotFound:
        log.error("Couldn't find the check auto-configuration folder, no auto configuration will be used.")
        return None

    auto_conf_path = os.path.join(auto_confd_path, '%s.yaml' % check_name)
    if not os.path.exists(auto_conf_path):
        log.error("Couldn't find any auto configuration file for the %s check." % check_name)
        return None

    try:
        auto_conf = check_yaml(auto_conf_path)
    except Exception as e:
        log.error("Unable to load the auto-config, yaml file."
                  "Auto-config will not work for this check.\n%s" % str(e))
        return None

    return auto_conf
开发者ID:alq666,项目名称:dd-agent,代码行数:23,代码来源:checkfiles.py


示例12: check_yaml

                        configs_and_sources[check_name] = (
                            service_disco_configs[check_name][0],
                            {'init_config': sd_init_config, 'instances': sd_instances})
                    else:
                        sd_init_config, sd_instances = service_disco_configs[check_name]
                    check_config = {'init_config': sd_init_config, 'instances': sd_instances}
                    skip_config_lookup = True

            else:
                conf_path = default_conf_path
                conf_exists = True

        if not skip_config_lookup:
            if conf_exists:
                try:
                    check_config = check_yaml(conf_path)
                    if agentConfig.get(TRACE_CONFIG):
                        configs_and_sources[check_name] = (CONFIG_FROM_FILE, check_config)
                except Exception, e:
                    log.exception("Unable to parse yaml config in %s" % conf_path)
                    traceback_message = traceback.format_exc()
                    init_failed_checks[check_name] = {'error': str(e), 'traceback': traceback_message}
                    continue
            else:
                # Compatibility code for the Nagios checks if it's still configured
                # in datadog.conf
                # FIXME: 6.x, should be removed
                if check_name == 'nagios':
                    if any([nagios_key in agentConfig for nagios_key in NAGIOS_OLD_CONF_KEYS]):
                        log.warning("Configuring Nagios in datadog.conf is deprecated "
                                    "and will be removed in a future version. "
开发者ID:abhilash07,项目名称:dd-agent,代码行数:31,代码来源:config.py


示例13: __init__

    def __init__(self, **kwargs):
        self.docker_util = DockerUtil()
        if 'init_config' in kwargs and 'instance' in kwargs:
            init_config = kwargs.get('init_config', {})
            instance = kwargs.get('instance', {})
        else:
            try:
                config_file_path = get_conf_path(KUBERNETES_CHECK_NAME)
                check_config = check_yaml(config_file_path)
                init_config = check_config['init_config'] or {}
                instance = check_config['instances'][0] or {}
            # kubernetes.yaml was not found
            except IOError as ex:
                log.error(ex.message)
                init_config, instance = {}, {}
            except Exception:
                log.error('Kubernetes configuration file is invalid. '
                          'Trying connecting to kubelet with default settings anyway...')
                init_config, instance = {}, {}

        self.method = instance.get('method', KubeUtil.DEFAULT_METHOD)
        self._node_ip = self._node_name = None  # lazy evaluation
        self.host_name = os.environ.get('HOSTNAME')
        self.pod_name = os.environ.get('KUBERNETES_POD_NAME') or self.host_name
        self.tls_settings = self._init_tls_settings(instance)

        # apiserver
        if 'api_server_url' in instance:
            self.kubernetes_api_root_url = instance.get('api_server_url')
        else:
            master_host = os.environ.get('KUBERNETES_SERVICE_HOST') or self.DEFAULT_MASTER_NAME
            master_port = os.environ.get('KUBERNETES_SERVICE_PORT') or self.DEFAULT_MASTER_PORT
            self.kubernetes_api_root_url = 'https://%s:%s' % (master_host, master_port)

        self.kubernetes_api_url = '%s/api/v1' % self.kubernetes_api_root_url

        # Service mapping helper class
        self._service_mapper = PodServiceMapper(self)
        from config import _is_affirmative
        self.collect_service_tag = _is_affirmative(instance.get('collect_service_tags', KubeUtil.DEFAULT_COLLECT_SERVICE_TAG))


        # leader status triggers event collection
        self.is_leader = False
        self.leader_elector = None
        self.leader_lease_duration = instance.get('leader_lease_duration')

        # kubelet
        # If kubelet_api_url is None, init_kubelet didn't succeed yet.
        self.init_success = False
        self.kubelet_api_url = None
        self.init_retry_interval = init_config.get('init_retry_interval', DEFAULT_RETRY_INTERVAL)
        self.last_init_retry = None
        self.left_init_retries = init_config.get('init_retries', DEFAULT_INIT_RETRIES) + 1
        self.init_kubelet(instance)

        self.kube_label_prefix = instance.get('label_to_tag_prefix', KubeUtil.DEFAULT_LABEL_PREFIX)
        self.kube_node_labels = instance.get('node_labels_to_host_tags', {})

        # keep track of the latest k8s event we collected and posted
        # default value is 0 but TTL for k8s events is one hour anyways
        self.last_event_collection_ts = 0
开发者ID:DataDog,项目名称:dd-agent,代码行数:62,代码来源:kubeutil.py


示例14: __init__

    def __init__(self, instance=None):
        self.docker_util = DockerUtil()
        if instance is None:
            try:
                config_file_path = get_conf_path(KUBERNETES_CHECK_NAME)
                check_config = check_yaml(config_file_path)
                instance = check_config['instances'][0]
            # kubernetes.yaml was not found
            except IOError as ex:
                log.error(ex.message)

                instance = {}
            except Exception:
                log.error('Kubernetes configuration file is invalid. '
                          'Trying connecting to kubelet with default settings anyway...')
                instance = {}

        self.method = instance.get('method', KubeUtil.DEFAULT_METHOD)
        self._node_ip = self._node_name = None  # lazy evaluation
        self.host_name = os.environ.get('HOSTNAME')
        self.tls_settings = self._init_tls_settings(instance)

        # apiserver
        if 'api_server_url' in instance:
            self.kubernetes_api_root_url = instance.get('api_server_url')
        else:
            master_host = os.environ.get('KUBERNETES_SERVICE_HOST') or self.DEFAULT_MASTER_NAME
            master_port = os.environ.get('KUBERNETES_SERVICE_PORT') or self.DEFAULT_MASTER_PORT
            self.kubernetes_api_root_url = 'https://%s:%s' % (master_host, master_port)

        self.kubernetes_api_url = '%s/api/v1' % self.kubernetes_api_root_url

        # kubelet
        try:
            self.kubelet_api_url = self._locate_kubelet(instance)
            if not self.kubelet_api_url:
                raise Exception("Couldn't find a method to connect to kubelet.")
        except Exception as ex:
            log.error("Kubernetes check exiting, cannot run without access to kubelet.")
            raise ex

        # Service mapping helper class
        self._service_mapper = PodServiceMapper(self)

        self.kubelet_host = self.kubelet_api_url.split(':')[1].lstrip('/')
        self.pods_list_url = urljoin(self.kubelet_api_url, KubeUtil.PODS_LIST_PATH)
        self.kube_health_url = urljoin(self.kubelet_api_url, KubeUtil.KUBELET_HEALTH_PATH)
        self.kube_label_prefix = instance.get('label_to_tag_prefix', KubeUtil.DEFAULT_LABEL_PREFIX)
        self.kube_node_labels = instance.get('node_labels_to_host_tags', {})

        # cadvisor
        self.cadvisor_port = instance.get('port', KubeUtil.DEFAULT_CADVISOR_PORT)
        self.cadvisor_url = '%s://%s:%d' % (self.method, self.kubelet_host, self.cadvisor_port)
        self.metrics_url = urljoin(self.cadvisor_url, KubeUtil.METRICS_PATH)
        self.machine_info_url = urljoin(self.cadvisor_url, KubeUtil.MACHINE_INFO_PATH)

        from config import _is_affirmative
        self.collect_service_tag = _is_affirmative(instance.get('collect_service_tags', KubeUtil.DEFAULT_COLLECT_SERVICE_TAG))

        # keep track of the latest k8s event we collected and posted
        # default value is 0 but TTL for k8s events is one hour anyways
        self.last_event_collection_ts = 0
开发者ID:alq666,项目名称:dd-agent,代码行数:62,代码来源:kubeutil.py



注:本文中的util.check_yaml函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.chunks函数代码示例发布时间:2022-05-27
下一篇:
Python util.check_won函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap