Beispiel #1
0
def get_auto_conf(agentConfig, 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("Enable to load the auto-config, yaml file."
                  "Auto-config will not work for this check.\n%s" % str(e))
        return None

    return auto_conf
Beispiel #2
0
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
Beispiel #3
0
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
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('ad_identifiers',
                                   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
Beispiel #5
0
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
Beispiel #6
0
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
Beispiel #7
0
    def _add_conf_tar(self):
        conf_path = get_config_path()
        if self._can_read(conf_path, output=False):
            self._add_clean_conf(conf_path, 'etc', self.MAIN_CREDENTIALS)

        if not Platform.is_windows():
            supervisor_path = os.path.join(os.path.dirname(get_config_path()),
                                           'supervisor.conf')
            if self._can_read(supervisor_path, output=False):
                self._add_clean_conf(supervisor_path, 'etc')

        for file_path in glob.glob(os.path.join(get_confd_path(), '*.yaml')) +\
                glob.glob(os.path.join(get_confd_path(), '*.yaml.default')):
            if self._can_read(file_path, output=False):
                self._add_clean_conf(file_path, os.path.join('etc', 'confd'),
                                     self.CHECK_CREDENTIALS)

        for file_path in glob.glob(
                os.path.join(get_auto_confd_path(), '*.yaml')):
            if self._can_read(file_path, output=False):
                self._add_clean_conf(file_path,
                                     os.path.join('etc', 'confd', 'auto_conf'),
                                     self.CHECK_CREDENTIALS)
Beispiel #8
0
    def _add_conf_tar(self):
        conf_path = get_config_path()
        if self._can_read(conf_path, output=False):
            self._add_clean_conf(
                conf_path,
                'etc',
                self.MAIN_CREDENTIALS
            )

        if not Platform.is_windows():
            supervisor_path = os.path.join(
                os.path.dirname(get_config_path()),
                'supervisor.conf'
            )
            if self._can_read(supervisor_path, output=False):
                self._add_clean_conf(
                    supervisor_path,
                    'etc'
                )

        for file_path in glob.glob(os.path.join(get_confd_path(), '*.yaml')) +\
                glob.glob(os.path.join(get_confd_path(), '*.yaml.default')):
            if self._can_read(file_path, output=False):
                self._add_clean_conf(
                    file_path,
                    os.path.join('etc', 'confd'),
                    self.CHECK_CREDENTIALS
                )

        for file_path in glob.glob(os.path.join(get_auto_confd_path(), '*.yaml')):
            if self._can_read(file_path, output=False):
                self._add_clean_conf(
                    file_path,
                    os.path.join('etc', 'confd', 'auto_conf'),
                    self.CHECK_CREDENTIALS
                )
Beispiel #9
0
def get_auto_conf_images(agentConfig):
    from config import PathNotFound, get_auto_confd_path
    auto_conf_images = {}

    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

    for yaml_file in os.listdir(auto_confd_path):
        check_name = yaml_file.split('.')[0]
        try:
            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 = {}
        images = auto_conf.get('docker_images', [])
        for image in images:
            auto_conf_images[image] = check_name
    return auto_conf_images