Skip to content

Commit 3aaf5bb

Browse files
committed
Add Resource tags to dynamic content in logic apps
1 parent f40fd56 commit 3aaf5bb

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

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

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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

@@ -23,7 +23,7 @@ This article shows you how to create a Logic App and integrate it with an Azure
2323
+ [Query/management HTTP response](/azure/data-explorer/kusto/api/rest/response)
2424
+ Integrate with external services using existing connectors like Outlook, Microsoft Teams, Slack and PagerDuty, or by configuring the Logic App for your own services.
2525

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:
26+
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:
2727

2828
1. [Create a Logic App](#create-a-logic-app) for sending an email or a Teams post.
2929
1. [Create an alert action group](#create-an-action-group) that triggers the logic app.
@@ -110,21 +110,31 @@ In this example, we'll use the following steps to create a Logic App that uses t
110110
```
111111

112112

113-
1. (Optional). You can customize the alert notification by extracting information about the resource using resource tags. You can then include those resource tags to the alert payload and use the information in your logical expressions for sending the notifications. In this case, we are going to create a variable for the Affected Resource IDs and split them into in an array to add to the payload. You can then use these values to customize the alert notification.
114-
1. Select the **+** icon to insert a new step.
113+
1. (Optional). You can customize the alert notification by extracting information about the resource using resource tags. You can then include those resource tags to the alert payload and use the information in your logical expressions for sending the notifications. Create a variable for the Affected Resource IDs and split them into in an array to add to the payload. You can then use these values to customize the alert notification.
114+
1. Select **+** and **Add an action** to insert a new step.
115115

116-
:::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.":::
116+
:::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.":::
117117

118-
1. In the **Search** field, search for and select enter **Initialize variable**.
118+
1. In the **Search** field, search for and select **Initialize variable**.
119119
1. In the **Name** field, enter the name of the variable, such as 'AffectedResources'.
120-
1. In the type field, select **Array**.
121-
1. In the **Value** field, select **Dynamic Content**. In the **Expression** tab, enter:
122-
```json
123-
split(triggerBody()?['data']?['essentials']?['alertTargetIDs'][0], '/')
124-
```
125-
1. Select **OK**.
126-
127-
:::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.":::
120+
1. In the **Type** field, select **Array**.
121+
1. In the **Value** field, select **Add dynamic Content**. Select the **Expression** tab, and enter this string: *split(triggerBody()?['data']?['essentials']?['alertTargetIDs'][0], '/')*
122+
123+
:::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.":::
124+
125+
1. Select **+** and **Add an action** to insert another step.
126+
1. In the **Search** field, search for and select **Azure Resource Manager**, and then **Read a resource**.
127+
1. Populate the array with the tags from the affected resources with this information. 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:
128+
129+
|Field|String value|
130+
|---------|---------|
131+
|Subscription|*variables('AffectedResource')[2]*|
132+
|Resource Group|*variables('AffectedResource')[4]*|
133+
|Resource Provider|*variables('AffectedResource')[6]*|
134+
|Short Resource Id|*concat(variables('AffectedResource')[7], '/', variables('AffectedResource')[8])*|
135+
|Client Api Version|2021-06-01|
136+
1. The dynamic content now includes tags from the resource that you can use in your notification.
137+
128138
1. Send an email or post a Teams message.
129139

130140
## [Send an email](#tab/send-email)
@@ -140,22 +150,22 @@ In this example, we'll use the following steps to create a Logic App that uses t
140150
1. Sign into Office 365 when prompted to create a connection.
141151
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.
142152
For example:
143-
- Enter *An alert has monitoring condition:* then select **monitorCondition** from the **Dynamic content** list.
144-
- Then enter *Date fired:* and select **firedDateTime** from the **Dynamic content** list.
145-
- Enter *Affected resources:* and select **alertTargetIDs** from the **Dynamic content** list.
146-
153+
- Enter the text: *An alert has been triggered with this monitoring condition:*. Then, select **monitorCondition** from the **Dynamic content** list.
154+
- Enter the text: *Date fired:*. Then, select **firedDateTime** from the **Dynamic content** list.
155+
- Enter the text: *Affected resources:*. Then, select **alertTargetIDs** from the **Dynamic content** list.
156+
147157
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.
148158
For example:
149-
- Enter *Alert:* and select **alertRule** from the **Dynamic content** list.
150-
- Then enter *with severity:* and select **severity** from the **Dynamic content** list.
151-
- Enter *has condition:* and select **monitorCondition** from the **Dynamic content** list.
152-
159+
- Enter the text: *Alert:*. Then, select **alertRule** from the **Dynamic content** list.
160+
- Enter the text: *with severity:*. Then, select **severity** from the **Dynamic content** list.
161+
- Enter the text: *has condition:*. Then, select **monitorCondition** from the **Dynamic content** list.
162+
153163
1. Enter the email address to send the alert to in the **To** field.
154164
1. Select **Save**.
155165

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

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

160170
The next step is to create an action group to trigger your Logic App.
161171

@@ -170,7 +180,7 @@ The next step is to create an action group to trigger your Logic App.
170180
1. Select *User* from the **Post as** dropdown.
171181
1. Select *Group chat* from the **Post in** dropdown.
172182
1. Select your group from the **Group chat** dropdown.
173-
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.
183+
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.
174184
For example:
175185
- Enter *Alert:* then select **alertRule** from the **Dynamic content** list.
176186
- Enter *with severity:* and select **severity** from the **Dynamic content** list.
@@ -179,7 +189,7 @@ The next step is to create an action group to trigger your Logic App.
179189
1. Select **Save**
180190
:::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.":::
181191

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

184194
The next step is to create an action group to trigger your Logic App.
185195

@@ -198,7 +208,7 @@ To trigger your Logic app, create an action group, then create an alert that use
198208
:::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.":::
199209
1. In the **Actions** tab under **Action type**, select **Logic App**.
200210
1. In the **Logic App** section, select your logic app from the dropdown.
201-
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).
211+
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).
202212
1. Select **OK**.
203213
1. Enter a name in the **Name** field.
204214
1. Select **Review + create**, the **Create**.
@@ -214,7 +224,7 @@ To trigger your Logic app, create an action group, then create an alert that use
214224

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

217-
The following email will be sent to the specified account:
227+
The following email is sent to the specified account:
218228

219229
:::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.":::
220230

0 commit comments

Comments
 (0)