diff --git a/terraform/environments/ppud/eventbridge.tf b/terraform/environments/ppud/eventbridge.tf index c20d4843d31..c49939d1d3d 100644 --- a/terraform/environments/ppud/eventbridge.tf +++ b/terraform/environments/ppud/eventbridge.tf @@ -102,6 +102,31 @@ resource "aws_cloudwatch_event_target" "trigger_lambda_target_ppud_email_report_ arn = aws_lambda_function.terraform_lambda_func_ppud_email_report_prod[0].arn } +# Eventbridge rule to invoke the PPUD Disk Information Report lambda function every Monday at 07:00 + +resource "aws_lambda_permission" "allow_eventbridge_invoke_ppud_disk_info_report_prod" { + count = local.is-production == true ? 1 : 0 + statement_id = "AllowEventBridgeInvoke" + action = "lambda:InvokeFunction" + function_name = aws_lambda_function.terraform_lambda_func_ppud_disk_info_report_prod[0].function_name + principal = "events.amazonaws.com" + source_arn = aws_cloudwatch_event_rule.weekly_schedule_ppud_disk_info_report_prod[0].arn +} + +resource "aws_cloudwatch_event_rule" "weekly_schedule_ppud_disk_info_report_prod" { + count = local.is-production == true ? 1 : 0 + name = "ppud-disk_info-report-weekly-schedule" + description = "Trigger Lambda at 07:10 UTC each Monday" + schedule_expression = "cron(0 7 ? * MON *)" +} + +resource "aws_cloudwatch_event_target" "trigger_lambda_target_ppud_disk_info_report_prod" { + count = local.is-production == true ? 1 : 0 + rule = aws_cloudwatch_event_rule.weekly_schedule_ppud_disk_info_report_prod[0].name + target_id = "disk_info_report" + arn = aws_lambda_function.terraform_lambda_func_ppud_disk_info_report_prod[0].arn +} + # Eventbridge Rule to Disable CPU Alarms each Friday at 23:00 resource "aws_cloudwatch_event_rule" "disable_cpu_alarm" { diff --git a/terraform/environments/ppud/lambda_scripts/disk_info_report_prod.py b/terraform/environments/ppud/lambda_scripts/disk_info_report_prod.py index 3ac99af7c9e..182827688b3 100644 --- a/terraform/environments/ppud/lambda_scripts/disk_info_report_prod.py +++ b/terraform/environments/ppud/lambda_scripts/disk_info_report_prod.py @@ -19,7 +19,7 @@ # Configuration CURRENT_DATE = datetime.now().strftime('%a %d %b %Y') SENDER = "donotreply@cjsm.secure-email.ppud.justice.gov.uk" -RECIPIENTS = ['nick.buckingham@colt.net'] +RECIPIENTS = ["nick.buckingham@colt.net", "gabriella.browning@colt.net", "pankaj.pant@colt.net", "david.savage@colt.net"] SUBJECT = f'AWS PPUD Disk Information Report - {CURRENT_DATE}' AWS_REGION = 'eu-west-2' bucket_name = 'moj-lambda-layers-prod' @@ -62,6 +62,7 @@ def format_disk_info(disk_info): formatted_info = """
Server | +Date | Drive | Drive Label | File System | @@ -77,19 +78,28 @@ def format_disk_info(disk_info): if current_hostname != info[0]: if current_hostname is not None: # formatted_info += f"""|||||||
---|---|---|---|---|---|---|---|---|---|---|---|
{info[0]} | +{info[1]} | {info[2]} | {info[3]} | {info[4]} | {info[5]} | {info[6]} | {info[7]} | -{info[8]}% | -{info[9]} | +{info[8]} | +{info[9]} |