Customize alert notifications using Logic Apps

This article shows you how to create a Logic App and integrate it with an Azure Monitor Alert.

Azure Logic Apps allows you to build and customize workflows for integration. Use Logic Apps to customize your alert notifications.

  • Customize the alerts email, using your own email subject and body format.
  • Customize the alert metadata by looking up tags for affected resources or fetching a log query search result.
  • Integrate with external services using existing connectors like Outlook, Microsoft Teams, Slack and PagerDuty, or by configuring the Logic App for your own services.

In this example, we'll use the following steps to create a Logic App that uses the common alerts schema to send details from the alert. The example uses the following steps:

  1. Create a Logic App for sending an email or a Teams post.
  2. Create an alert action group that triggers the logic app.
  3. Create a rule the uses the action group.

Create a Logic App

  1. Create a new Logic app. Set Logic App name , select Consumption Plan type.

  2. Select Review + create, then select Create.

  3. Select Go to resource when the deployment is complete. A screenshot showing the create logic app page.

  4. On the Logic Apps Designer page, select When a HTTP request is received.
    A screenshot showing the Logic Apps designer start page.

  5. Paste the common alert schema into the Request Body JSON Schema field from the following JSON:

     {
        "type": "object",
        "properties": {
            "schemaId": {
                "type": "string"
            },
            "data": {
                "type": "object",
                "properties": {
                    "essentials": {
                        "type": "object",
                        "properties": {
                            "alertId": {
                                "type": "string"
                            },
                            "alertRule": {
                                "type": "string"
                            },
                            "severity": {
                                "type": "string"
                            },
                            "signalType": {
                                "type": "string"
                            },
                            "monitorCondition": {
                                "type": "string"
                            },
                            "monitoringService": {
                                "type": "string"
                            },
                            "alertTargetIDs": {
                                "type": "array",
                                "items": {
                                    "type": "string"
                                }
                            },
                            "originAlertId": {
                                "type": "string"
                            },
                            "firedDateTime": {
                                "type": "string"
                            },
                            "resolvedDateTime": {
                                "type": "string"
                            },
                            "description": {
                                "type": "string"
                            },
                            "essentialsVersion": {
                                "type": "string"
                            },
                            "alertContextVersion": {
                                "type": "string"
                            }
                        }
                    },
                    "alertContext": {
                        "type": "object",
                        "properties": {}
                    }
                }
            }
        }
    }
    
  6. Select the + icon to insert a new step. A screenshot showing the parameters for the when http request received step.

  7. Send an email or post a Teams message.

  1. In the search field, search for outlook.

  2. Select Office 365 Outlook. A screenshot showing add action page of the logic apps designer with Office 365 Outlook selected.

  3. Select Send an email (V2) from the list of actions.

  4. Sign into Office 365 when prompted to create a connection.

  5. Create the email Body by entering static text and including content taken from the alert payload by choosing fields from the Dynamic content list.
    For example:

    • Enter An alert has monitoring condition: then select monitorCondition from the Dynamic content list.
    • Then enter Date fired: and select firedDateTime from the Dynamic content list.
    • Enter Affected resources: and select alterTargetIDs from the Dynamic content list.
  6. 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.
    For example:

    • Enter Alert: and select alertRule from the Dynamic content list.
    • Then enter with severity: and select severity from the Dynamic content list.
    • Enter has condition: and select monitorCondition from the Dynamic content list.
  7. Enter the email address to send the alert to in the To field.

  8. Select Save.

    A screenshot showing the parameters tab for the send email action.

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

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

Create an action group

To trigger your Logic app, create an action group, then create an alert that uses that action group.

  1. Go to the Azure Monitor page and select Alerts from the sidebar.

  2. Select Action groups, then select Create.

  3. Select a Subscription, Resource group and Region.

  4. Enter an Actions group name and Display name.

  5. Select the Actions tab. A screenshot showing the actions tab of a create action group page.

  6. In the Actions tab under Action type, select Logic App.

  7. In the Logic App section, select your logic app from the dropdown.

  8. 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.

  9. Select OK.

  10. Enter a name in the Name field.

  11. Select Review + create, the Create. A screenshot showing the Logic Apps pane of a create action group, actions tab.

Test your action group

  1. Select your action group.
  2. In the Logic App section, select Test action group(preview). A screenshot showing an action group details page with test action group highlighted.
  3. Select a Sample alert type from the dropdown.
  4. Select Test.

A screenshot showing an action group details test page.

The following email will be sent to the specified account:

A screenshot showing an sample email sent by the test page.

Create a rule using your action group

  1. Create a rule for one of your resources.

  2. In the actions section of your rule, select Select action groups.

  3. Select your action group from the list.

  4. Select Select.

  5. Finish the creation of your rule. A screenshot showing the actions tab of the create rules page and the select action groups pane.

Next steps