-
Notifications
You must be signed in to change notification settings - Fork 1.5k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
custom msg-templates for c7n_mailer #1127
Comments
two sides of this, customizing templates at the delivery / rendering side in the mailer, and specifying the notification template. right now we just upload the msg-templates folder from the current working directory that the mailer deploy command is invoked from. you can drop custom templates in that folder. wrt to sending side and picking a named template, the notify action can has a template name field/attibute that can be specified. |
I tried to specify the template name in the configuration, i.e. mydefault.html, but was unable to see my changes reflected unless I overwrote the default.html template. It appears the render function looks for a default template, unless i'm missing something. |
@kennyg I believe that code snippet tries to get the template value from the policy, and if it doesn't exist.. it uses the 'default' file. data['action'].get('template', 'default')
^ note that it looks for 'template'. Would you dump the commands you're using the deploy the lambda function? your policy with the action? and the name of your template? |
I was able to get this working. The catch is that sqs_message_processor uses the Jinja FileSystemLoader, so it's looking for templates in I'm using cloud-custodian from git pinned to a specific hash, so to install the mailer, this is what worked for me: virtualenv --no-site-packages -p python2.7 .
. ./bin/activate
pip install -e 'git+https://github.com/capitalone/cloud-custodian.git@34d74e0dce6a2eb8599311947a4b2fea3036d#egg=c7n_mailer&subdirectory=tools/c7n_mailer'
pip install -r src/c7n-mailer/tools/c7n_mailer/requirements.txt
# my custom templates are in ./templates/; copy them into the source tree
cp templates/* src/c7n-mailer/tools/c7n_mailer/msg-templates/
PYTHONPATH=$PYTHONPATH:.:. ; . ./bin/activate && c7n-mailer -c /app/mailer.yml |
yea, the pathing is hard coded in that weird way. a PR to fix that sounds reasonable! |
I installed the mailer following the directions provided in the mailer README.md and had a similar question regarding using customized msg-templates. At the moment, I've been tinkering with modifying the default.html.j2 and default.j2 templates (eg: adding a simple "hello" text line) but not seeing my change in the email rendered. I have a feeling I'm not editing the right file because when I remove the default.html.j2 and default.j2 files entirely (expecting some failure error due to absence of template file, the mailer runs to completion and sends an email back with output but without my additional text. The directory I've been making changes to the msg-template files is: (custodian) [ec2-user@ip-x-x-x-x msg-templates]$ pwd I've tried modifying the default.html.j2 and default.j2 respectively and tried the following lines to my policy: HTML-basedactions: - type: notify template: default.html template_format: 'html' priority_header: '5' subject: 'test notification' to: - event-owner owner_absent_contact: - transport: type: sqs queue: Text-basedactions: - type: notify template: default template_format: 'text' priority_header: '5' subject: 'test notification' ... (same as HTML-based) jantman mentions something about the templates being in the "source tree" but I have no idea where or how to find that in my present virtualenv. :( |
@davidclin The Makefile that I used is available in a blog post here. The gist of it is:
DISCLAIMER: We're currently using 0.8.26.0, so I'm not sure what refactoring may have happened since then. The shorter path to arrive at the above is: install c7n in your virtualenv, and then search the virtualenv for |
@jantman Thank you!!! I took the path of least resistance and installed c7n in my custodian virtualenv -- and I'm able to modify the default.html.j2 file now! Haven't had a chance to try out custom templates yet, but will try later next week. |
Was able to get custom templates working using the option mentioned above of installing c7n in the custodian virtualenv. Everything is working great and I'm able to create customized templates for my policies. The trick was finding the path where the default.html.j2 file lived. Easily solved issueing: find ~/ -type f -name "default.html.j2" |
I am using Azure Storage queue for sending emails, after installing the c7n-mailer this the location of my templates. "/cloud-custodian\tools\c7n_mailer\c7n_mailer\msg-templates" below is my action sample from policy. Thanks in Advance! |
Hello, |
you can use above comment while deploying the mailer |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
can you add support for customized msg-templates for c7n_mailer? it appears the tool is hard-coded to look for a default template regardless of what's specified in the .yml config.
The text was updated successfully, but these errors were encountered: