-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
elastalert-test-rule fails with alert_text_jinja #100
Comments
In test_rule.py it's performing a deepcopy on the loaded rule object. Inside of that object there's a Jinja "Template" instance, which is causing problems with the deepcopy function. If we avoid deepcopying this Template object the test completes correctly. For example, in test_rule.py, the following change prevents the crash: I wonder if Template objects aren't deepcopy compliant then perhaps they should be overriding the deepcopy function, but that is really outside the scope of this project. @drakaru, as the Jinja Template PR submitter in #70, do you have any thoughts on this? |
Apologies, I meant to bring this up in discussions as I ran into the same issue and wasn't sure what the best solution was. I had a look when I first ran into this error, Jinja templates, as you mention, are not deepcopyable: pallets/jinja#758 (comment) We need a way of avoiding copying the templates. Before I made any changes only string templates were supported, directly from the rule yaml. Jinja caches templates loaded from the filesystem, this required creating a jinja environment (see loaders.py:100) However the rendering takes place within the alerter "create_alert_body", which only has access to the rule and the match and not to the global(?) config
|
Thanks for the additional context. I'll PR my simple solution for now. We can always improve it if a better alternative comes along. |
Elastalert2 2.0.4
Python 3.9
I'm testing alert_text using jinja templates and it fails using the elastalert-test-rule:
But it doesn't crash when using
elastalert --config config.yaml --rule toto.yaml --verbose
.I might not use it correctly, as I did not find the way refer to the rule parameter using jinja, as it doesn't put values in some of my field, but this might be another issue, as I do not see self.rule passed to the jinja renderer.
Part of the rule:
Output from
elastalert --config config.yaml --rule toto.yaml --verbose
:The text was updated successfully, but these errors were encountered: