Send Azure Infrastructure Alerts to Microsoft Teams!

Ajinkya Bhabal
FAUN — Developer Community 🐾
4 min readMay 15, 2022

--

Introduction

Today, we’ll be looking at how to get Azure alerts in the Microsoft teams channel, which will help us reduce email overload and provide a centralized location where all team members can watch alerts and take action according to them.

Here we’ll be using the Logic app to post a message in the Teams channel, as it contains a built-in Microsoft teams Connector and with it’s consumption based capability we would have the pay-per-use model.

In the following scenario, I have taken the Azure Redis resource on which alerts have been configured.

Let’s Understand the Azure Redis Alert configuration and its components.

  • First, we have defined the base resource of the Azure logic app.
  • Then the Workflow configuration is specified in ARM Template and the reason is it’s still a complex configuration in terraform and even if the API Connection resource was released recently, It's very difficult to work within the logic app structure.
  • The best thing is with help of “azurerm_resource_group_template_deployment” Resource Terraform manages the ARM deployed resources also.
  • Creating a New Action Group where Logic app callback URL is configured in Webhook.
  • Following alerts have been configured
    - Azure Redis CPU Usage Threshold reaches above 90%
    - Azure Redis Memory Usage Threshold reaches above 90%
    - Azure Logic App Runs failed

Now let's take a look at the Workflow configuration which is written in the ARM Template.

  • First, API Connection for Teams has been configured. Here I have created one account in the Office admin portal with access to the Microsoft teams app that will post messages as the service account. After deploying Resources we have to manually authenticate with that account.
  • The Default HTTP Trigger has been configured, The Callback URL generated from which will be utilized by the Alert Action group to notify the logic app about the alert triggered.
  • With this, our logic app can parse, consume and pass along the data from the HTTP request through the trigger into our workflow.
  • From the result of the above trigger, we will check whether the alert status has been activated or not. Based on that condition would be set up.
  • Then in the If section we will add the “Post a Message in teams chat” action and write a custom message about the triggered alert with all of it’s detail and in a similar way else section will add the “Post a Message in teams chat” action and write a custom message about the alert resolved.
  • From the terraform we will provide input for Microsoft Teams Id and Microsoft Teams Channel Id.
    - To get the above values we need to go to “Get a link to the team”.
    - e.g. Microsoft Teams Channel ID — 19%3aKsrELenmjB3PYM6jgWbk9nu5J_e191NOoZoIC9vwHbk1%40thread.tacv2
    - Microsoft Teams ID — groupId=4dbebb37-c017–4483-aa8b-26d4a01b4de8

Complete Terraform Code available here —

To perform a stress test on Redis Instance “Redis-benchmark” tool is used here.

To test things out, I have reduced the threshold value to 5% to quickly get an alert from the Redis instance.

Now we will start the stress test on the Redis instance with the following command.

The alert is triggered for CPU usage, let’s take a look at it.

On our Microsoft Teams channel, we will get a notification about alert triggered for Azure Redis Resource.

After successfully remediation action is performed on the instance we will get notified about the alert has been resolved.

If you’d like to read more about IaaC tools and Azure Cloud topics, Just let me know in the comments. Thanks for reading!

You can connect me on #LinkedIn

Join FAUN: Website 💻|Podcast 🎙️|Twitter 🐦|Facebook 👥|Instagram 📷|Facebook Group 🗣️|Linkedin Group 💬| Slack 📱|Cloud Native News 📰|More.

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇

--

--