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

Python loader.yaml_loader函数代码示例

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

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



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

示例1: load_rules

def load_rules(args):
    """ Creates a conf dictionary for ElastAlerter. Loads the global
    config file and then each rule found in rules_folder.

    :param args: The parsed arguments to ElastAlert
    :return: The global configuration, a dictionary.
    """
    names = []
    filename = args.config
    conf = yaml_loader(filename)
    use_rule = args.rule

    for env_var, conf_var in env_settings.items():
        val = env(env_var, None)
        if val is not None:
            conf[conf_var] = val

    # Make sure we have all required globals
    if required_globals - frozenset(conf.keys()):
        raise EAException('%s must contain %s' % (filename, ', '.join(required_globals - frozenset(conf.keys()))))

    conf.setdefault('max_query_size', 10000)
    conf.setdefault('scroll_keepalive', '30s')
    conf.setdefault('disable_rules_on_error', True)
    conf.setdefault('scan_subdirectories', True)

    # Convert run_every, buffer_time into a timedelta object
    try:
        conf['run_every'] = datetime.timedelta(**conf['run_every'])
        conf['buffer_time'] = datetime.timedelta(**conf['buffer_time'])
        if 'alert_time_limit' in conf:
            conf['alert_time_limit'] = datetime.timedelta(**conf['alert_time_limit'])
        else:
            conf['alert_time_limit'] = datetime.timedelta(days=2)
        if 'old_query_limit' in conf:
            conf['old_query_limit'] = datetime.timedelta(**conf['old_query_limit'])
        else:
            conf['old_query_limit'] = datetime.timedelta(weeks=1)
    except (KeyError, TypeError) as e:
        raise EAException('Invalid time format used: %s' % (e))

    global base_config
    base_config = copy.deepcopy(conf)

    # Load each rule configuration file
    rules = []
    rule_files = get_file_paths(conf, use_rule)
    for rule_file in rule_files:
        try:
            rule = load_configuration(rule_file, conf, args)
            if rule['name'] in names:
                raise EAException('Duplicate rule named %s' % (rule['name']))
        except EAException as e:
            raise EAException('Error loading file %s: %s' % (rule_file, e))

        rules.append(rule)
        names.append(rule['name'])

    conf['rules'] = rules
    return conf
开发者ID:CCoffie,项目名称:elastalert,代码行数:60,代码来源:config.py


示例2: load_configuration

def load_configuration(filename, conf, args=None):
    """ Load a yaml rule file and fill in the relevant fields with objects.

    :param filename: The name of a rule configuration file.
    :param conf: The global configuration dictionary, used for populating defaults.
    :return: The rule configuration, a dictionary.
    """

    rule = {
        'rule_file': filename
    }

    while True:
        try:
            loaded = yaml_loader(filename)
        except yaml.scanner.ScannerError as e:
            raise EAException('Could not parse file %s: %s' % (filename, e))

        # Special case for merging filters - if both files specify a filter merge (AND) them
        if 'filter' in rule and 'filter' in loaded:
            rule['filter'] = loaded['filter'] + rule['filter']

        loaded.update(rule)
        rule = loaded
        if 'import' in rule:
            # Find the path of the next file.
            filename = os.path.join(os.path.dirname(filename), rule['import'])
            del(rule['import'])  # or we could go on forever!
        else:
            break

    load_options(rule, conf, args)
    load_modules(rule, args)
    return rule
开发者ID:kureus,项目名称:elastalert,代码行数:34,代码来源:config.py


示例3: load_rule_yaml

def load_rule_yaml(filename):
    rule = {
        'rule_file': filename,
    }

    while True:
        try:
            loaded = yaml_loader(filename)
        except yaml.scanner.ScannerError as e:
            raise EAException('Could not parse file %s: %s' % (filename, e))

        # Special case for merging filters - if both files specify a filter merge (AND) them
        if 'filter' in rule and 'filter' in loaded:
            rule['filter'] = loaded['filter'] + rule['filter']

        loaded.update(rule)
        rule = loaded
        if 'import' in rule:
            # Find the path of the next file.
            filename = os.path.join(os.path.dirname(filename), rule['import'])
            del(rule['import'])  # or we could go on forever!
        else:
            break

    return rule
开发者ID:bebo,项目名称:elastalert,代码行数:25,代码来源:config.py


示例4: load_rule_yaml

def load_rule_yaml(filename):
    rule = {
        'rule_file': filename,
    }

    import_rules.pop(filename, None)  # clear `filename` dependency
    while True:
        try:
            loaded = yaml_loader(filename)
        except yaml.scanner.ScannerError as e:
            raise EAException('Could not parse file %s: %s' % (filename, e))

        # Special case for merging filters - if both files specify a filter merge (AND) them
        if 'filter' in rule and 'filter' in loaded:
            rule['filter'] = loaded['filter'] + rule['filter']

        loaded.update(rule)
        rule = loaded
        if 'import' in rule:
            # Find the path of the next file.
            if os.path.isabs(rule['import']):
                import_filename = rule['import']
            else:
                import_filename = os.path.join(os.path.dirname(filename), rule['import'])
            # set dependencies
            rules = import_rules.get(filename, [])
            rules.append(import_filename)
            import_rules[filename] = rules
            filename = import_filename
            del(rule['import'])  # or we could go on forever!
        else:
            break

    return rule
开发者ID:Yelp,项目名称:elastalert,代码行数:34,代码来源:config.py


示例5: load_rules

def load_rules(filename, use_rule=None):
    """ Creates a conf dictionary for ElastAlerter. Loads the global
    config file and then each rule found in rules_folder.

    :param filename: Name of the global configuration file.
    :param use_rule: Only load the rule which has this filename.
    :return: The global configuration, a dictionary.
    """
    names = []
    conf = yaml_loader(filename)

    # Make sure we have all required globals
    if required_globals - frozenset(conf.keys()):
        raise EAException('%s must contain %s' % (filename, ', '.join(required_globals - frozenset(conf.keys()))))

    conf.setdefault('max_query_size', 100000)

    # Convert run_every, buffer_time into a timedelta object
    try:
        conf['run_every'] = datetime.timedelta(**conf['run_every'])
        conf['buffer_time'] = datetime.timedelta(**conf['buffer_time'])
        if 'alert_time_limit' in conf:
            conf['alert_time_limit'] = datetime.timedelta(**conf['alert_time_limit'])
        else:
            conf['alert_time_limit'] = datetime.timedelta(days=2)
        if 'old_query_limit' in conf:
            conf['old_query_limit'] = datetime.timedelta(**conf['old_query_limit'])
        else:
            conf['old_query_limit'] = datetime.timedelta(weeks=1)
    except (KeyError, TypeError) as e:
        raise EAException('Invalid time format used: %s' % (e))

    # Load each rule configuration file
    rule_folder = conf['rules_folder']
    rule_files = os.listdir(rule_folder)
    rules = []
    for rule_file in rule_files:
        if use_rule and rule_file != use_rule:
            continue
        if '.yaml' == rule_file[-5:]:
            try:
                rule = load_configuration(os.path.join(rule_folder, rule_file))
                if rule['name'] in names:
                    raise EAException('Duplicate rule named %s' % (rule['name']))
            except EAException as e:
                raise EAException('Error loading file %s: %s' % (rule_file, e))

            rules.append(rule)
            names.append(rule['name'])

    if not rules:
        logging.exception('No rules loaded. Exiting')
        exit(1)

    conf['rules'] = rules
    return conf
开发者ID:garyelephant,项目名称:elastalert,代码行数:56,代码来源:config.py


示例6: load_rules

def load_rules(args):
    """ Creates a conf dictionary for ElastAlerter. Loads the global
    config file and then each rule found in rules_folder.

    :param args: The parsed arguments to ElastAlert
    :return: The global configuration, a dictionary.
    """
    names = []
    filename = args.config
    conf = yaml_loader(filename)
    use_rule = args.rule

    # Make sure we have all required globals
    if required_globals - frozenset(conf.keys()):
        raise EAException("%s must contain %s" % (filename, ", ".join(required_globals - frozenset(conf.keys()))))

    conf.setdefault("max_query_size", 10000)
    conf.setdefault("scroll_keepalive", "30s")
    conf.setdefault("disable_rules_on_error", True)
    conf.setdefault("scan_subdirectories", True)

    # Convert run_every, buffer_time into a timedelta object
    try:
        conf["run_every"] = datetime.timedelta(**conf["run_every"])
        conf["buffer_time"] = datetime.timedelta(**conf["buffer_time"])
        if "alert_time_limit" in conf:
            conf["alert_time_limit"] = datetime.timedelta(**conf["alert_time_limit"])
        else:
            conf["alert_time_limit"] = datetime.timedelta(days=2)
        if "old_query_limit" in conf:
            conf["old_query_limit"] = datetime.timedelta(**conf["old_query_limit"])
        else:
            conf["old_query_limit"] = datetime.timedelta(weeks=1)
    except (KeyError, TypeError) as e:
        raise EAException("Invalid time format used: %s" % (e))

    # Load each rule configuration file
    rules = []
    rule_files = get_file_paths(conf, use_rule)
    for rule_file in rule_files:
        try:
            rule = load_configuration(rule_file, conf, args)
            if rule["name"] in names:
                raise EAException("Duplicate rule named %s" % (rule["name"]))
        except EAException as e:
            raise EAException("Error loading file %s: %s" % (rule_file, e))

        rules.append(rule)
        names.append(rule["name"])

    if not rules:
        logging.exception("No rules loaded. Exiting")
        exit(1)

    conf["rules"] = rules
    return conf
开发者ID:theofilis,项目名称:elastalert,代码行数:56,代码来源:config.py


示例7: get_account

    def get_account(self, account_file):
        """ Gets the username and password from an account file.

        :param account_file: Name of the file which contains user and password information.
        """
        account_conf = yaml_loader(account_file)
        if 'user' not in account_conf or 'password' not in account_conf:
            raise EAException('Account file must have user and password fields')
        self.user = account_conf['user']
        self.password = account_conf['password']
开发者ID:kenshin17,项目名称:elastalert,代码行数:10,代码来源:alerts.py


示例8: load_configuration

def load_configuration(filename):
    """ Load a yaml rule file and fill in the relevant fields with objects.

    :param filename: The name of a rule configuration file.
    :return: The rule configuration, a dictionary.
    """
    try:
        rule = yaml_loader(filename)
    except yaml.scanner.ScannerError as e:
        raise EAException('Could not parse file %s: %s' % (filename, e))

    rule['rule_file'] = os.path.split(filename)[-1]
    load_options(rule)
    load_modules(rule)
    return rule
开发者ID:garyelephant,项目名称:elastalert,代码行数:15,代码来源:config.py


示例9: load_configuration

def load_configuration(filename, conf, args=None):
    """ Load a yaml rule file and fill in the relevant fields with objects.

    :param filename: The name of a rule configuration file.
    :param conf: The global configuration dictionary, used for populating defaults.
    :return: The rule configuration, a dictionary.
    """
    try:
        rule = yaml_loader(filename)
    except yaml.scanner.ScannerError as e:
        raise EAException('Could not parse file %s: %s' % (filename, e))

    rule['rule_file'] = filename
    load_options(rule, conf, args)
    load_modules(rule, args)
    return rule
开发者ID:harshanarayana,项目名称:elastalert,代码行数:16,代码来源:config.py


示例10: load_rules

def load_rules(args):
    """ Creates a conf dictionary for ElastAlerter. Loads the global
    config file and then each rule found in rules_folder.

    :param args: The parsed arguments to ElastAlert
    :return: The global configuration, a dictionary.
    """
    names = []
    filename = args.config
    conf = yaml_loader(filename)
    use_rule = args.rule

    # Make sure we have all required globals
    if required_globals - frozenset(conf.keys()):
        raise EAException('%s must contain %s' % (filename, ', '.join(required_globals - frozenset(conf.keys()))))

    conf.setdefault('max_query_size', 10000)
    conf.setdefault('scroll_keepalive', '30s')
    conf.setdefault('disable_rules_on_error', True)
    conf.setdefault('scan_subdirectories', True)

    # Convert run_every, buffer_time into a timedelta object
    try:
        conf['run_every'] = datetime.timedelta(**conf['run_every'])
        conf['buffer_time'] = datetime.timedelta(**conf['buffer_time'])
        if 'alert_time_limit' in conf:
            conf['alert_time_limit'] = datetime.timedelta(**conf['alert_time_limit'])
        else:
            conf['alert_time_limit'] = datetime.timedelta(days=2)
        if 'old_query_limit' in conf:
            conf['old_query_limit'] = datetime.timedelta(**conf['old_query_limit'])
        else:
            conf['old_query_limit'] = datetime.timedelta(weeks=1)
    except (KeyError, TypeError) as e:
        raise EAException('Invalid time format used: %s' % (e))

    # Load each rule configuration file
    rules = []
    rule_files = get_file_paths(conf, use_rule)
    for rule_file in rule_files:
        try:
            rule = load_configuration(rule_file, conf, args)
            if rule['name'] in names:
                raise EAException('Duplicate rule named %s' % (rule['name']))
        except EAException as e:
            raise EAException('Error loading file %s: %s' % (rule_file, e))

        rules.append(rule)
        names.append(rule['name'])

    if not rules:
        logging.exception('No rules loaded. Exiting')
        exit(1)
    
    # Warn if use_strf_index is used with %y, %M or %D
    # (%y = short year, %M = minutes, %D = full date)
    
    # añado el indice donde quiero que me busque las cosas que escribió: 'writeback_index*'
    conf['readback_index']=conf['writeback_index'] + '*'

    if (conf.get('writeback_index') and conf.get('writeback_index_fmt')):
        try:
            conf['writeback_index']=conf.get('writeback_index') + '%s' % (now.strftime(conf.get('writeback_index_fmt')))    
        except SyntaxError:
            raise SyntaxError('error with the format of writeback_index_fmt in the config.yaml')

    conf['rules'] = rules
    return conf
开发者ID:Runecast,项目名称:elastalert,代码行数:68,代码来源:config.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python ErrorCodeManager.ErrorCodeManager类代码示例发布时间:2022-05-27
下一篇:
Python staticconf.get函数代码示例发布时间: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