Sending Microsoft Teams Alerts in Grafana
Prerequisites
Before setting up Microsoft Teams alerts, ensure the following:
- You have access to a Microsoft Teams channel where alerts will be sent.
- You have the permission to configure an incoming webhook in Microsoft Teams.
Step 1: Set Up an Incoming Webhook in Microsoft Teams
- Open Microsoft Teams and navigate to the Team where you want to send alerts.
- Go to the Channel where alerts will be sent and click the three dots (...) next to the channel name.
- Select Connectors from the dropdown.
- Search for Incoming Webhook and click Configure.
- Provide a name for the webhook (e.g.,
Grafana Alerts). - Optionally, upload an image to use as the webhook icon.
- 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
- Log in to your Grafana instance.
- Navigate to Alerting > Notification channels.
- Click New Notification Channel and choose Webhook.
- 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 }}"
}
- Name: Provide a name (e.g.,
- Click Test to send a test notification to the Microsoft Teams channel.
- Save the notification channel.
Step 3: Create an Alert Rule
- Go to a Grafana dashboard and click Edit for a panel.
- Switch to the Alert tab and click Create Alert.
- Configure the alert:
- Define the conditions (e.g., metric thresholds, evaluation frequency, duration).
- Add the Microsoft Teams notification channel created earlier.
- Save the changes.
Step 4: Verify Alerts
- Trigger the alert condition (e.g., exceed a threshold).
- 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
}
]
}
}
]
}