Skip to content

Commit 59e098d

Browse files
matej5Matej Stajduhar
andauthored
Updating-Backup-validation-role (#2344)
* Updating-Backup-validation-role * Updating-lambda-function * Updating-tasks --------- Co-authored-by: Matej Stajduhar <[email protected]>
1 parent 6a3e9e8 commit 59e098d

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

roles/aws/aws_backup_validation/tasks/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@
6666
dest: "{{ _ce_provision_build_dir }}/{{ item }}_validation.py"
6767
loop: "{{ aws_backup_validation.resources }}"
6868

69+
- name: Get info about newly created restore testing plan.
70+
ansible.builtin.command: >
71+
aws backup list-restore-testing-plans --region {{ _aws_region }}
72+
register: _testing_plans
73+
74+
- name: Print return information from the previous task
75+
ansible.builtin.debug:
76+
var: _testing_plans
77+
6978
- name: Write validation report functions
7079
ansible.builtin.template:
7180
src: "validation_report.j2"

roles/aws/aws_backup_validation/templates/validation_report.j2

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,21 @@ def lambda_handler(event, context):
4242
failed_validation = False
4343
global mail_body
4444
last_restore_valdation_date = (datetime.datetime.now() - datetime.timedelta(days=1)).strftime('%Y-%m-%d')
45+
completed_jobs=[]
46+
failed_jobs=[]
4547

4648
print("Getting list of successful restoration.")
47-
completed_jobs = backup_cli.list_restore_jobs(
48-
ByCreatedAfter=last_restore_valdation_date,
49-
ByStatus='COMPLETED'
49+
{% for plan in _testing_plans.stdout | from_json | json_query('RestoreTestingPlans') %}
50+
completed_job = backup_cli.list_restore_jobs(
51+
ByCreatedAfter=last_restore_valdation_date,
52+
ByStatus='COMPLETED',
53+
ByRestoreTestingPlanArn='{{ plan['RestoreTestingPlanArn'] }}'
5054
)
55+
completed_jobs+=completed_job['RestoreJobs']
56+
{% endfor %}
5157

5258
print("Getting instance details.")
53-
for inst in completed_jobs['RestoreJobs']:
59+
for inst in completed_jobs:
5460
success_restore = True
5561
print("Getting instance arn.")
5662
ami_arn = inst['RecoveryPointArn'].split(':')[2]
@@ -81,21 +87,25 @@ def lambda_handler(event, context):
8187
set_mail_body(success_restore, inst, instance_name, ami_id)
8288

8389
print(mail_body)
84-
85-
failed_jobs = backup_cli.list_restore_jobs(
86-
ByCreatedAfter=last_restore_valdation_date,
87-
ByStatus='FAILED'
90+
print("Getting list of failed restoration.")
91+
{% for plan in _testing_plans.stdout | from_json | json_query('RestoreTestingPlans') %}
92+
failed_job = backup_cli.list_restore_jobs(
93+
ByCreatedAfter=last_restore_valdation_date,
94+
ByStatus='FAILED',
95+
ByRestoreTestingPlanArn='{{ plan['RestoreTestingPlanArn'] }}'
8896
)
97+
failed_jobs += failed_job['RestoreJobs']
98+
{% endfor %}
8999

90-
if len(failed_jobs['RestoreJobs']) > 0:
100+
if len(failed_jobs) > 0:
91101
mail_title = "Failed!"
92102
else:
93103
mail_title = "Success!"
94104
print("Successful restore jobs:")
95-
print(completed_jobs['RestoreJobs'])
105+
print(completed_jobs)
96106

97107
print("Failed restore jobs:")
98-
print(failed_jobs['RestoreJobs'])
108+
print(failed_jobs)
99109

100110
print("Sending email!")
101111
response = ses_cli.send_email(

0 commit comments

Comments
 (0)