ps/Modules/Alkami.DevOps.Operations/Private/Get-ELBHealthcheckEndpoints.ps1

68 lines
2.1 KiB
PowerShell
Raw Permalink Normal View History

2023-05-30 22:51:22 -07:00
function Get-ELBHealthcheckEndpoints {
<#
.SYNOPSIS
Gets the ELB healthcheck URLs for the server from which it's run.
.DESCRIPTION
Gets the ELB healthcheck URLs for the server from which it's run. First obtains the name from Get-CurrentInstanceTags,
uses the tag to obtain the ARN, then uses the ARN to obtain the endpoint.
.EXAMPLE
Get-ELBHealthcheckEndpoints
https://localhost:8443/IdentityGuardAuthService/services/AuthenticationServiceV11
https://localhost:8444/IdentityGuardAdminService/services/AdminServiceV11
#>
[CmdletBinding()]
param()
$logLead = (Get-LogLeadName)
Import-AWSModule # ELB2
if (!(Test-IsAws)) {
Write-Warning "$logLead : This function can only be executed on an AWS server"
return
}
# Get the name of the current machine and clean it to match ELB naming convention
$name = (Get-CurrentInstanceTags | Where-Object { $_.Key -eq 'Name' } | Select-Object -First 1).Value
$name = $name -replace '\.','-'
$name = $name -replace '_','-'
$name += '-alb'
Write-Host "$logLead : Name computed as $name"
# Get the ARN using the name generated above and verify there is only 1
$endpointARN = Get-ELB2LoadBalancer -Name $name
if (Test-IsCollectionNullOrEmpty -collection $endpointARN) {
Write-Error "Result returned a NULL or empty value for ARN"
return $null
} elseif($endpointARN.Count -gt 1) {
Write-Error "Result returned more than 1 ARN"
return $null
}
# Get the Endpoint data using the ARN
$elbEndpoints = Get-ELB2TargetGroup -loadbalancerarn $endpointARN.loadbalancerarn
if (Test-IsCollectionNullOrEmpty -collection $elbEndpoints) {
Write-Error "Result returned NULL or empty value for endpoints"
return $null
}
# Put together the URLs with the Endpoint data
$results = @()
foreach ($endpoint in $elbEndpoints) {
$url = '{0}://localhost:{1}{2}' -f $endpoint.Protocol.ToString().ToLower(), $endpoint.Port, $endpoint.healthcheckpath
$results += $url
}
return $results
}