You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to create a logic app to process Azure Monitor alerts.
4
4
author: EdB-MSFT
5
5
ms.topic: conceptual
6
-
ms.date: 09/07/2022
6
+
ms.date: 02/09/2023
7
7
ms.author: edbaynash
8
8
ms.reviewer: edbaynash
9
9
10
10
# 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
-
12
11
---
13
12
14
13
# 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
17
16
18
17
[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.
19
18
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)
+ 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)
- Integrate with external services using existing connectors like Outlook, Microsoft Teams, Slack and PagerDuty, or by configuring the Logic App for your own services.
25
24
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:
27
26
28
27
1.[Create a Logic App](#create-a-logic-app) for sending an email or a Teams post.
29
28
1.[Create an alert action group](#create-an-action-group) that triggers the logic app.
30
29
1.[Create a rule](#create-a-rule-using-your-action-group) the uses the action group.
30
+
31
31
## Create a Logic App
32
32
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**.
34
37
1. Select **Review + create**, then select **Create**.
35
38
1. Select **Go to resource** when the deployment is complete.
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
105
108
}
106
109
```
107
110
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:
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.
110
140
111
141
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.":::
112
145
113
146
## [Send an email](#tab/send-email)
114
147
@@ -119,46 +152,45 @@ In this example, we'll use the following steps to create a Logic App that uses t
119
152
1. Sign into Office 365 when prompted to create a connection.
120
153
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.
121
154
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
+
126
159
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.
127
160
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
+
132
165
1. Enter the email address to send the alert to in the **To** field.
133
166
1. Select **Save**.
134
167
135
168
:::image type="content" source="./media/alerts-logic-apps/configure-email.png" alt-text="A screenshot showing the parameters tab for the send email action.":::
136
169
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.
138
171
139
172
The next step is to create an action group to trigger your Logic App.
140
173
141
174
## [Post a Teams message](#tab/send-teams-message)
142
175
143
176
1. In the search field, search for *Microsoft Teams*.
144
-
145
177
1. Select **Microsoft Teams**
146
178
:::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.":::
147
179
1. Select **Post a message in a chat or channel** from the list of actions.
148
180
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.
151
183
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.
153
185
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.
158
190
1. Select **Save**
159
191
:::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.":::
160
192
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.
162
194
163
195
The next step is to create an action group to trigger your Logic App.
164
196
@@ -177,7 +209,7 @@ To trigger your Logic app, create an action group, then create an alert that use
177
209
:::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.":::
178
210
1. In the **Actions** tab under **Action type**, select **Logic App**.
179
211
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).
181
213
1. Select **OK**.
182
214
1. Enter a name in the **Name** field.
183
215
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
193
225
194
226
:::image type="content" source="./media/alerts-logic-apps/test-action-group2.png" alt-text="A screenshot showing an action group details test page.":::
195
227
196
-
The following email will be sent to the specified account:
228
+
The following email is sent to the specified account:
197
229
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.":::
0 commit comments