diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f1d499b..08b4ac90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - sphinx 4.2.0 to 4.3.0 and tzlocal==2.1 - [#561](https://github.com/jertel/elastalert2/pull/561) - @nsano-rururu - jinja2 3.0.1 to 3.0.3 - [#562](https://github.com/jertel/elastalert2/pull/562) - @nsano-rururu - Fix `get_rule_file_hash` TypeError - [#566](https://github.com/jertel/elastalert2/pull/566) - @JeffAshton +- Ensure `schema.yaml` stream closed - [#567](https://github.com/jertel/elastalert2/pull/567) - @JeffAshton # 2.2.3 diff --git a/elastalert/loaders.py b/elastalert/loaders.py index f7782c39..21b76800 100644 --- a/elastalert/loaders.py +++ b/elastalert/loaders.py @@ -62,6 +62,14 @@ from elastalert.yaml import read_yaml +# load rules schema +def load_rule_schema(): + schema_path = os.path.join(os.path.dirname(__file__), 'schema.yaml') + with open(schema_path) as schema_file: + schema_yml = yaml.load(schema_file, Loader=yaml.FullLoader) + return jsonschema.Draft7Validator(schema_yml) + + class RulesLoader(object): # import rule dependency import_rules = {} @@ -137,10 +145,7 @@ class RulesLoader(object): jinja_environment = Environment(loader=FileSystemLoader("")) def __init__(self, conf): - # schema for rule yaml - self.rule_schema = jsonschema.Draft7Validator( - yaml.load(open(os.path.join(os.path.dirname(__file__), 'schema.yaml')), Loader=yaml.FullLoader)) - + self.rule_schema = load_rule_schema() self.base_config = copy.deepcopy(conf) def load(self, conf, args=None):