|
| 1 | +--- |
| 2 | +title: Customize alert notifications using Logic Apps |
| 3 | +description: Learn how to create a logic app to process Azure Monitor alerts. |
| 4 | +author: EdB-MSFT |
| 5 | +ms.topic: conceptual |
| 6 | +ms.date: 09/07/2022 |
| 7 | +ms.author: edbaynash |
| 8 | +ms.reviewer: edbaynash |
| 9 | + |
| 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 | +--- |
| 13 | + |
| 14 | +# Customize alert notifications using Logic Apps |
| 15 | + |
| 16 | +This article shows you how to create a Logic App and integrate it with an Azure Monitor Alert. |
| 17 | + |
| 18 | +[Azure Logic Apps](https://docs.microsoft.com/azure/logic-apps/logic-apps-overview) allows you to build and customize workflows for integration. Use Logic Apps to customize your alert notifications. |
| 19 | + |
| 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. |
| 22 | ++ Integrate with external services using existing connectors like Outlook, Microsoft Teams, Slack and PagerDuty, or by configuring the Logic App for your own services. |
| 23 | + |
| 24 | +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 | + |
| 26 | +1. [Create a Logic App](#create-a-logic-app) for sending an email or a Teams post. |
| 27 | +1. [Create an alert action group](#create-an-action-group) that triggers the logic app. |
| 28 | +1. [Create a rule](#create-a-rule-using-your-action-group) the uses the action group. |
| 29 | +## Create a Logic App |
| 30 | + |
| 31 | +1. Create a new Logic app. Set **Logic App name** , select **Consumption Plan type**. |
| 32 | +1. Select **Review + create**, then select **Create**. |
| 33 | +1. Select **Go to resource** when the deployment is complete. |
| 34 | +:::image type="content" source="./media/alerts-logic-apps/create-logic-app.png" alt-text="A screenshot showing the create logic app page."::: |
| 35 | +1. On the Logic Apps Designer page, select **When a HTTP request is received**. |
| 36 | +:::image type="content" source="./media/alerts-logic-apps/logic-apps-designer.png" alt-text="A screenshot showing the Logic Apps designer start page."::: |
| 37 | + |
| 38 | +1. Paste the common alert schema into the **Request Body JSON Schema** field from the following JSON: |
| 39 | + ```json |
| 40 | + { |
| 41 | + "type": "object", |
| 42 | + "properties": { |
| 43 | + "schemaId": { |
| 44 | + "type": "string" |
| 45 | + }, |
| 46 | + "data": { |
| 47 | + "type": "object", |
| 48 | + "properties": { |
| 49 | + "essentials": { |
| 50 | + "type": "object", |
| 51 | + "properties": { |
| 52 | + "alertId": { |
| 53 | + "type": "string" |
| 54 | + }, |
| 55 | + "alertRule": { |
| 56 | + "type": "string" |
| 57 | + }, |
| 58 | + "severity": { |
| 59 | + "type": "string" |
| 60 | + }, |
| 61 | + "signalType": { |
| 62 | + "type": "string" |
| 63 | + }, |
| 64 | + "monitorCondition": { |
| 65 | + "type": "string" |
| 66 | + }, |
| 67 | + "monitoringService": { |
| 68 | + "type": "string" |
| 69 | + }, |
| 70 | + "alertTargetIDs": { |
| 71 | + "type": "array", |
| 72 | + "items": { |
| 73 | + "type": "string" |
| 74 | + } |
| 75 | + }, |
| 76 | + "originAlertId": { |
| 77 | + "type": "string" |
| 78 | + }, |
| 79 | + "firedDateTime": { |
| 80 | + "type": "string" |
| 81 | + }, |
| 82 | + "resolvedDateTime": { |
| 83 | + "type": "string" |
| 84 | + }, |
| 85 | + "description": { |
| 86 | + "type": "string" |
| 87 | + }, |
| 88 | + "essentialsVersion": { |
| 89 | + "type": "string" |
| 90 | + }, |
| 91 | + "alertContextVersion": { |
| 92 | + "type": "string" |
| 93 | + } |
| 94 | + } |
| 95 | + }, |
| 96 | + "alertContext": { |
| 97 | + "type": "object", |
| 98 | + "properties": {} |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + ``` |
| 105 | + |
| 106 | +1. Select the **+** icon to insert a new step. |
| 107 | +:::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."::: |
| 108 | + |
| 109 | +1. Send an email or post a Teams message. |
| 110 | + |
| 111 | +## [Send an email](#tab/send-email) |
| 112 | + |
| 113 | +1. In the search field, search for *outlook*. |
| 114 | +1. Select **Office 365 Outlook**. |
| 115 | + :::image type="content" source="./media/alerts-logic-apps/choose-operation-outlook.png" alt-text="A screenshot showing add action page of the logic apps designer with Office 365 Outlook selected."::: |
| 116 | +1. Select **Send an email (V2)** from the list of actions. |
| 117 | +1. Sign into Office 365 when prompted to create a connection. |
| 118 | +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. |
| 119 | +For example: |
| 120 | + - Enter *An alert has monitoring condition:* then select **monitorCondition** from the **Dynamic content** list. |
| 121 | + - Then enter *Date fired:* and select **firedDateTime** from the **Dynamic content** list. |
| 122 | + - Enter *Affected resources:* and select **alterTargetIDs** from the **Dynamic content** list. |
| 123 | + |
| 124 | +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. |
| 125 | +For example: |
| 126 | + - Enter *Alert:* and select **alertRule** from the **Dynamic content** list. |
| 127 | + - Then enter *with severity:* and select **severity** from the **Dynamic content** list. |
| 128 | + - Enter *has condition:* and select **monitorCondition** from the **Dynamic content** list. |
| 129 | + |
| 130 | +1. Enter the email address to send the alert to in the **To** field. |
| 131 | +1. Select **Save**. |
| 132 | + |
| 133 | + :::image type="content" source="./media/alerts-logic-apps/configure-email.png" alt-text="A screenshot showing the parameters tab for the send email action."::: |
| 134 | + |
| 135 | +You've created a Logic App that will send an email to the specified address, with details from the alert that triggered it. |
| 136 | + |
| 137 | +The next step is to create an action group to trigger your Logic App. |
| 138 | + |
| 139 | +## [Post a Teams message](#tab/send-teams-message) |
| 140 | + |
| 141 | +1. In the search field, search for *Microsoft Teams*. |
| 142 | + |
| 143 | +1. Select **Microsoft Teams** |
| 144 | + :::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."::: |
| 145 | +1. Select **Post a message in a chat or channel** from the list of actions. |
| 146 | +1. Sign into Teams when prompted to create a connection. |
| 147 | +1. Select *User* from the **Post as** dropdown. |
| 148 | +1. Select *Group chat* from the **Post in** dropdown. |
| 149 | +1. Select your group from the **Group chat** dropdown. |
| 150 | +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. |
| 151 | + For example: |
| 152 | + - Enter *Alert:* then select **alertRule** from the **Dynamic content** list. |
| 153 | + - Enter *with severity:* and select **severity** from the **Dynamic content** list. |
| 154 | + - Enter *was fired at:* and select **firedDateTime** from the **Dynamic content** list. |
| 155 | + - Add more fields according to your requirements. |
| 156 | +1. Select **Save** |
| 157 | + :::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."::: |
| 158 | + |
| 159 | +You've created a Logic App that will send a Teams message to the specified group, with details from the alert that triggered it. |
| 160 | + |
| 161 | +The next step is to create an action group to trigger your Logic App. |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +## Create an action group |
| 166 | + |
| 167 | +To trigger your Logic app, create an action group, then create an alert that uses that action group. |
| 168 | + |
| 169 | +1. Go to the Azure Monitor page and select **Alerts** from the sidebar. |
| 170 | + |
| 171 | +1. Select **Action groups**, then select **Create**. |
| 172 | +1. Select a **Subscription**, **Resource group** and **Region**. |
| 173 | +1. Enter an **Actions group name** and **Display name**. |
| 174 | +1. Select the **Actions** tab. |
| 175 | +:::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."::: |
| 176 | +1. In the **Actions** tab under **Action type**, select **Logic App**. |
| 177 | +1. In the **Logic App** section, select your logic app from the dropdown. |
| 178 | +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). |
| 179 | +1. Select **OK**. |
| 180 | +1. Enter a name in the **Name** field. |
| 181 | +1. Select **Review + create**, the **Create**. |
| 182 | +:::image type="content" source="./media/alerts-logic-apps/create-action-group-actions.png" alt-text="A screenshot showing the Logic Apps blade of a create action group, actions tab."::: |
| 183 | + |
| 184 | +## Test your action group |
| 185 | + |
| 186 | +1. Select your action group. |
| 187 | +1. In the **Logic App** section, select **Test action group(preview)**. |
| 188 | +:::image type="content" source="./media/alerts-logic-apps/test-action-group1.png" alt-text="A screenshot showing an action group details page with test action group highlighted."::: |
| 189 | +1. Select a **Sample alert type** from the dropdown. |
| 190 | +1. Select **Test**. |
| 191 | + |
| 192 | +:::image type="content" source="./media/alerts-logic-apps/test-action-group2.png" alt-text="A screenshot showing an action group details test page."::: |
| 193 | + |
| 194 | +The following email will be sent to the specified account: |
| 195 | + |
| 196 | +:::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."::: |
| 197 | + |
| 198 | + |
| 199 | +## Create a rule using your action group |
| 200 | + |
| 201 | +1. [Create a rule](./alerts-create-new-alert-rule.md) for one of your resources. |
| 202 | + |
| 203 | +1. In the actions section of your rule, select **Select action groups**. |
| 204 | +1. Select your action group from the list. |
| 205 | +1. Select **Select**. |
| 206 | +1. Finish the creation of your rule. |
| 207 | + :::image type="content" source="./media/alerts-logic-apps/select-action-groups.png" alt-text="A screenshot showing the actions tab of the create rules page and the select action groups blade."::: |
| 208 | + |
| 209 | +## Next steps |
| 210 | + |
| 211 | +* [Learn more about action groups](./action-groups.md). |
| 212 | +* [Learn more about the common alert schema](./alerts-common-schema.md). |
0 commit comments