Skip to content
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

Absolute Jinja2 template path doesn't work #1360

Open
gethvi opened this issue Jan 23, 2024 · 2 comments
Open

Absolute Jinja2 template path doesn't work #1360

gethvi opened this issue Jan 23, 2024 · 2 comments
Labels

Comments

@gethvi
Copy link

gethvi commented Jan 23, 2024

Hi,

using elastalert2==2.15.0 we encountered an error with jinja2 absolute template path not working:

jinja_template_path: /opt/elastalert/config/jinja_template.txt

It raises the following exception:

jinja2.exceptions.TemplateNotFound: /opt/elastalert/config/jinja_template.txt

Elastalert is installed like this:

python3 -m venv /opt/elastalert/venv
source /opt/elastalert/venv/bin/activate
pip install elastalert2

And used with custom systemd unit file:

[Unit]
Description=ElastAlert2
After=elasticsearch.service

[Service]
User=gitlab-runner
Group=gitlab-runner
WorkingDirectory=/opt/elastalert/
ExecStart=/opt/elastalert/venv/bin/elastalert --config /opt/elastalert/config/config.yml --verbose
Restart=on-failure

[Install]
WantedBy=multi-user.target

After some digging through the source code of elastalert2 and experimentation, it works with the following rule settings:

jinja_template_path: config/jinja_template.txt

Using the relative path (considering the working directory set by the systemd unit file) it works. However for a regular user it is not very intuitive to set the jinja_template_path to a relative path and the documentation doesn't mention it.

@jertel
Copy link
Owner

jertel commented Jan 24, 2024

Yes, it requires relative paths. I've updated the documentation to reflect this. We cannot change it to use absolute paths since it will break existing users configurations. However, if you're interested in adding an additional field named jinja_template_base_path then that value could allow users to change the behavior:

  • jinja_template_base_path: "" => Templates will be provided via relative paths under the current working directory (existing default behavior)
  • jinja_template_base_path: "/" => Templates will be provided via absolute paths
  • jinja_template_base_path: "/some/other/path" => Templates will be provided via relative paths under the given parent directory

The value would be supplied on line 149 of loaders.py.

Thanks for raising the issue.

Copy link

This issue is stale because it has been open for 6 months with no activity. Stale issues convey that the issue, while important to someone, is not critical enough for the author, or other community members to work on, sponsor, or otherwise shepherd the issue through to a resolution.

@github-actions github-actions bot added the Stale label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants