mirror of
https://dev.azure.com/effectory/Survey%20Software/_git/Cloud%20Engineering
synced 2026-02-28 03:02:19 +01:00
DanglingDNS -> Saving to blob
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
function Get-EffectoryDomainResources {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Find dangling DNS records
|
||||
Find resources in Azure that have DNS records
|
||||
.DESCRIPTION
|
||||
Compares DNS bindings with a previous state and checks the existence of DNS records for bindings that may have been deleted.
|
||||
Gets all resources that have hostnames.
|
||||
.PARAMETER subscriptionId
|
||||
Optional Subscription Id to set the context to. Otherwise uses the current context.
|
||||
#>
|
||||
@@ -29,29 +29,29 @@ function Get-EffectoryDomainResources {
|
||||
|
||||
Write-Host "Processing subscription $($currentContext.Name)"
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------------
|
||||
Write-Host "Checking WebApps and WebApp Slots for subscription $($currentContext.Name)"
|
||||
$webApps = Get-AzWebApp
|
||||
[int]$webAppCounter = 0
|
||||
[int]$webAppSlotCounter = 0
|
||||
# # ------------------------------------------------------------------------------------------------------------------
|
||||
# Write-Host "Checking WebApps and WebApp Slots for subscription $($currentContext.Name)"
|
||||
# $webApps = Get-AzWebApp
|
||||
# [int]$webAppCounter = 0
|
||||
# [int]$webAppSlotCounter = 0
|
||||
|
||||
if ($null -ne $webApps) {
|
||||
# check webapps
|
||||
$itemsWebApps = CheckWebApps -subscription $currentContext -webApps $webApps -effectoryDomainPattern $effectoryDomainPattern
|
||||
$webAppCounter += $itemsWebApps.Count
|
||||
$result += $itemsWebApps
|
||||
# if ($null -ne $webApps) {
|
||||
# # check webapps
|
||||
# $itemsWebApps = CheckWebApps -subscription $currentContext -webApps $webApps -effectoryDomainPattern $effectoryDomainPattern
|
||||
# $webAppCounter += $itemsWebApps.Count
|
||||
# $result += $itemsWebApps
|
||||
|
||||
# check webapp slots
|
||||
foreach ($webApp in $webApps) {
|
||||
$slot = Get-AzWebAppSlot -WebApp $webApp
|
||||
if ($null -ne $slot) {
|
||||
$itemsWebAppSlots = CheckWebApps -subscription $currentContext -webApps $slot -effectoryDomainPattern $effectoryDomainPattern
|
||||
$webAppSlotCounter += $itemsWebAppSlots.Count
|
||||
$result += $itemsWebAppSlots
|
||||
}
|
||||
}
|
||||
}
|
||||
Write-Host "Found $($webAppCounter) WebApps and $($webAppSlotsCounter) WebApp Slots for subscription $($currentContext.Name)"
|
||||
# # check webapp slots
|
||||
# foreach ($webApp in $webApps) {
|
||||
# $slot = Get-AzWebAppSlot -WebApp $webApp
|
||||
# if ($null -ne $slot) {
|
||||
# $itemsWebAppSlots = CheckWebApps -subscription $currentContext -webApps $slot -effectoryDomainPattern $effectoryDomainPattern
|
||||
# $webAppSlotCounter += $itemsWebAppSlots.Count
|
||||
# $result += $itemsWebAppSlots
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# Write-Host "Found $($webAppCounter) WebApps and $($webAppSlotsCounter) WebApp Slots for subscription $($currentContext.Name)"
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------------
|
||||
Write-Host "Checking FrontDoor Endpoints for subscription $($currentContext.Name)"
|
||||
@@ -77,57 +77,57 @@ function Get-EffectoryDomainResources {
|
||||
}
|
||||
Write-Host "Found $($storageCounter) Storage Accounts for subscription $($currentContext.Name)"
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------------
|
||||
Write-Host "Checking Cdn Endpoints for subscription $($currentContext.Name)"
|
||||
$cdnProfiles = Get-AzCdnProfile
|
||||
[int]$cdnCounter = 0
|
||||
# # ------------------------------------------------------------------------------------------------------------------
|
||||
# Write-Host "Checking Cdn Endpoints for subscription $($currentContext.Name)"
|
||||
# $cdnProfiles = Get-AzCdnProfile
|
||||
# [int]$cdnCounter = 0
|
||||
|
||||
if ($null -ne $cdnProfiles) {
|
||||
$itemsCdn = CheckCdnEndpoints -subscription $currentContext -cdnProfiles $cdnProfiles -effectoryDomainPattern $effectoryDomainPattern
|
||||
$cdnCounter += $itemsCdn.Count
|
||||
$result += $itemsCdn
|
||||
}
|
||||
Write-Host "Found $($cdnCounter) Cdn Endpoints for subscription $($currentContext.Name)"
|
||||
# if ($null -ne $cdnProfiles) {
|
||||
# $itemsCdn = CheckCdnEndpoints -subscription $currentContext -cdnProfiles $cdnProfiles -effectoryDomainPattern $effectoryDomainPattern
|
||||
# $cdnCounter += $itemsCdn.Count
|
||||
# $result += $itemsCdn
|
||||
# }
|
||||
# Write-Host "Found $($cdnCounter) Cdn Endpoints for subscription $($currentContext.Name)"
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------------
|
||||
Write-Host "Checking public IP addresses for subscription $($currentContext.Name)"
|
||||
$ipAddresses = Get-AzPublicIpAddress | Where-Object DnsSettings -ne $null | Where-Object { $_.DnsSettings.DomainNameLabel -ne "" }
|
||||
[int]$ipCounter = 0
|
||||
# # ------------------------------------------------------------------------------------------------------------------
|
||||
# Write-Host "Checking public IP addresses for subscription $($currentContext.Name)"
|
||||
# $ipAddresses = Get-AzPublicIpAddress | Where-Object DnsSettings -ne $null | Where-Object { $_.DnsSettings.DomainNameLabel -ne "" }
|
||||
# [int]$ipCounter = 0
|
||||
|
||||
if ($null -ne $ipAddresses) {
|
||||
$itemsIpAddresses = CheckIpAddresses -subscription $currentContext -ipAddresses $ipAddresses -effectoryDomainPattern $effectoryDomainPattern
|
||||
$ipCounter += $itemsIpAddresses.Count
|
||||
$result += $itemsIpAddresses
|
||||
}
|
||||
Write-Host "Found $($ipCounter) public IP addresses for subscription $($currentContext.Name)"
|
||||
# if ($null -ne $ipAddresses) {
|
||||
# $itemsIpAddresses = CheckIpAddresses -subscription $currentContext -ipAddresses $ipAddresses -effectoryDomainPattern $effectoryDomainPattern
|
||||
# $ipCounter += $itemsIpAddresses.Count
|
||||
# $result += $itemsIpAddresses
|
||||
# }
|
||||
# Write-Host "Found $($ipCounter) public IP addresses for subscription $($currentContext.Name)"
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------------
|
||||
Write-Host "Checking Traffic Managers for subscription $($currentContext.Name)"
|
||||
$trafficManagers = Get-AzTrafficManagerProfile
|
||||
[int]$trafficManagerCounter = 0
|
||||
# # ------------------------------------------------------------------------------------------------------------------
|
||||
# Write-Host "Checking Traffic Managers for subscription $($currentContext.Name)"
|
||||
# $trafficManagers = Get-AzTrafficManagerProfile
|
||||
# [int]$trafficManagerCounter = 0
|
||||
|
||||
if ($null -ne $trafficManagers) {
|
||||
$itemsTrafficManagers = CheckTrafficManagers -subscription $currentContext -trafficManagers $trafficManagers -effectoryDomainPattern $effectoryDomainPattern
|
||||
$trafficManagerCounter += $itemsTrafficManagers.Count
|
||||
$result += $itemsTrafficManagers
|
||||
}
|
||||
Write-Host "Found $($trafficManagerCounter) Traffic Managers for subscription $($currentContext.Name)"
|
||||
# if ($null -ne $trafficManagers) {
|
||||
# $itemsTrafficManagers = CheckTrafficManagers -subscription $currentContext -trafficManagers $trafficManagers -effectoryDomainPattern $effectoryDomainPattern
|
||||
# $trafficManagerCounter += $itemsTrafficManagers.Count
|
||||
# $result += $itemsTrafficManagers
|
||||
# }
|
||||
# Write-Host "Found $($trafficManagerCounter) Traffic Managers for subscription $($currentContext.Name)"
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------------
|
||||
Write-Host "Checking Container groups for subscription $($currentContext.Name)"
|
||||
$containerInstances = Get-AzContainerGroup
|
||||
# # ------------------------------------------------------------------------------------------------------------------
|
||||
# Write-Host "Checking Container groups for subscription $($currentContext.Name)"
|
||||
# $containerInstances = Get-AzContainerGroup
|
||||
|
||||
if ($null -ne $containerInstances) {
|
||||
throw "Container groups are not implemented yet."
|
||||
}
|
||||
# if ($null -ne $containerInstances) {
|
||||
# throw "Container groups are not implemented yet."
|
||||
# }
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------------
|
||||
Write-Host "Checking API Management for subscription $($currentContext.Name)"
|
||||
$apiManagementServices = Get-AzApiManagement
|
||||
# # ------------------------------------------------------------------------------------------------------------------
|
||||
# Write-Host "Checking API Management for subscription $($currentContext.Name)"
|
||||
# $apiManagementServices = Get-AzApiManagement
|
||||
|
||||
if ($null -ne $apiManagementServices) {
|
||||
throw "API Management services are not implemented yet."
|
||||
}
|
||||
# if ($null -ne $apiManagementServices) {
|
||||
# throw "API Management services are not implemented yet."
|
||||
# }
|
||||
|
||||
# ------------------------------------------------------------------------------------------------------------------
|
||||
$result
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
function PerformDanglingDnsRecordsCheck() {
|
||||
|
||||
[EffectoryDomainNameCheck[]]$current = @()
|
||||
[EffectoryDomainNameCheck[]]$previous = @()
|
||||
|
||||
# ----------------------------------------------------------------------------------------
|
||||
Write-Host "RETRIEVING PREVIOUS DOMAIN RECSOURCES"
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------
|
||||
Write-Host "RETRIEVING CURRENT DOMAIN RECSOURCES"
|
||||
$subscriptions = Get-AzSubscription | Where-Object State -eq "Enabled"
|
||||
|
||||
foreach ($subscription in $subscriptions)
|
||||
{
|
||||
$items = Get-EffectoryDomainResources -subscriptionId $subscription.Id
|
||||
$current = $current + $items
|
||||
}
|
||||
|
||||
$current
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
function Set-BlobEffectoryDomainResources {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Stores the effectory domain resources list as csv in Azure storage.
|
||||
.DESCRIPTION
|
||||
Stores the effectory domain resources list as csv in Azure storage, while making a backup of the previous state.
|
||||
.PARAMETER effectoryResources
|
||||
Resources to be exported to CSV.
|
||||
.PARAMETER connectionString
|
||||
Connection string of the storage account to save to.
|
||||
#>
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[EffectoryDomainNameCheck[]] $effectoryResources,
|
||||
[Parameter(Mandatory)]
|
||||
[string] $connectionString
|
||||
)
|
||||
|
||||
[string] $fileName = "$((Get-Date).ToString("yyyy-MM-dd hh-mm")) - resources.csv"
|
||||
$context = New-AzStorageContext -ConnectionString $connectionString
|
||||
|
||||
# move to history
|
||||
$blobs = Get-AzStorageBlob -Container "dangling-dns" -Context $context
|
||||
if ($null -ne $blobs) {
|
||||
foreach ($blob in $blobs) {
|
||||
Start-AzStorageBlobCopy -CloudBlob $blob.ICloudBlob -DestContainer "dangling-dns-history" -DestBlob $blob.Name -Context $context
|
||||
Remove-AzStorageBlob -Container "dangling-dns" -Blob $blob.Name -Context $context
|
||||
}
|
||||
}
|
||||
|
||||
# store as current
|
||||
$effectoryResources | Export-Csv "$Env:temp/$($fileName)"
|
||||
Set-AzStorageBlobContent -Context $context -Container "dangling-dns" -File "$Env:temp/$($fileName)" -Blob $fileName -Force
|
||||
}
|
||||
|
||||
# function Get-BlobEffectoryDomainResources {
|
||||
# <#
|
||||
# .SYNOPSIS
|
||||
# -
|
||||
# .DESCRIPTION
|
||||
# -
|
||||
# .PARAMETER subscriptionId
|
||||
# -
|
||||
# #>
|
||||
|
||||
# [EffectoryDomainNameCheck[]] $effectoryResources
|
||||
|
||||
|
||||
# }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# $context = New-AzStorageContext -ConnectionString "DefaultEndpointsProtocol=https;AccountName=runbookseffectory;AccountKey=PIyewEcppMcm8imMhpUUOgrOUbWyFPK0o8PfdwPnEiNvEQqUvTDzjuV4W18z2sBuRzspGs5pV/Fz96umfePviw==;EndpointSuffix=core.windows.net"
|
||||
# Get-AzTrafficManagerProfile | Export-Csv "$Env:temp/test4.csv"
|
||||
# Set-AzStorageBlobContent -Context $context -Container "dangling-dns" -File "$Env:temp/test4.csv" -Blob "test2.csv" -Force >$null
|
||||
|
||||
# Get-AzStorageBlobContent -Context $context -Container "dangling-dns" -Blob "test2.csv" -Destination "$Env:temp/test3.csv" -Force
|
||||
# $foo = Import-CSV "$Env:temp/test3.csv"
|
||||
|
||||
# $foo
|
||||
Reference in New Issue
Block a user