Use autoscale actions to send email and webhook alert notifications in Azure Monitor

This article shows you how to set up triggers so that you can call specific web URLs or send emails based on autoscale actions in Azure.

Webhooks

Webhooks allow you to route Azure alert notifications to other systems for post-processing or custom notifications. Examples include routing the alert to services that can handle an incoming web request to send an SMS, log bugs, or notify a team by using chat or messaging services. The webhook URI must be a valid HTTP or HTTPS endpoint.

Email

You can send email to any valid email address. Administrators and co-administrators of the subscription where the rule is running are also notified.

Cloud Services and App Service

You can opt in from the Azure portal for Azure Cloud Services and server farms (Azure App Service).

  • Choose the scale by metric.

    Screenshot that shows the Autoscale setting pane.

Virtual machine scale sets

For newer virtual machines created with Azure Resource Manager (virtual machine scale sets), you can use the REST API, Resource Manager templates, PowerShell, and the Azure CLI for configuration. An Azure portal interface isn't yet available.

When you use the REST API or Resource Manager templates, include the notifications element in your autoscale settings with the following options:

"notifications": [
      {
        "operation": "Scale",
        "email": {
          "sendToSubscriptionAdministrator": false,
          "sendToSubscriptionCoAdministrators": false,
          "customEmails": [
              "user1@mycompany.com",
              "user2@mycompany.com"
              ]
        },
        "webhooks": [
          {
            "serviceUri": "https://foo.webhook.example.com?token=abcd1234",
            "properties": {
              "optional_key1": "optional_value1",
              "optional_key2": "optional_value2"
            }
          }
        ]
      }
    ]
Field Mandatory Description
operation Yes Value must be "Scale."
sendToSubscriptionAdministrator Yes Value must be "true" or "false."
sendToSubscriptionCoAdministrators Yes Value must be "true" or "false."
customEmails Yes Value can be null [] or a string array of emails.
webhooks Yes Value can be null or valid URI.
serviceUri Yes Valid HTTPS URI.
properties Yes Value must be empty {} or can contain key-value pairs.

Authentication in webhooks

The webhook can authenticate by using token-based authentication, where you save the webhook URI with a token ID as a query parameter. An example is https://mysamplealert/webcallback?tokenid=sometokenid&someparameter=somevalue.

Autoscale notification webhook payload schema

When the autoscale notification is generated, the following metadata is included in the webhook payload:

{
        "version": "1.0",
        "status": "Activated",
        "operation": "Scale In",
        "context": {
                "timestamp": "2016-03-11T07:31:04.5834118Z",
                "id": "/subscriptions/s1/resourceGroups/rg1/providers/microsoft.insights/autoscalesettings/myautoscaleSetting",
                "name": "myautoscaleSetting",
                "details": "Autoscale successfully started scale operation for resource 'MyCSRole' from capacity '3' to capacity '2'",
                "subscriptionId": "s1",
                "resourceGroupName": "rg1",
                "resourceName": "MyCSRole",
                "resourceType": "microsoft.classiccompute/domainnames/slots/roles",
                "resourceId": "/subscriptions/s1/resourceGroups/rg1/providers/microsoft.classicCompute/domainNames/myCloudService/slots/Production/roles/MyCSRole",
                "portalLink": "https://portal.azure.com/#resource/subscriptions/s1/resourceGroups/rg1/providers/microsoft.classicCompute/domainNames/myCloudService",
                "oldCapacity": "3",
                "newCapacity": "2"
        },
        "properties": {
                "key1": "value1",
                "key2": "value2"
        }
}
Field Mandatory Description
status Yes Status that indicates that an autoscale action was generated.
operation Yes For an increase of instances, it's' "Scale Out." For a decrease in instances, it's' "Scale In."
context Yes Autoscale action context.
timestamp Yes Time stamp when the autoscale action was triggered.
id Yes Resource Manager ID of the autoscale setting.
name Yes Name of the autoscale setting.
details Yes Explanation of the action that the autoscale service took and the change in the instance count.
subscriptionId Yes Subscription ID of the target resource that's being scaled.
resourceGroupName Yes Resource group name of the target resource that's being scaled.
resourceName Yes Name of the target resource that's being scaled.
resourceType Yes Three supported values: "microsoft.classiccompute/domainnames/slots/roles" - Azure Cloud Services roles, "microsoft.compute/virtualmachinescalesets" - Azure Virtual Machine Scale Sets, and "Microsoft.Web/serverfarms" - Web App feature of Azure Monitor.
resourceId Yes Resource Manager ID of the target resource that's being scaled.
portalLink Yes Azure portal link to the summary page of the target resource.
oldCapacity Yes Current (old) instance count when autoscale took a scale action.
newCapacity Yes New instance count to which autoscale scaled the resource.
properties No Optional. Set of <Key, Value> pairs (for example, Dictionary <String, String>). The properties field is optional. In a custom user interface or logic app-based workflow, you can enter keys and values that can be passed by using the payload. An alternate way to pass custom properties back to the outgoing webhook call is to use the webhook URI itself (as query parameters).