Teams workflow | M/Monit | Troubleshooting | Monit
M/Monit comes with a pre-defined Teams Alert service which posts alerts to a Microsoft Teams channel through a Teams Workflow. You need a Microsoft 365 work or school account that may create Workflows (the free personal Teams cannot). This guide takes about 10 minutes. See Alert Services for how Alert Services work in general.

M/Monit 4.5.0 and later send the alert as an Adaptive Card. Earlier versions sent a MessageCard; workflows made from the template below post both.
Note: a workflow URL is about 300 characters long. M/Monit before 4.5.0 accepts at most 255 characters in URL/Endpoint and cannot save it (endpoint: Input too long); upgrade to 4.5.0.
Note: Microsoft has retired the Office 365 connectors (Incoming Webhook) in Teams. URLs of the form https://....webhook.office.com/webhookb2/... no longer work; create a Workflow as below instead.
1. Create a Teams workflow
- In Teams, open the channel for the alerts, click ... next to the channel name and choose Workflows.
- Search for webhook and select the template Send webhook alerts to a channel (not ... from people in your org, which accepts only signed-in callers).
- Check the team and channel and click Save.
- Click Copy webhook link. (The link is not shown, only copied.)
The URL contains its own secret: anyone with it can post to the channel. If the Workflows entry or the template is missing, ask your Microsoft 365 administrator to allow Workflows (Power Automate) for your account.
2. Configure M/Monit
- In M/Monit go to Admin -> Alerts -> Alert Service and open the Teams Alert row with the arrow on the right.
- URL/Endpoint: the HTTP POST URL of the workflow.
- API Key/Token: leave empty.
- Press Test Service. M/Monit shows Test message successfully sent and, a few seconds later, the test alert appears in the channel, posted by Workflows.
- Press Update.

Then use the service in an alert rule: on the Rules tab choose the action Execute Service and Teams Alert, save the rule and switch it on. See Alert Services.
Troubleshooting
A workflow accepts the request first (HTTP 202) and posts the message afterwards. So an exit status 0 means that Teams received the alert, not that it was posted. If nothing appears in the channel, open the workflow in Power Automate -> My flows and look at its run history: a failed run shows the reason.
| Answer | Meaning |
|---|---|
| AuthorizationFailed (HTTP 401) | The URL is incomplete or its sig parameter is wrong. Copy the link again. |
| HTTP 404 | The workflow was deleted or turned off. |
| HTTP 429 | Too many requests; Power Automate throttles the workflow. |
Monit
Without M/Monit, Monit can run the same script with exec. Save it as, for instance, /usr/local/etc/monit/teams-alert.sh, fill in the workflow URL at the top and make it readable only for the user that runs Monit (chmod 700):
#!/bin/sh
# M/Monit 4.5.0 "Teams Alert" script, for Monit's exec
ENDPOINT="https://your-workflow-http-post-url" # HTTP POST URL of the Teams workflow
# Monit passes the event values as they are; M/Monit escapes them for the message (JSON): do the same here
_nl='
'
_replace() {
_r= _t=$1
while :; do
case $_t in
*"$2"*) _r=$_r${_t%%"$2"*}$3; _t=${_t#*"$2"} ;;
*) break ;;
esac
done
printf '%s' "$_r$_t"
}
_json_escape() {
_s=$(printf '%s' "$1" | tr -d '\000-\010\013\014\016-\037')
_s=$(_replace "$_s" '\' '\\')
_s=$(_replace "$_s" '"' '\"')
_s=$(_replace "$_s" "$_nl" '\n')
_s=$(_replace "$_s" "$(printf '\r')" '\r')
_replace "$_s" "$(printf '\t')" '\t'
}
MONIT_HOST=$(_json_escape "$MONIT_HOST")
MONIT_SERVICE=$(_json_escape "$MONIT_SERVICE")
MONIT_DESCRIPTION=$(_json_escape "$MONIT_DESCRIPTION")
# Generate the Teams message payload: an Adaptive Card for the Teams Workflow
generate_payload() {
printf '{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.4",
"msteams": { "width": "Full" },
"body": [
{ "type": "TextBlock", "text": "M/Monit Alert", "size": "Medium", "weight": "Bolder", "color": "Attention" },
{ "type": "TextBlock", "text": "%s on %s", "wrap": true, "spacing": "None" },
{
"type": "FactSet",
"facts": [
{ "title": "Date", "value": "%s" },
{ "title": "Host", "value": "%s" },
{ "title": "Service", "value": "%s" },
{ "title": "Action", "value": "%s" },
{ "title": "Event", "value": "%s" },
{ "title": "Description", "value": "%s" }
]
}
]
}
}
]
}' "$MONIT_EVENT" "$MONIT_HOST" "$MONIT_DATE" "$MONIT_HOST" "$MONIT_SERVICE" "$MONIT_ACTION" "$MONIT_EVENT" "$MONIT_DESCRIPTION"
}
# Generate and send the payload
payload=$(generate_payload)
response=$(curl -sS -w "%{http_code}" -H "Content-Type: application/json" -d "$payload" "$ENDPOINT") || exit
code=${response#"${response%???}"}
body=${response%???}
[ -n "$body" ] && printf "%s\n" "$body"
case "$code" in
2??) ;;
*) echo "HTTP status $code" >&2; exit 1 ;;
esac
case "$body" in
*"Microsoft Teams endpoint returned HTTP error"*) exit 1 ;;
esac
Then call it from any check in the Monit control file, for failure and recovery:
check host www.example.com with address www.example.com
if failed port 443 protocol https
then exec "/usr/local/etc/monit/teams-alert.sh"
else if succeeded then exec "/usr/local/etc/monit/teams-alert.sh"