|
| 1 | +--- |
| 2 | +title: How to integrate the common alert schema with Logic Apps |
| 3 | +description: Learn how to create a logic app that leverages the common alert schema to handle all your alerts. |
| 4 | +author: anantr |
| 5 | +services: azure-monitor |
| 6 | +ms.service: azure-monitor |
| 7 | +ms.topic: conceptual |
| 8 | +ms.date: 05/27/2019 |
| 9 | +ms.author: anantr |
| 10 | +ms.subservice: alerts |
| 11 | +--- |
| 12 | +# How to integrate the common alert schema with Logic Apps |
| 13 | + |
| 14 | +This article shows you how to create a logic app that leverages the common alert schema to handle all your alerts. |
| 15 | + |
| 16 | +## Overview |
| 17 | + |
| 18 | +The [common alert schema](https://aka.ms/commonAlertSchemaDocs) provides a standardised and extensible JSON schema across all your different alert types. One of the best places to leverage this is through a logic app. You can now have a single logic app that handles all your alerts. The logic app described in this article creates well-defined variables for the ['essential' fields](https://docs.microsoft.com/azure/azure-monitor/platform/alerts-common-schema-definitions#essentials-fields), and also describes how you can handle [alert type]('https://docs.microsoft.com/azure/azure-monitor/platform/alerts-common-schema-definitions#alert-context-fields') specific logic. |
| 19 | + |
| 20 | + |
| 21 | +## Pre-requisites |
| 22 | + |
| 23 | +This article assumes that the reader is familiar with |
| 24 | +* Setting up alert rules ([metric](https://docs.microsoft.com/azure/azure-monitor/platform/alerts-metric), [log](https://docs.microsoft.com/azure/azure-monitor/platform/alerts-log), [activity log](https://docs.microsoft.com/azure/azure-monitor/platform/alerts-activity-log)) |
| 25 | +* Setting up [action groups](https://docs.microsoft.com/azure/azure-monitor/platform/action-groups) |
| 26 | +* Enabling the [common alert schema](https://docs.microsoft.com/azure/azure-monitor/platform/alerts-common-schema#how-do-i-enable-the-common-alert-schema) from within action groups |
| 27 | + |
| 28 | +## Create a logic app leveraging the common alert schema |
| 29 | + |
| 30 | +1. Follow the steps outlined [here](https://docs.microsoft.com/azure/azure-monitor/platform/action-groups-logic-app) to create your logic app. |
| 31 | + |
| 32 | +1. Select the trigger: **When a HTTP request is received**. |
| 33 | + |
| 34 | +  |
| 35 | + |
| 36 | +1. Select **Edit** to change the HTTP request trigger. |
| 37 | + |
| 38 | +  |
| 39 | + |
| 40 | + |
| 41 | +1. Copy and paste the following schema: |
| 42 | + |
| 43 | + ```json |
| 44 | + { |
| 45 | + "type": "object", |
| 46 | + "properties": { |
| 47 | + "schemaId": { |
| 48 | + "type": "string" |
| 49 | + }, |
| 50 | + "data": { |
| 51 | + "type": "object", |
| 52 | + "properties": { |
| 53 | + "essentials": { |
| 54 | + "type": "object", |
| 55 | + "properties": { |
| 56 | + "alertId": { |
| 57 | + "type": "string" |
| 58 | + }, |
| 59 | + "alertRule": { |
| 60 | + "type": "string" |
| 61 | + }, |
| 62 | + "severity": { |
| 63 | + "type": "string" |
| 64 | + }, |
| 65 | + "signalType": { |
| 66 | + "type": "string" |
| 67 | + }, |
| 68 | + "monitorCondition": { |
| 69 | + "type": "string" |
| 70 | + }, |
| 71 | + "monitoringService": { |
| 72 | + "type": "string" |
| 73 | + }, |
| 74 | + "alertTargetIDs": { |
| 75 | + "type": "array", |
| 76 | + "items": { |
| 77 | + "type": "string" |
| 78 | + } |
| 79 | + }, |
| 80 | + "originAlertId": { |
| 81 | + "type": "string" |
| 82 | + }, |
| 83 | + "firedDateTime": { |
| 84 | + "type": "string" |
| 85 | + }, |
| 86 | + "resolvedDateTime": { |
| 87 | + "type": "string" |
| 88 | + }, |
| 89 | + "description": { |
| 90 | + "type": "string" |
| 91 | + }, |
| 92 | + "essentialsVersion": { |
| 93 | + "type": "string" |
| 94 | + }, |
| 95 | + "alertContextVersion": { |
| 96 | + "type": "string" |
| 97 | + } |
| 98 | + } |
| 99 | + }, |
| 100 | + "alertContext": { |
| 101 | + "type": "object", |
| 102 | + "properties": {} |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + ``` |
| 109 | + |
| 110 | +1. Select **+** **New step** and then choose **Add an action**. |
| 111 | + |
| 112 | +  |
| 113 | + |
| 114 | +1. At this stage, you can add a variety of connectors (Microsoft Teams, Slack, Salesforce, etc.) based on your specific business requirements. You can use the 'essential fields' out-of-the-box. |
| 115 | + |
| 116 | +  |
| 117 | + |
| 118 | + Alternatively, you can author conditional logic based on the alert type using the 'Expression' option. |
| 119 | + |
| 120 | +  |
| 121 | + |
| 122 | + The ['monitoringService' field]('https://docs.microsoft.com/azure/azure-monitor/platform/alerts-common-schema-definitions#alert-context-fields') allows you to uniquely identify the alert type, based on which you can create the conditional logic. |
| 123 | + |
| 124 | + |
| 125 | + For example, the below snippet checks if the alert is a Application Insights based log alert, and if so prints the search results. Else, it prints 'NA'. |
| 126 | + |
| 127 | + ```text |
| 128 | + if(equals(triggerBody()?['data']?['essentials']?['monitoringService'],'Application Insights'),triggerBody()?['data']?['alertContext']?['SearchResults'],'NA') |
| 129 | + ``` |
| 130 | + |
| 131 | + You can learn more about writing logic app expressions [here](https://docs.microsoft.com/azure/logic-apps/workflow-definition-language-functions-reference#logical-comparison-functions). |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | +## Next steps |
| 137 | + |
| 138 | +* [Learn more about action groups](../../azure-monitor/platform/action-groups.md). |
| 139 | +* [Learn more about the common alert schema](https://aka.ms/commonAlertSchemaDocs). |
| 140 | + |
0 commit comments