We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug When using the get_date_age jinja2 filter, I receive the error Can't subtract offset-naive and offset-aware datetimes
get_date_age
Can't subtract offset-naive and offset-aware datetimes
To Reproduce
The mailer should now show an exception
Expected behavior A clear and concise description of what you expected to happen.
No errors
Background (please complete the following information):
--version
vars: mode: &mode type: periodic schedule: "rate(7 days)" role: arn:aws:iam::{account_id}:role/cloud-custodian tags: application: cloud-custodian team: sre env: production policies: - name: ami-unused description: | Unused AMIs older than a year resource: ami max-resources: 100 mode: <<: *mode filters: - type: unused value: true - type: image-age days: 365 actions: # - deregister - type: notify slack_template: ami-unused-slack to: - https://hooks.slack.com/ transport: type: sqs queue: https://sqs.us-west-2.amazonaws.com/{account_id}/cloud-custodian
{ "attachments": [ { "fallback": "Cloud Custodian Policy Violation", "title": "{{ policy['name'] }}", "color": "warning", "fields": [ { "title": "Account", "value": "{{ account }}" }, { "title": "Region", "value": "{{ region }}" }, { "title": "Description", "value": "{{ policy['description'].strip() }}" }, { "title": "Found", "value": "{{ resources | length }}" }, { "title": "Subset", "value": "{%- for resource in (resources|sort(attribute='CreationDate'))[:5] -%} {{ resource['ImageId'] }}, {% set age = (resource['CreationDate'] | date_time_format(format='%Y %b %d %H:%M %Z')) | get_date_age %}{{'%0.2f' % (age / 365)|float}} years, (tags: {%- for tag in resource['Tags'] -%} {{ tag['Key'] }}={{ tag['Value'] }}, {%- endfor -%})\n\n {%- endfor -%}" } ] } ], {% if recipient is string and not recipient.startswith('https://') %} "channel":"{{ recipient }}", {% endif -%} "username": "Custodian" }
File "/var/task/jinja2/_compat.py", line 28, in reraise raise value.with_traceback(tb) File "msg-templates/ami-unused-slack.j2", line 32, in top-level template code {{ resource['ImageId'] }}, {% set age = (resource['CreationDate'] | date_time_format(format='%Y %b %d %H:%M %Z')) | get_date_age %}{{'%0.2f' % (age / 365)|float}} years, (tags: File "/var/task/c7n_mailer/utils.py", line 144, in get_date_age return (datetime.now(tz=tzutc()) - parser.parse(date)).days
Additional context Add any other context about the problem here.
This works using replay.
c7n-mailer-replay \ --config mailer.yml \ -t templates \ -p messages/sqs-ami-unused.slack.json
Possible fix for python2 or python3: https://stackoverflow.com/questions/796008/cant-subtract-offset-naive-and-offset-aware-datetimes
https://github.com/cloud-custodian/cloud-custodian/blob/master/tools/c7n_mailer/c7n_mailer/utils.py#L147
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Describe the bug
When using the
get_date_age
jinja2 filter, I receive the errorCan't subtract offset-naive and offset-aware datetimes
To Reproduce
The mailer should now show an exception
Expected behavior
A clear and concise description of what you expected to happen.
No errors
Background (please complete the following information):
--version
switch...Additional context
Add any other context about the problem here.
This works using replay.
Possible fix for python2 or python3: https://stackoverflow.com/questions/796008/cant-subtract-offset-naive-and-offset-aware-datetimes
https://github.com/cloud-custodian/cloud-custodian/blob/master/tools/c7n_mailer/c7n_mailer/utils.py#L147
The text was updated successfully, but these errors were encountered: