Skip to content

Commit 2674654

Browse files
authored
Add message template to article (#125)
As Discord API has a strict message size limit it is needed to limit the size with a custom message template. With this template we reduce the message body to the bare minimum.
1 parent d0d951e commit 2674654

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

_posts/2023-12-28-discord_as_alertmanager_receiver.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ title: Discord as OpenShift alert receiver
44
subtitle: How to configure discord as a receiver for alertmanager
55
tags: [openshift, prometheus, alertmanager, discord, receiver, shorts, k8s]
66
author: cmeissner
7+
last-updated: 2024-10-15
78
---
89

910
Having alerts sent to a channel like Slack, E-Mail or Pagerduty is easy configured in OpenShift.
@@ -51,6 +52,40 @@ As it is not possible yet to configure discord as a receiver type, you need to c
5152
5253
Replace `<Webhook URL>` with the one you copied in while creating the webhook in the step before.
5354

55+
- Add message template
56+
57+
We define a message template for `discord_configs`.
58+
59+
{% raw %}
60+
61+
```yaml
62+
receivers:
63+
- name: default
64+
discord_configs:
65+
- webhook_url: >-
66+
<Webhook URL>
67+
message: |-
68+
{{ range .Alerts.Firing }}
69+
Alert: **{{ printf "%.150s" .Annotations.summary }}** ({{ .Labels.severity }})
70+
Description: {{ printf "%.150s" .Annotations.description }}
71+
Alertname: {{ .Labels.alertname }}
72+
Namespace: {{ .Labels.namespace }}
73+
Service: {{ .Labels.service }}
74+
{{ end }}
75+
76+
{{ range .Alerts.Resolved }}
77+
Alert: **{{ printf "%.150s" .Annotations.summary }}** ({{ .Labels.severity }})
78+
Description: {{ printf "%.150s" .Annotations.description }}
79+
Alertname: {{ .Labels.alertname }}
80+
Namespace: {{ .Labels.namespace }}
81+
Service: {{ .Labels.service }}
82+
{{ end }}
83+
```
84+
85+
{% endraw %}
86+
87+
This template is needed as the Discord API has a message size limit which will return an error 400 if the message send is to long. Reaching this limit is not that difficult for Prometheus alerts, so we reduced the message size to the bare minimum.
88+
5489
- Update your alertmanager configuration
5590

5691
```shell

0 commit comments

Comments
 (0)