Skip to content

Commit

Permalink
Merge pull request #567 from JeffAshton/load_rule_schema
Browse files Browse the repository at this point in the history
Closing the rule schema.yml file stream
  • Loading branch information
jertel authored Nov 23, 2021
2 parents 2d9306d + 0a9c36d commit d783c93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 9 additions & 4 deletions elastalert/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit d783c93

Please sign in to comment.