Create Pull Request
| Date | Scan | Status | Result |
|---|---|---|---|
| 2025-07-12 23:44 | #41 | cancelled |
Biased
|
| 2025-07-12 00:58 | #8 | cancelled |
Clean
|
| 2025-07-10 05:06 | #7 | processing |
Clean
|
################# Input parameters #################
# Resource Group Name where the ExR GWs resides in
$rgList= @('ASH-Cust10-02','ASH-Cust30')
$thresholdNumRoutes = 160
###################################################
# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process | Out-Null
Try {
$conn = Get-AutomationConnection -Name 'AzureRunAsConnection'
while(!($connectionResult) -And ($logonAttempt -le 5))
{
$LogonAttempt++
# Logging in to Azure...
$connectionResult = Connect-AzAccount `
-ServicePrincipal `
-ApplicationId $conn.ApplicationId `
-Tenant $conn.TenantId `
-CertificateThumbprint $conn.CertificateThumbprint `
-Subscription $conn.SubscriptionId `
-Environment AzureCloud
Start-Sleep -Seconds 10
}
} Catch {
if (!$conn)
{
$ErrorMessage = "Service principal not found."
throw $ErrorMessage
}
else
{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
# Get the name of the Azure subscription
$subscriptionName=(Get-AzSubscription -SubscriptionId $conn.SubscriptionId).Name
#write-Output "<br>$(Get-Date) - selection of the Azure subscription: $subscriptionName"
Select-AzSubscription -SubscriptionId $conn.SubscriptionId | Out-Null
$GtwList = @()
$results= @()
foreach ($rgName in $rgList)
{
## Collect all the ExpressRoute gateways in a Resource Group
$GtwList=Get-AzVirtualNetworkGateway -ResourceGroupName $rgName
## For each ExpressRoute gateway, get the IP addresses of the BGP peers and collect the number of routes advertised
foreach ($gw in $GtwList) {
$peers = Get-AzVirtualNetworkGatewayBGPPeerStatus -VirtualNetworkGatewayName $gw.Name -ResourceGroupName $rgName
if ($peers[0].State -eq 'Connected') {
$routes1=$null
$routes1 = Get-AzVirtualNetworkGatewayAdvertisedRoute -VirtualNetworkGatewayName $gw.Name -ResourceGroupName $rgName -Peer $peers[0].Neighbor
}
if ($peers[1].State -eq 'Connected') {
$routes2=$null
$routes2 = Get-AzVirtualNetworkGatewayAdvertisedRoute -VirtualNetworkGatewayName $gw.Name -ResourceGroupName $rgName -Peer $peers[1].Neighbor
}
$sampleTime=(Get-Date).ToString("dd-MM-yyyy HH:mm:ss")
if ($routes1.Count -eq $routes2.Count)
{
if ($routes1.Count -lt $thresholdNumRoutes){
$status='OK'
$alertMsg='number of routes below threshold'
}
else {
$status='ALERT'
$alertMsg='number of routes above threshold'
}
}
else
{
$status='WARNING'
$alertMsg='check ER Gateway'
}
$obj = [psCustomObject]@{
resourceGroup =$rgName
nameGtw = $gw.Name
peer1 = $peers[0].Neighbor
peer2 = $peers[1].Neighbor
numRoutesPeer1= $routes1.Count
numRoutesPeer2= $routes2.Count
time=$sampleTime
status=$status
alertMessage = $alertMsg
}
$results += $obj
} ### end foreach gateways in each resource group
} ### end foreach resource group
$jsonResults= ConvertTo-Json $results -Depth 100
Write-Output $jsonResults