Skip to content

Commit e1aa3e1

Browse files
authored
Merge pull request #226334 from AbbyMSFT/logic-app-alerts
Add ability to add resource tags to logic apps for alert notifications
2 parents feeeed7 + d85aa14 commit e1aa3e1

File tree

2 files changed

+65
-33
lines changed

2 files changed

+65
-33
lines changed

articles/azure-monitor/alerts/alerts-logic-apps.md

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ title: Customize alert notifications using Logic Apps
33
description: Learn how to create a logic app to process Azure Monitor alerts.
44
author: EdB-MSFT
55
ms.topic: conceptual
6-
ms.date: 09/07/2022
6+
ms.date: 02/09/2023
77
ms.author: edbaynash
88
ms.reviewer: edbaynash
99

1010
# Customer intent: As an administrator I want to create a logic app that is triggered by an alert so that I can send emails or Teams messages when an alert is fired.
11-
1211
---
1312

1413
# Customize alert notifications using Logic Apps
@@ -17,24 +16,28 @@ This article shows you how to create a Logic App and integrate it with an Azure
1716

1817
[Azure Logic Apps](../../logic-apps/logic-apps-overview.md) allows you to build and customize workflows for integration. Use Logic Apps to customize your alert notifications.
1918

20-
+ Customize the alerts email, using your own email subject and body format.
21-
+ Customize the alert metadata by looking up tags for affected resources or fetching a log query search result. For information on how to access the search result rows containing alerts data, see:
22-
+ [Azure Monitor Log Analytics API response format](../logs/api/response-format.md)
23-
+ [Query/management HTTP response](/azure/data-explorer/kusto/api/rest/response)
24-
+ Integrate with external services using existing connectors like Outlook, Microsoft Teams, Slack and PagerDuty, or by configuring the Logic App for your own services.
19+
- Customize the alerts email, using your own email subject and body format.
20+
- Customize the alert metadata by looking up tags for affected resources or fetching a log query search result. For information on how to access the search result rows containing alerts data, see:
21+
- [Azure Monitor Log Analytics API response format](../logs/api/response-format.md)
22+
- [Query/management HTTP response](/azure/data-explorer/kusto/api/rest/response)
23+
- Integrate with external services using existing connectors like Outlook, Microsoft Teams, Slack and PagerDuty, or by configuring the Logic App for your own services.
2524

26-
In this example, we'll use the following steps to create a Logic App that uses the [common alerts schema](./alerts-common-schema.md) to send details from the alert. The example uses the following steps:
25+
In this example, the following steps create a Logic App that uses the [common alerts schema](./alerts-common-schema.md) to send details from the alert. The example uses the following steps:
2726

2827
1. [Create a Logic App](#create-a-logic-app) for sending an email or a Teams post.
2928
1. [Create an alert action group](#create-an-action-group) that triggers the logic app.
3029
1. [Create a rule](#create-a-rule-using-your-action-group) the uses the action group.
30+
3131
## Create a Logic App
3232

33-
1. Create a new Logic app. Set **Logic App name** , select **Consumption Plan type**.
33+
1. In the [portal](https://portal.azure.com/), create a new Logic app. In the **Search** bar at the top of the page, enter "Logic App".
34+
1. On the **Logic App** page, select **+Add**.
35+
1. Select the **Subscription** and **Resource group** for your Logic App.
36+
1. Set **Logic App name**, and select **Consumption Plan type**.
3437
1. Select **Review + create**, then select **Create**.
3538
1. Select **Go to resource** when the deployment is complete.
3639
:::image type="content" source="./media/alerts-logic-apps/create-logic-app.png" alt-text="A screenshot showing the create logic app page.":::
37-
1. On the Logic Apps Designer page, select **When a HTTP request is received**.
40+
1. On the **Logic Apps Designer** page, select **When a HTTP request is received**.
3841
:::image type="content" source="./media/alerts-logic-apps/logic-apps-designer.png" alt-text="A screenshot showing the Logic Apps designer start page.":::
3942

4043
1. Paste the common alert schema into the **Request Body JSON Schema** field from the following JSON:
@@ -105,10 +108,40 @@ In this example, we'll use the following steps to create a Logic App that uses t
105108
}
106109
```
107110

108-
1. Select the **+** icon to insert a new step.
109-
:::image type="content" source="./media/alerts-logic-apps/configure-http-request-received.png" alt-text="A screenshot showing the parameters for the when http request received step.":::
111+
:::image type="content" source="./media/alerts-logic-apps/configure-http-request-received.png" alt-text="A screenshot showing the parameters for the http request received step.":::
112+
113+
1. (Optional). You can customize the alert notification by extracting information about the affected resource on which the alert fired, e.g. the resource’s tags. You can then include those resource tags in the alert payload and use the information in your logical expressions for sending the notifications. To do this, we will:
114+
- Create a variable for the affected resource IDs.
115+
- Split the resource ID into in an array so we can use its various elements (e.g. subscription, resource group).
116+
- Use the Azure Resource Manager connector to read the resource’s metadata.
117+
- Fetch the resource’s tags which can then be used in subsequent steps of the Logic App.
118+
119+
1. Select **+** and **Add an action** to insert a new step.
120+
1. In the **Search** field, search for and select **Initialize variable**.
121+
1. In the **Name** field, enter the name of the variable, such as 'AffectedResources'.
122+
1. In the **Type** field, select **Array**.
123+
1. In the **Value** field, select **Add dynamic Content**. Select the **Expression** tab, and enter this string: `split(triggerBody()?['data']?['essentials']?['alertTargetIDs'][0], '/')`.
124+
125+
:::image type="content" source="./media/alerts-logic-apps/initialize-variable.png" alt-text="A screenshot showing the parameters for the initializing a variable in Logic Apps.":::
126+
127+
1. Select **+** and **Add an action** to insert another step.
128+
1. In the **Search** field, search for and select **Azure Resource Manager**, and then **Read a resource**.
129+
1. Populate the fields of the **Read a resource** action with the array values from the `AffectedResources` variable. In each of the fields, click inside the field, and scroll down to **Enter a custom value**. Select **Add dynamic content**, and then select the **Expression** tab. Enter the strings from this table:
130+
131+
|Field|String value|
132+
|---------|---------|
133+
|Subscription|`variables('AffectedResource')[2]`|
134+
|Resource Group|`variables('AffectedResource')[4]`|
135+
|Resource Provider|`variables('AffectedResource')[6]`|
136+
|Short Resource Id|`concat(variables('AffectedResource')[7], '/', variables('AffectedResource')[8]`)|
137+
|Client Api Version|2021-06-01|
138+
139+
The dynamic content now includes tags from the affected resource. You can use those tags when you configure your notifications as described in the following steps.
110140

111141
1. Send an email or post a Teams message.
142+
1. Select **+** and **Add an action** to insert a new step.
143+
144+
:::image type="content" source="./media/alerts-logic-apps/configure-http-request-received.png" alt-text="A screenshot showing the parameters for the when http request received step.":::
112145

113146
## [Send an email](#tab/send-email)
114147

@@ -119,46 +152,45 @@ In this example, we'll use the following steps to create a Logic App that uses t
119152
1. Sign into Office 365 when prompted to create a connection.
120153
1. Create the email **Body** by entering static text and including content taken from the alert payload by choosing fields from the **Dynamic content** list.
121154
For example:
122-
- Enter *An alert has monitoring condition:* then select **monitorCondition** from the **Dynamic content** list.
123-
- Then enter *Date fired:* and select **firedDateTime** from the **Dynamic content** list.
124-
- Enter *Affected resources:* and select **alterTargetIDs** from the **Dynamic content** list.
125-
155+
- Enter the text: `An alert has been triggered with this monitoring condition:`. Then, select **monitorCondition** from the **Dynamic content** list.
156+
- Enter the text: `Date fired:`. Then, select **firedDateTime** from the **Dynamic content** list.
157+
- Enter the text: `Affected resources:`. Then, select **alertTargetIDs** from the **Dynamic content** list.
158+
126159
1. In the **Subject** field, create the subject text by entering static text and including content taken from the alert payload by choosing fields from the **Dynamic content** list.
127160
For example:
128-
- Enter *Alert:* and select **alertRule** from the **Dynamic content** list.
129-
- Then enter *with severity:* and select **severity** from the **Dynamic content** list.
130-
- Enter *has condition:* and select **monitorCondition** from the **Dynamic content** list.
131-
161+
- Enter the text: `Alert:`. Then, select **alertRule** from the **Dynamic content** list.
162+
- Enter the text: `with severity:`. Then, select **severity** from the **Dynamic content** list.
163+
- Enter the text: `has condition:`. Then, select **monitorCondition** from the **Dynamic content** list.
164+
132165
1. Enter the email address to send the alert to in the **To** field.
133166
1. Select **Save**.
134167

135168
:::image type="content" source="./media/alerts-logic-apps/configure-email.png" alt-text="A screenshot showing the parameters tab for the send email action.":::
136169

137-
You've created a Logic App that will send an email to the specified address, with details from the alert that triggered it.
170+
You've created a Logic App that sends an email to the specified address, with details from the alert that triggered it.
138171

139172
The next step is to create an action group to trigger your Logic App.
140173

141174
## [Post a Teams message](#tab/send-teams-message)
142175

143176
1. In the search field, search for *Microsoft Teams*.
144-
145177
1. Select **Microsoft Teams**
146178
:::image type="content" source="./media/alerts-logic-apps/choose-operation-teams.png" alt-text="A screenshot showing add action page of the logic apps designer with Microsoft Teams selected.":::
147179
1. Select **Post a message in a chat or channel** from the list of actions.
148180
1. Sign into Teams when prompted to create a connection.
149-
1. Select *User* from the **Post as** dropdown.
150-
1. Select *Group chat* from the **Post in** dropdown.
181+
1. Select **User** from the **Post as** dropdown.
182+
1. Select **Group chat** from the **Post in** dropdown.
151183
1. Select your group from the **Group chat** dropdown.
152-
1. Create the message text in the **Message** field by entering static text and including content taken from the alert payload by choosing fields from the **Dynamic content** list.
184+
1. Create the message text in the **Message** field by entering static text and including content taken from the alert payload by choosing fields from the **Dynamic content** list.
153185
For example:
154-
- Enter *Alert:* then select **alertRule** from the **Dynamic content** list.
155-
- Enter *with severity:* and select **severity** from the **Dynamic content** list.
156-
- Enter *was fired at:* and select **firedDateTime** from the **Dynamic content** list.
157-
- Add more fields according to your requirements.
186+
1. Enter `Alert:` then select **alertRule** from the **Dynamic content** list.
187+
1. Enter `with severity:` and select **severity** from the **Dynamic content** list.
188+
1. Enter `was fired at:` and select **firedDateTime** from the **Dynamic content** list.
189+
1. Add more fields according to your requirements.
158190
1. Select **Save**
159191
:::image type="content" source="./media/alerts-logic-apps/configure-teams-message.png" alt-text="A screenshot showing the parameters tab for the post a message in a chat or channel action.":::
160192

161-
You've created a Logic App that will send a Teams message to the specified group, with details from the alert that triggered it.
193+
You've created a Logic App that sends a Teams message to the specified group, with details from the alert that triggered it.
162194

163195
The next step is to create an action group to trigger your Logic App.
164196

@@ -177,7 +209,7 @@ To trigger your Logic app, create an action group, then create an alert that use
177209
:::image type="content" source="./media/alerts-logic-apps/create-action-group.png" alt-text="A screenshot showing the actions tab of a create action group page.":::
178210
1. In the **Actions** tab under **Action type**, select **Logic App**.
179211
1. In the **Logic App** section, select your logic app from the dropdown.
180-
1. Set **Enable common alert schema** to *Yes*. If you select *No*, the alert type will determine which alert schema is used. For more information about alert schemas, see [Context specific alert schemas](./alerts-non-common-schema-definitions.md).
212+
1. Set **Enable common alert schema** to *Yes*. If you select *No*, the alert type determines which alert schema is used. For more information about alert schemas, see [Context specific alert schemas](./alerts-non-common-schema-definitions.md).
181213
1. Select **OK**.
182214
1. Enter a name in the **Name** field.
183215
1. Select **Review + create**, the **Create**.
@@ -193,9 +225,9 @@ To trigger your Logic app, create an action group, then create an alert that use
193225

194226
:::image type="content" source="./media/alerts-logic-apps/test-action-group2.png" alt-text="A screenshot showing an action group details test page.":::
195227

196-
The following email will be sent to the specified account:
228+
The following email is sent to the specified account:
197229

198-
:::image type="content" source="./media/alerts-logic-apps/sample-output-email.png" alt-text="A screenshot showing an sample email sent by the test page.":::
230+
:::image type="content" source="./media/alerts-logic-apps/sample-output-email.png" alt-text="A screenshot showing a sample email sent by the test page.":::
199231

200232

201233
## Create a rule using your action group
49.4 KB
Loading

0 commit comments

Comments
 (0)