Tuesday, January 07, 2020

Data Platform Tips 41 - Push Alerts to MS Teams using Logic Apps and Azure Alerts

Webhooks are executable commands sent from one app to another over HTTP. For e.g. when an event happens and other applications needs to be notified a webhook can be used which is similar to an API.

In this post we will look at when an alert is triggered in Azure how to send the alert to Microsoft Teams using Logic Apps.

Pre-requisites

a) Create a new teams site named "Azure Alerts"

























b) Create a channel named "Alerts".




















Configure the Alert Rule and Logic App


a) Logon to the Azure Portal.

b) Provision an Azure SQL Database and click on "Alerts" under "Montoring" and click "New alert rule".













c) Select the resource group and the appropriate resource and in this case it's the Azure SQL Database you provisioned.














d) Create the condition for the alert in this case to raise an alert if the avg. DTU is greater than 85%.














e) Create a new Action group with the Action Type as LogicApp.

























f) Open another tab and navigate to the Azure Portal and create a new LogicApp within the same resource as the Azure SQL Database.











g) Provide the below as Request Body JSON schema for the Azure Alerts.













{
    "type": "object",
    "properties": {
        "schemaId": {
            "type": "string"
        },
        "data": {
            "type": "object",
            "properties": {
                "status": {
                    "type": "string"
                },
                "context": {
                    "type": "object",
                    "properties": {
                        "activityLog": {
                            "type": "object",
                            "properties": {
                                "authorization": {
                                    "type": "object",
                                    "properties": {
                                        "action": {
                                            "type": "string"
                                        },
                                        "scope": {
                                            "type": "string"
                                        }
                                    }
                                },
                                "channels": {
                                    "type": "string"
                                },
                                "claims": {
                                    "type": "string"
                                },
                                "caller": {
                                    "type": "string"
                                },
                                "correlationId": {
                                    "type": "string"
                                },
                                "description": {
                                    "type": "string"
                                },
                                "eventSource": {
                                    "type": "string"
                                },
                                "eventTimestamp": {
                                    "type": "string"
                                },
                                "eventDataId": {
                                    "type": "string"
                                },
                                "level": {
                                    "type": "string"
                                },
                                "operationName": {
                                    "type": "string"
                                },
                                "operationId": {
                                    "type": "string"
                                },
                                "resourceId": {
                                    "type": "string"
                                },
                                "resourceGroupName": {
                                    "type": "string"
                                },
                                "resourceProviderName": {
                                    "type": "string"
                                },
                                "status": {
                                    "type": "string"
                                },
                                "subStatus": {
                                    "type": "string"
                                },
                                "subscriptionId": {
                                    "type": "string"
                                },
                                "submissionTimestamp": {
                                    "type": "string"
                                },
                                "resourceType": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                },
                "properties": {
                    "type": "object",
                    "properties": {}
                }
            }
        }
    }
}

h) Once the payload is added then add another step and select "Teams" as action.





















i) Sign into Teams and select the Team name and the Channel name and also configure the message with a combination of static and dynamic content.
























j) Now go back to the Action group configuration of your alert rule and select the newly created LogicApp and complete the creation of the Alert rule.










































k) If the avg DTU percentage is greater than 85 for more than 5 minutes then a alert will raised and pushed to the Alerts channel in Teams using the Logic App.


No comments:

Post a Comment