Skip to content

Commit 42e4df0

Browse files
Merge pull request #242537 from EdB-MSFT/autoscale-notifications
Article updated and refreshed
2 parents 833fcd4 + c89d4da commit 42e4df0

File tree

3 files changed

+116
-35
lines changed

3 files changed

+116
-35
lines changed

articles/azure-monitor/autoscale/autoscale-webhook-email.md

Lines changed: 116 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,110 @@ description: Learn how to use autoscale actions to call web URLs or send email n
44
author: EdB-MSFT
55
ms.author: edbaynash
66
ms.topic: conceptual
7-
ms.date: 04/03/2017
7+
ms.date: 06/21/2023
88
ms.subservice: autoscale
99
ms.reviewer: akkumari
1010
---
1111
# Use autoscale actions to send email and webhook alert notifications in Azure Monitor
12-
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.
12+
This article shows you how to set up notifications so that you can call specific web URLs or send emails based on autoscale actions in Azure.
1313

1414
## Webhooks
15-
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.
15+
Webhooks allow you to send HTTP requests to a specific URL endpoint (callback URL) when a certain event or trigger occurs. Using webhooks, you can automate and streamline processes by enabling the automatic exchange of information between different systems or applications. Use webhooks to trigger custom code, notifications, or other actions to run when an autoscale event occurs.
1616

1717
## Email
18-
You can send email to any valid email address. Administrators and co-administrators of the subscription where the rule is running are also notified.
18+
You can send email to any valid email address when an autoscale event occurs. Administrators and co-administrators of the subscription where the rule is running are also notified.
1919

20-
## Cloud Services and App Service
21-
You can opt in from the Azure portal for Azure Cloud Services and server farms (Azure App Service).
20+
## Configure Notifications
2221

23-
* Choose the **scale by** metric.
22+
Use the Azure portal, CLI, PowerShell, or Resource Manager templates to configure notifications.
2423

25-
![Screenshot that shows the Autoscale setting pane.](./media/autoscale-webhook-email/insights-autoscale-notify.png)
24+
### [Portal](#tab/portal)
2625

27-
## Virtual machine scale sets
28-
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.
26+
### Set up notifications using the Azure portal.
2927

30-
When you use the REST API or Resource Manager templates, include the notifications element in your [autoscale settings](/azure/templates/microsoft.insights/2015-04-01/autoscalesettings) with the following options:
28+
Select the **Notify** tab on the autoscale settings page to configure notifications.
3129

30+
Select the check boxes to send an email to the subscription administrator or co-administrators. You can also enter a list of email addresses to send notifications to.
31+
32+
Enter a webhook URI to send a notification to a web service. You can also add custom headers to the webhook request. For example, you can add an authentication token in the header, query parameters, or add a custom header to identify the source of the request.
33+
34+
:::image type="content" source="./media/autoscale-webhook-email/autoscale-notify.png" lightbox="./media/autoscale-webhook-email/autoscale-notify.png" alt-text="A screenshot showing the notify tab on the autoscale settings page.":::
35+
36+
37+
### [CLI](#tab/cli)
38+
39+
### Use CLI to configure notifications.
40+
41+
Use the `az monitor autoscale update` or the `az monitor autoscale create` command to configure notifications using Azure CLI.
42+
43+
The following parameters are used to configure notifications:
44+
45+
+ `--add-action` - The action to take when the autoscale rule is triggered. The value must be `email` or `webhook`.
46+
+ `--email-administrator {false, true}` - Send email to the subscription administrator.
47+
+ `--email-coadministrators {false, true}` - Send email to the subscription co-administrators.
48+
+ `--remove-action` - Remove an action previously added by `--add-action`. The value must be `email` or `webhook`. The parameter is only relevant for the `az monitor autoscale update` command.
49+
50+
51+
For example, the following command adds an email notification and a webhook notification to and existing autoscale setting. The command also sends email to the subscription administrator.
52+
53+
```azurecli
54+
az monitor autoscale update \
55+
--resource-group <resource group name> \
56+
--name <autoscale setting name> \
57+
--email-administrator true \
58+
--add-action email [email protected] \
59+
--add-action webhook http://myservice.com/webhook-listerner-123
3260
```
61+
62+
> [!NOTE]
63+
> You can add mote than one email or webhook notification by using the `--add-action` parameter multiple times. While multiple webhook notifications are supported and can be seen in the JSON, the portal only shows the first webhook.
64+
65+
66+
For more information, see [az monitor autoscale](https://learn.microsoft.com/cli/azure/monitor/autoscale?view=azure-cli-latest).
67+
68+
69+
70+
### [PowerShell](#tab/powershell)
71+
72+
### Use PowerShell to configure notifications.
73+
74+
The following example shows how to configure a webhook and email notification.
75+
76+
1. Create the webhook object.
77+
78+
1. Create the notification object.
79+
1. Add the notification object to the autoscale setting using `New-AzAutoscaleSetting` or `Update-AzAutoscaleSetting` cmdlets.
80+
81+
```powershell
82+
# Assumining you have already created a profile object and have a vmssName, resourceGroup, and subscriptionId
83+
84+
$webhook=New-AzAutoscaleWebhookNotificationObject `
85+
-Property @{"method"='GET'; "headers"= '"Authorization", "tokenvalue-12345678abcdef"'} `
86+
-ServiceUri "http://myservice.com/webhook-listerner-123"
87+
88+
$notification=New-AzAutoscaleNotificationObject `
89+
-EmailCustomEmail "[email protected]" `
90+
-EmailSendToSubscriptionAdministrator $true ` -EmailSendToSubscriptionCoAdministrator $true `
91+
-Webhook $webhook
92+
93+
94+
New-AzAutoscaleSetting -Name autoscalesetting2 `
95+
-ResourceGroupName $resourceGroup `
96+
-Location eastus `
97+
-Profile $profile `
98+
-Enabled -Notification $notification `
99+
-PropertiesName "autoscalesetting" `
100+
-TargetResourceUri "/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$vmssName"
101+
```
102+
103+
104+
### [Resource Manager](#tab/resourcemanager)
105+
106+
### Use Resource Manager templates to configure notifications.
107+
108+
When you use the Resource Manager templates or REST API, include the `notifications` element in your [autoscale settings](https://learn.microsoft.com/azure/templates/microsoft.insights/autoscalesettings?pivots=deployment-language-arm-template#resource-format-1), for example:
109+
110+
```JSON
33111
"notifications": [
34112
{
35113
"operation": "Scale",
@@ -43,7 +121,7 @@ When you use the REST API or Resource Manager templates, include the notificatio
43121
},
44122
"webhooks": [
45123
{
46-
"serviceUri": "https://foo.webhook.example.com?token=abcd1234",
124+
"serviceUri": "https://my.webhook.example.com?token=abcd1234",
47125
"properties": {
48126
"optional_key1": "optional_value1",
49127
"optional_key2": "optional_value2"
@@ -64,35 +142,38 @@ When you use the REST API or Resource Manager templates, include the notificatio
64142
| serviceUri |Yes |Valid HTTPS URI. |
65143
| properties |Yes |Value must be empty {} or can contain key-value pairs. |
66144

145+
---
146+
67147
## Authentication in webhooks
68-
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.
148+
The webhook can authenticate by using token-based authentication, where you save the webhook URI with a token ID as a query parameter. For example, `https://mysamplealert/webcallback?tokenid=123-abc456-7890&myparameter2=value123`.
69149

70150
## Autoscale notification webhook payload schema
71151
When the autoscale notification is generated, the following metadata is included in the webhook payload:
72152

73-
```
153+
```JSON
74154
{
75-
"version": "1.0",
76-
"status": "Activated",
77-
"operation": "Scale In",
78-
"context": {
79-
"timestamp": "2016-03-11T07:31:04.5834118Z",
80-
"id": "/subscriptions/s1/resourceGroups/rg1/providers/microsoft.insights/autoscalesettings/myautoscaleSetting",
81-
"name": "myautoscaleSetting",
82-
"details": "Autoscale successfully started scale operation for resource 'MyCSRole' from capacity '3' to capacity '2'",
83-
"subscriptionId": "s1",
84-
"resourceGroupName": "rg1",
85-
"resourceName": "MyCSRole",
86-
"resourceType": "microsoft.classiccompute/domainnames/slots/roles",
87-
"resourceId": "/subscriptions/s1/resourceGroups/rg1/providers/microsoft.classicCompute/domainNames/myCloudService/slots/Production/roles/MyCSRole",
88-
"portalLink": "https://portal.azure.com/#resource/subscriptions/s1/resourceGroups/rg1/providers/microsoft.classicCompute/domainNames/myCloudService",
89-
"oldCapacity": "3",
90-
"newCapacity": "2"
91-
},
92-
"properties": {
93-
"key1": "value1",
94-
"key2": "value2"
95-
}
155+
"version": "1.0",
156+
"status": "Activated",
157+
"operation": "Scale Out",
158+
"context": {
159+
"timestamp": "2023-06-22T07:01:47.8926726Z",
160+
"id": "/subscriptions/123456ab-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/rg-001/providers/microsoft.insights/autoscalesettings/AutoscaleSettings-002",
161+
"name": "AutoscaleSettings-002",
162+
"details": "Autoscale successfully started scale operation for resource 'ScaleableAppServicePlan' from capacity '1' to capacity '2'",
163+
"subscriptionId": "123456ab-9876-a1b2-a2b1-123a567b9f8767",
164+
"resourceGroupName": "rg-001",
165+
"resourceName": "ScaleableAppServicePlan",
166+
"resourceType": "microsoft.web/serverfarms",
167+
"resourceId": "/subscriptions/123456ab-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/rg-001/providers/Microsoft.Web/serverfarms/ScaleableAppServicePlan",
168+
"portalLink": "https://portal.azure.com/#resource/subscriptions/123456ab-9876-a1b2-a2b1-123a567b9f8767/resourceGroups/rg-001/providers/Microsoft.Web/serverfarms/ScaleableAppServicePlan",
169+
"resourceRegion": "West Central US",
170+
"oldCapacity": "1",
171+
"newCapacity": "2"
172+
},
173+
"properties": {
174+
"key1": "value1",
175+
"key2": "value2"
176+
}
96177
}
97178
```
98179

37.8 KB
Loading

0 commit comments

Comments
 (0)