App Gateway, Unable to create health probe with powershell

231 Views Asked by At

I'm currently experiencing an issue while attempting to create a health probe using PowerShell. I've already successfully created multiple health probes through the portal.

When I execute the command, I don't receive any error messages. However, upon checking the portal, I cannot find the health probe that I attempted to create using PowerShell. Interestingly, I am able to create a health probe with the same name via the portal.

Any assistance in resolving this issue would be greatly appreciated. Thank you!

I used the command:

$getgw =  Get-AzApplicationGateway -Name Nametest -ResourceGroupName RGtest

# Create the probe object that will check health 

$probeApi = Add-AzApplicationGatewayProbeConfig -ApplicationGateway $getgw -Name $probeNameApi -Protocol Http -Path '/api/test' -Interval 30 -Timeout 120 -UnhealthyThreshold 3 
2

There are 2 best solutions below

3
Imran On

To create health probe in PowerShell, make use of below command.

# Load the application gateway resource into a PowerShell variable by using Get-AzApplicationGateway.
$getgw =  Get-AzApplicationGateway -Name <ApplicationGatewayName>  -ResourceGroupName <RGName>

# Create the probe object that will check health at http://contoso.com/path/path.htm
$probe = Add-AzApplicationGatewayProbeConfig -ApplicationGateway $getgw -Name <HealthyprobeName> -Protocol Http -HostName 'contoso.com' -Path '/path/custompath.htm' -Interval 30 -Timeout 120 -UnhealthyThreshold 8

# Set the backend HTTP settings to use the new probe
$getgw = Set-AzApplicationGatewayBackendHttpSettings -ApplicationGateway $getgw -Name $getgw.BackendHttpSettingsCollection.name -Port 80 -Protocol Http -CookieBasedAffinity Disabled  -RequestTimeout 120

# Save the application gateway with the configuration changes
Set-AzApplicationGateway -ApplicationGateway $getgw

Output:

enter image description here

When I checked the same in Portal after executing script, health probe is created successfully like below:

enter image description here

0
mo taar On

I found the issue, the mistake that I was doing is creating a probe and backendsettings and then save the application gateway.

The solution is that I had to save the application gateway with the command: Set-AzApplicationGateway -ApplicationGateway $getgw

after each scope added:

# Load the application gateway resource into a PowerShell variable by using 
Get-AzApplicationGateway.
$getgw =  Get-AzApplicationGateway -Name appGWName -ResourceGroupName RGName

# Create the probe object that will check health at http://contoso.com/path/path.htm
$probe = Add-AzApplicationGatewayProbeConfig -ApplicationGateway $getgw -Name testprobe01 -Protocol Http -HostName 'contoso.com' -Path '/path/custompath.htm' -Interval 30 -Timeout 120 -UnhealthyThreshold 8
# Save the application gateway with the configuration changes
Set-AzApplicationGateway -ApplicationGateway $getgw
$probe = get-AzApplicationGatewayProbeConfig -ApplicationGateway $getgw -Name testprobe01 

# Set the backend HTTP settings to use the new probe
$Bes = Add-AzApplicationGatewayBackendHttpSettings -ApplicationGateway $getgw - 

Name testbackendhttpsettings -Port 80 -Protocol Http -CookieBasedAffinity Disabled -Probe $probe -RequestTimeout 180 # Save the application gateway with the configuration changes Set-AzApplicationGateway -ApplicationGateway $getgw