4

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 Answers1

3

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"
WaitingForGuacamole
  • 3,744
  • 1
  • 8
  • 22
  • Thanks a lot for the solution. It Works !!!!! Great work !!! Happy Coding :) – Srinivasan CK Feb 21 '21 at 19:15
  • Can we get the same implementation using powershell script ? – Srinivasan CK Feb 22 '21 at 13:59
  • See my edit to the post. It's not tested or debugged, but I think changing the ARM template to something "powershell-ish", and pushing it through `Set-AzResource` might do it. – WaitingForGuacamole Feb 22 '21 at 14:30
  • Thanks a lot for the Solution :) the above code works with some semicolons at the end and it saved my day.... You are amazing !!!! – Srinivasan CK Feb 24 '21 at 19:35
  • For those, like me, who found this answer but kept getting "Could not determine JSON object type for type System.Management.Automation.ScriptBlock". The solution is to put an @ in front of the { of the statusCodesRange definition. It's a multi dimensional array and only with the @ I could get it to work. – Jean-Paul Smit Dec 06 '21 at 20:30