Last active
November 5, 2019 05:37
-
-
Save mbourgon/fd5c1b8a9f25e1279e0c80a71ce35ce2 to your computer and use it in GitHub Desktop.
AWS RDS - email when there's an update to be applied via Get-RDSPendingMaintenanceAction
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
Remove-Variable -Name * -ErrorAction SilentlyContinue | |
import-module awspowershell | |
$myaccesskey = "youraccesskey" | |
$mysecretkey = "yoursecretkey" | |
$myregion = "yourregion" | |
$myemail = "youremailaddress" | |
$mysmtp = "smtp.yourcompany.com" | |
set-awscredentials -accesskey $myaccesskey -secretkey $mysecretkey | |
$now = get-date | |
$upgrade_info = Get-RDSPendingMaintenanceAction -Region $myregion | |
# Taking the results and parsing out the info for each instance | |
$Parsed_Results = $upgrade_info | select @{Label='ResourceIdentifier';Expression={$_.ResourceIdentifier} | |
}, @{Label='Action';Expression={$_.PendingMaintenanceActionDetails.Action} | |
}, @{Label='Description';Expression={$_.PendingMaintenanceActionDetails.Description} | |
}, @{Label='AutoAppliedAfterDate';Expression={$_.PendingMaintenanceActionDetails.AutoAppliedAfterDate} | |
}, @{Label='CurrentApplyDate';Expression={$_.PendingMaintenanceActionDetails.CurrentApplyDate} | |
}, @{Label='ForcedApplyDate';Expression={$_.PendingMaintenanceActionDetails.ForcedApplyDate} | |
}, @{Label='OptInStatus';Expression={$_.PendingMaintenanceActionDetails.OptInStatus} | |
} | |
# Making an HTML table | |
# https://jamesdatatechq.wordpress.com/2014/12/23/how-to-create-an-html-table-from-powershell/ | |
$Style = " | |
<style> | |
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;} | |
TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;} | |
TD{border-width: 1px;padding: 3px;border-style: solid;border-color: black;} | |
</style> | |
" | |
#Convert the parsed info to a table | |
$error_table = $Parsed_Results| ConvertTo-HTML -AS Table -Fragment -PreContent "<h2>Aurora Updates as of $now</h2>"|Out-String | |
#Save the HTML Web Page with the table style | |
[string]$email_table = (ConvertTo-HTML -head $Style -PostContent $error_table) | |
# Now send the mail | |
if ($upgrade_info){ | |
#Send email to $myemail. SMTP is a CNAME to the corporate SMTP server we use. | |
Send-MailMessage -smtpserver $mysmtp ` | |
-To $myemail ` | |
-From "My_AWS_Account_Do_Not_Reply <[email protected]>" ` | |
-Subject "[AWS] Aurora updates available - time to test and mark for upgrades if good. $now" ` | |
-body $email_table -BodyAsHtml | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment