generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Buckingham
authored and
Buckingham
committed
Dec 13, 2024
1 parent
7a49f8c
commit a2f21f9
Showing
2 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
# Configuration | ||
CURRENT_DATE = datetime.now().strftime('%a %d %b %Y') | ||
SENDER = "[email protected]" | ||
RECIPIENTS = ['[email protected]'] | ||
RECIPIENTS = ["[email protected]", "[email protected]", "[email protected]", "[email protected]"] | ||
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 = """<table border="1" style="border-collapse: collapse; width: 100%;"> | ||
<tr style="background-color: #f2f2f2;"> | ||
<th style="padding: 8px; text-align: left;">Server</th> | ||
<th style="padding: 8px; text-align: left;">Date</th> | ||
<th style="padding: 8px; text-align: left;">Drive</th> | ||
<th style="padding: 8px; text-align: left;">Drive Label</th> | ||
<th style="padding: 8px; text-align: left;">File System</th> | ||
|
@@ -77,19 +78,28 @@ def format_disk_info(disk_info): | |
if current_hostname != info[0]: | ||
if current_hostname is not None: | ||
# formatted_info += f"""<tr><td colspan="9" style="border-bottom: 10px solid black;"></td></tr>""" | ||
formatted_info += f"""<tr><td colspan="9" style="height: 20px;"></td></tr>""" | ||
formatted_info += f"""<tr><td colspan="10" style="height: 20px;"></td></tr>""" | ||
current_hostname = info[0] | ||
|
||
status = info[9].strip().capitalize() | ||
status_color = { | ||
'Good': 'green', | ||
'Low': 'teal', | ||
'Warning': 'orange', | ||
'Critical': 'red' | ||
}.get(status, 'black') | ||
|
||
formatted_info += f"""<tr> | ||
<td style="padding: 8px; text-align: left;">{info[0]}</td> | ||
<td style="padding: 8px; text-align: left;">{info[1]}</td> | ||
<td style="padding: 8px; text-align: left;">{info[2]}</td> | ||
<td style="padding: 8px; text-align: left;">{info[3]}</td> | ||
<td style="padding: 8px; text-align: left;">{info[4]}</td> | ||
<td style="padding: 8px; text-align: left;">{info[5]}</td> | ||
<td style="padding: 8px; text-align: left;">{info[6]}</td> | ||
<td style="padding: 8px; text-align: left;">{info[7]}</td> | ||
<td style="padding: 8px; text-align: left;">{info[8]}%</td> | ||
<td style="padding: 8px; text-align: left;">{info[9]}</td> | ||
<td style="padding: 8px; text-align: left;">{info[8]}</td> | ||
<td style="padding: 8px; text-align: left; background-color: {status_color};">{info[9]}</td> | ||
</tr>""" | ||
formatted_info += "</table>" | ||
return formatted_info | ||
|
@@ -98,7 +108,7 @@ def send_email(subject, body_html): | |
msg = MIMEMultipart() | ||
msg['From'] = SENDER | ||
msg['To'] = ', '.join(RECIPIENTS) | ||
msg['Subject'] = subject | ||
msg['Subject'] = SUBJECT | ||
|
||
msg.attach(MIMEText(body_html, 'html')) | ||
|
||
|
@@ -116,9 +126,12 @@ def lambda_handler(event, context): | |
|
||
# Format disk information | ||
formatted_info = format_disk_info(disk_info) | ||
|
||
|
||
# Get current date | ||
CURRENT_DATE = datetime.now().strftime('%a %d %b %Y') | ||
|
||
# Email formatted disk information | ||
subject = 'AWS PPUD Disk Information Report' | ||
subject = 'AWS PPUD Disk Information Report - {CURRENT_DATE}' | ||
body_html = f"""<html> | ||
<head></head> | ||
<body> | ||
|