Skip to main content

Sending Microsoft Teams Alerts in Grafana

Prerequisites

Before setting up Microsoft Teams alerts, ensure the following:

  1. You have access to a Microsoft Teams channel where alerts will be sent.
  2. You have the permission to configure an incoming webhook in Microsoft Teams.

Step 1: Set Up an Incoming Webhook in Microsoft Teams

  1. Open Microsoft Teams and navigate to the Team where you want to send alerts.
  2. Go to the Channel where alerts will be sent and click the three dots (...) next to the channel name.
  3. Select Connectors from the dropdown.
  4. Search for Incoming Webhook and click Configure.
  5. Provide a name for the webhook (e.g., Grafana Alerts).
  6. Optionally, upload an image to use as the webhook icon.
  7. Click Create, and you’ll receive a Webhook URL. Copy this URL as you’ll need it in Grafana.

Step 2: Configure Microsoft Teams Notification Channel in Grafana

  1. Log in to your Grafana instance.
  2. Navigate to Alerting > Notification channels.
  3. Click New Notification Channel and choose Webhook.
  4. Fill in the following details:
    • Name: Provide a name (e.g., Microsoft Teams Alerts).
    • URL: Paste the webhook URL from Step 1.
    • HTTP Method: Set it to POST.
    • Custom Headers: Add the following header:
      Content-Type: application/json
    • Message: Customize the message payload to ensure compatibility with Microsoft Teams. For example:
      {
      "text": "Grafana Alert: {{ .Title }}\n{{ .Message }}"
      }
  5. Click Test to send a test notification to the Microsoft Teams channel.
  6. Save the notification channel.

Step 3: Create an Alert Rule

  1. Go to a Grafana dashboard and click Edit for a panel.
  2. Switch to the Alert tab and click Create Alert.
  3. Configure the alert:
    • Define the conditions (e.g., metric thresholds, evaluation frequency, duration).
    • Add the Microsoft Teams notification channel created earlier.
  4. Save the changes.

Step 4: Verify Alerts

  1. Trigger the alert condition (e.g., exceed a threshold).
  2. Check the Microsoft Teams channel to verify the alert message.

Diagram: Microsoft Teams Alert Workflow in Grafana


Advanced: Customizing Alert Messages

Microsoft Teams supports adaptive cards for richer messages. You can modify the JSON payload in the notification channel to use an adaptive card format. Example:

{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"version": "1.4",
"body": [
{
"type": "TextBlock",
"text": "Grafana Alert: {{ .Title }}",
"weight": "Bolder",
"size": "Medium"
},
{
"type": "TextBlock",
"text": "{{ .Message }}",
"wrap": true
}
]
}
}
]
}