Discord webhook : Cannot send an empty message
lazbord opened this issue · 4 comments
What did you do?
I tried to triggered my discord webhook when an alert is firing.
I tested my discord webhook with curl and it work just fine :
curl -X POST -H "Content-Type: application/json" -d '{"content": "Another test!"}' https://discord.com/api/webhooks/discordwebhooktoken
Prometheus and Alermanager do recognize the alert :
Everything seemed to work but i don't have any messages in my discord channel when an alert is firing.
Here is the log from alertmanager :
`Jul 19 12:54:37 CT-Monitoring alertmanager[3075]: ts=2024-07-19T12:54:37.265Z caller=dispatch.go:353 level=error component=dispatcher msg="Notify for alerts failed" num_alerts=1 err="discord_webhook/webhook[0]: notify retry canceled due to unrecoverable error after 1 attempts: unexpected status code 400: https://discordapp.com/api/webhooks/mywebhooktoken: {\"message\": \"Cannot send an empty message\", \"code\": 50006}"`
I have tried to resolve this issue by specifying template that specifies a message but it doesn't change a thing.
I'm a newbie so maybe I miss something out, but I believe I have done everything correctly...
-
Alertmanager version:
version=0.27.0
-
Prometheus version:
version=2.52.0-rc.1
-
Alertmanager configuration file:
route:
group_by: ['alertname']
group_wait: 30s
group_interval: 5m
repeat_interval: 1h
receiver: 'discord_webhook'
receivers:
- name: 'discord_webhook'
webhook_configs:
- url: 'https://discordapp.com/api/webhooks/1247133913369940038/discordwebhooktoken'
- Prometheus configuration file:
global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
- "alert_rules.yml"
alerting:
alertmanagers:
- static_configs:
- targets:
- 'localhost:9093'
*alert-rules.yml :
groups:
- name: alerts
rules:
- alert: NodeExporterDown
expr: up == 0
for: 5s
labels:
severity: critical
annotations:
summary: "NodeExporter on {{ $labels.instance }} is down"
description: "NodeExporter on {{ $labels.instance }} has been down for more than 5 seconds."
How did you made it works
In Alertmanager config file, you have to group by alertname AND job, like so :
route:
group_by: ['alertname','job']
group_wait: 30s
group_interval: 5m
repeat_interval: 1h
receiver: 'discord_webhook'
receivers:
- name: 'discord_webhook'
webhook_configs:
- url: 'https://discordapp.com/api/webhooks/1247133913369940038/discordwebhooktoken'
are you sure, bec. i did have the same config as you mentioned but didn't work for me
however the solution for me was running 1 more container for the discord integration
for more.
https://github.com/evanugarte/prometheus-monitoring-tutorial
https://github.com/benjojo/alertmanager-discord
discord-alerts:
image: benjojo/alertmanager-discord
container_name: discord-alerts
restart: unless-stopped
environment:
DISCORD_WEBHOOK: <discord_hook>
ports:
- "9094:9094"
Honestly, since the problem was resolved, I haven't touched a single config file. Good thing if your solution works!