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

Updating-Backup-validation-role #2344

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions roles/aws/aws_backup_validation/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@
dest: "{{ _ce_provision_build_dir }}/{{ item }}_validation.py"
loop: "{{ aws_backup_validation.resources }}"

- name: Get info about newly created restore testing plan.
ansible.builtin.command: >
aws backup list-restore-testing-plans --region {{ _aws_region }}
register: _testing_plans

- name: Print return information from the previous task
ansible.builtin.debug:
var: _testing_plans

- name: Write validation report functions
ansible.builtin.template:
src: "validation_report.j2"
Expand Down
32 changes: 21 additions & 11 deletions roles/aws/aws_backup_validation/templates/validation_report.j2
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,21 @@ def lambda_handler(event, context):
failed_validation = False
global mail_body
last_restore_valdation_date = (datetime.datetime.now() - datetime.timedelta(days=1)).strftime('%Y-%m-%d')
completed_jobs=[]
failed_jobs=[]

print("Getting list of successful restoration.")
completed_jobs = backup_cli.list_restore_jobs(
ByCreatedAfter=last_restore_valdation_date,
ByStatus='COMPLETED'
{% for plan in _testing_plans.stdout | from_json | json_query('RestoreTestingPlans') %}
completed_job = backup_cli.list_restore_jobs(
ByCreatedAfter=last_restore_valdation_date,
ByStatus='COMPLETED',
ByRestoreTestingPlanArn='{{ plan['RestoreTestingPlanArn'] }}'
)
completed_jobs+=completed_job['RestoreJobs']
{% endfor %}

print("Getting instance details.")
for inst in completed_jobs['RestoreJobs']:
for inst in completed_jobs:
success_restore = True
print("Getting instance arn.")
ami_arn = inst['RecoveryPointArn'].split(':')[2]
Expand Down Expand Up @@ -81,21 +87,25 @@ def lambda_handler(event, context):
set_mail_body(success_restore, inst, instance_name, ami_id)

print(mail_body)

failed_jobs = backup_cli.list_restore_jobs(
ByCreatedAfter=last_restore_valdation_date,
ByStatus='FAILED'
print("Getting list of failed restoration.")
{% for plan in _testing_plans.stdout | from_json | json_query('RestoreTestingPlans') %}
failed_job = backup_cli.list_restore_jobs(
ByCreatedAfter=last_restore_valdation_date,
ByStatus='FAILED',
ByRestoreTestingPlanArn='{{ plan['RestoreTestingPlanArn'] }}'
)
failed_jobs += failed_job['RestoreJobs']
{% endfor %}

if len(failed_jobs['RestoreJobs']) > 0:
if len(failed_jobs) > 0:
mail_title = "Failed!"
else:
mail_title = "Success!"
print("Successful restore jobs:")
print(completed_jobs['RestoreJobs'])
print(completed_jobs)

print("Failed restore jobs:")
print(failed_jobs['RestoreJobs'])
print(failed_jobs)

print("Sending email!")
response = ses_cli.send_email(
Expand Down
Loading