Skip to content

Commit af2329a

Browse files
mx record change detection
1 parent 71c8b58 commit af2329a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function Get-CIPPAlertMXRecordChanged {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
#>
6+
[CmdletBinding()]
7+
param (
8+
[Parameter(Mandatory)]
9+
$TenantFilter,
10+
[Alias('input')]
11+
$InputValue
12+
)
13+
14+
try {
15+
$DomainData = Get-CIPPDomainAnalyser -TenantFilter $TenantFilter
16+
$CacheTable = Get-CippTable -tablename 'CacheMxRecords'
17+
$PreviousResults = Get-CIPPAzDataTableEntity @CacheTable -Filter "PartitionKey eq '$TenantFilter'"
18+
19+
$ChangedDomains = foreach ($Domain in $DomainData) {
20+
$PreviousDomain = $PreviousResults | Where-Object { $_.Domain -eq $Domain.Domain }
21+
if ($PreviousDomain -and $PreviousDomain.ActualMXRecords -ne $Domain.ActualMXRecords) {
22+
"$($Domain.Domain): MX records changed from [$($PreviousDomain.ActualMXRecords -join ', ')] to [$($Domain.ActualMXRecords -join ', ')]"
23+
}
24+
}
25+
26+
if ($ChangedDomains) {
27+
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $ChangedDomains
28+
}
29+
30+
# Update cache with current data
31+
foreach ($Domain in $DomainData) {
32+
$CacheEntity = @{
33+
PartitionKey = $TenantFilter
34+
RowKey = $Domain.Domain
35+
Domain = $Domain.Domain
36+
ActualMXRecords = $Domain.ActualMXRecords
37+
LastRefresh = $Domain.LastRefresh
38+
MailProvider = $Domain.MailProvider
39+
}
40+
Add-CIPPAzDataTableEntity @CacheTable -Entity $CacheEntity -Force
41+
}
42+
} catch {
43+
Write-LogMessage -message "Failed to check MX record changes: $($_.Exception.Message)" -API 'MX Record Alert' -tenant $TenantFilter -sev Error
44+
}
45+
}

0 commit comments

Comments
 (0)