2
votes

I need to Create ARM Template to enable Auto healing in Azure App service with Custom Auto healing based on HTTP status code range (400-530) and recycle the App service if the request count is reached for the specified status codes and specified time limit. I couldn't find ARM template config for status code range and I am able to see only for single status code. Can someone pls help me in finding the right config to mention the status code range and tell me how the below has to be configured.

"type": "Microsoft.Web/sites/config", "apiVersion": "2018-11-01", "name": "[concat(parameters('sites_SampleAutoHeal_name'), '/web')]", "location": "West Europe", "dependsOn": [ "[resourceId('Microsoft.Web/sites', parameters('sites_SampleAutoHeal_name'))]" ], ..... "autoHealEnabled": true, "autoHealRules": { "triggers": { "privateBytesInKB": 0, "statusCodes": [], "slowRequests": {} }, "actions": { "actionType": "Recycle", "minProcessExecutionTime": "00:00:00" } },

1

1 Answers

1
votes

OK, I don't know if this is going to solve your issue. I'll post what I have and then explain:

        "autoHealEnabled": true,
        "autoHealRules": {
            "triggers": {
                "requests": null,
                "privateBytesInKB": 0,
                "statusCodes": [],
                "statusCodesRange": [
                    {
                        "statusCodes": "500-530",
                        "path": "",
                        "count": 10,
                        "timeInterval": "00:02:00"
                    }
                ],
                "slowRequests": null,
                "slowRequestsWithPath": []
            },
            "actions": {
                "actionType": 0,
                "customAction": null,
                "minProcessExecutionTime": "00:00:00"
            }
        },

Here's what I did:

  1. Went to the activity log for the app service and pulled up the most recent change JSON. no result
  2. Exported the template for that resource in the resource group export. Looked through all history. no result - only what appeared to be an empty config for auto heal
  3. Ran Export-AzResourceGroup to do the same thing, same as 2.
  4. Went to the diagnostics blade for the app service and pulled up Auto Heal with the debugger turned on, and went to the custom rules tab. In the traffic log, I found a request to the management API that returned a result which included the configuration above. Success???

Bottom line? I think you could try this. It might work. I'm not convinced this is completely wired into ARM in a standard way, and it may be possible that it has to be done by API.

Edit: I just verified in Postman that https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Web/sites/{{appServiceName}}/config/web?api-version=2015-08-01 returns the auto-heal settings. So, it's probable that if ARM templates aren't doing the trick you might be able to do this with the API.

Edit: So, I used $app = Get-AzWebApp ... on an app service where I had this set up, and $app.SiteConfig.AutoHealRules.Triggers only includes Requests, PrivateBytesInKB, StatusCodes (not range), and SlowRequests. So, using Set-AzWebApp looks like it's not ready for that yet.

You could try something like this - it's not debugged:

$props = @{
    autoHealEnabled =  $true
    autoHealRules =  @{
        triggers =  @{
            requests =  $null
            privateBytesInKB =  0
            statusCodes =  @()
            statusCodesRange =  @(
                {
                    statusCodes =  "500-530"
                    path =  ""
                    count =  10
                    timeInterval =  "00:02:00"
                }
            )
            slowRequests =  $null
            slowRequestsWithPath =  @()
        }
        actions =  @{
            actionType =  0
            customAction =  $null
            minProcessExecutionTime =  "00:00:00"
        }
        }
    }

Set-AzResource -$props -ResourceGroupName "YourResourceGroup" -ResourceName "YourAppServiceName/web" -ResourceType "Microsoft.Web/sites/config"