Skip to content

Notifications from Microsoft Azure on MS Teams

Alerts from MS Azure to Teams

Microsoft Azure platform can be very easily and quickly integrated with Microsoft Teams and thanks to this we can receive notifications and alerts directly on the messenger. A good example is setting up to receive alerts when there are problems with Virtual Machines. We may receive a notification if a user turns off our VM, or if a problem is detected on the Microsoft Azure platform.

How can this be done? How to set up such notifications? I will demonstrate an example in which the ‘Resource Health’ function will notify us about it in the Teams application using the ‘Logic App’. More specifically, an alert is generated from the event and then sent to the action group that will call the Logic App. Logic App will receive the alert and send it as a message on the channel in Teams.

I have been testing the solution for some time and I must admit that it is extra. If you ask about the costs, they are practically invisible in my case below $1. The exact price list can be found on the Microsoft website: https://azure.microsoft.com/en-us/pricing/details/logic-apps/.

Logic App

First, we’ll build an alert relay application. The ‘Logic App’ application. As I wrote earlier, it will have the task of receiving the alert and forwarding it to the Teams messenger. The application will be launched only when an alert is triggered.

To create Azure LogicApp, log in to the portal and select ‘+ Add’.

Azure logic App

We select a subscription, resource group and give the name of our application. We select the location ‘Region’ and choose the region, in my case ‘West Europe’. I also recommend that you enter tags, although it is not mandatory. Once done, we can click ‘Review + create’.

Azure create logic App

When the Logic App is created, go to the resource. We select ‘When a HTTP request is received‘.

Azure logic App - chose 'When a HTTP'

Now click on ‘Use sample payload to generate schema‘ and paste the following piece of code:

{
    "schemaId": "Microsoft.Insights/activityLogs",
    "data": {
        "status": "Activated",
        "context": {
            "activityLog": {
                "channels": "Test",
                "correlationId": "7032f77b-bf3a-4c70-6585-12db6d9a3der",
                "description": "…",
                "eventSource": "ResourceHealth",
                "eventTimestamp": "2020-09-09T22:44:43.7467716+00:00",
                "eventDataId": "rrdb3ebe-b6af-4920-adb7-13d43514db0d",
                "level": "Critical",
                "operationName": "Microsoft.Resourcehealth/healthevent/Activated/action",
                "operationId": "e126as3c-8874-4ec8-ba2b-57e3c92a56d2",
                "properties": {
                    "title": "...",
                    "details": "...",
                    "currentHealthStatus": "Degraded",
                    "previousHealthStatus": "Available",
                    "type": "Downtime",
                    "cause": "PlatformInitiated"
                },
                "status": "Active",
                "subscriptionId": "...",
                "submissionTimestamp": "2020-09-09T22:44:50.8013523+00:00"
            }
        },
        "properties": {}
    }
}

When the diagram is generated, add a new step ‘+ New step‘.

Logic App - When a HTTP request is received

We search for Microsoft Teams and select ‘Post a message (V3) (preview)’. Now we can login to our Teams.

Azure Microsoft Teams - post a message

After logging in, select the team and channel in which we want to publish alerts. After clicking on Message, we enter plain text and select the parameters that interest us from the ‘dynamic content‘, for example:

Azure Microsoft Teams - post a message configuration
Azure Microsoft Teams - post a message configuration dynamic content

For me, the whole thing looks more or less like in the example below. By the way, I encourage you to experiment, because it is not a perfect solution. There is too much data in the message and it would be nice to tweak the code and restrict it to make it more readable. As of today, it is enough for me, and when I introduce corrections, I will try to update the article;) When we choose the parameters that interest us, click ‘Save’.

Azure Microsoft Teams - post a message configuration dynamic content(full))

Resource Health

Now we go to the resource that we want to monitor, for example to a virtual machine. Go to the ‘Support + troubleshooting’ section, select ‘Resource health’ and click on ‘+ Add resource health alert’.

Azure resource health

We choose the subscription, resource type, resource group and finally the resources to be alerted to. It is worth checking the ‘Include all future resources’ option, which will allow you to automatically add new resources to the alert if we create one.

Azure resource health add

Alert conditions

Azure resource health add

In this part, I chose to receive notifications for:

  • Event status: Active, In Progress, Updated
  • Current resource status: Degraded, Unavailable, Unknown
  • Previous resource status: all
  • Reason type: Platform Initiated, User Initiated

If you do not want to receive notifications triggered by users, simply uncheck ‘Reason type: User Initiated’ so that only the ‘Platform Initiated‘ option is selected.

Actions

If we do not have any group created in this section, it should be created by clicking on ‘Select action group‘ and ‘+ Create action group‘ respectively.

Azure resource health add

We choose a subscription and give a name for our ‘action group’. We can skip the ‘Notifications’ tab and go straight to Actions where we choose Logic App and our previously created application.

Azure create action group

Alert rule details

After creating the ‘action group’, we give the name of the rule and we can enter an additional description.

Azure resource health add

End. If we have correctly created the ‘Logic App‘ and the alert for ‘Resource health‘, we will see the result of our actions on the selected channel in Teams, for example after restarting the virtual machine which the alert concerns. The channel message should look similar to the image below. As I wrote earlier, it is worth specifying the information that is to appear in order not to receive such long messages.

teams logic app message
teams logic app 2 message

If you liked the post on receiving notifications from Microsoft Azure directly in Teams then check out other Azure related articles in the azure category.

4 thoughts on “Notifications from Microsoft Azure on MS Teams”

    1. Yes, you can use the ‘Slack’ app instead of Microsoft Teams. You do all the steps in the same way, only when adding a new step after ‘When a HTTP request is received’ you search for ‘Slack‘ instead of Teams. It is definitely available because I checked and you choose the ‘post message’. The rest should be the same.

  1. Hi Wojciech, looks like my alerts are not rendered properly in Teams, https://i.ibb.co/kgSt7Vx/Capture.png
    What I have done differently was tick the “Enable the common alert schema” when creating the Action Group (as seen in other tutorials). I shouldn’t have done that?

    1. If you did everything according to my tutorial, it should be ok.
      First, check if you created the schema correctly.
      It is also possible that you have chosen wrong dynamic content that doesn’t exist and therefore is an empty message.

Comments are closed.