Skip to content

Commit 3cf9076

Browse files
authored
Discord as OCP alert receiver (#124)
This short article describe how to configure OpenShift Alertmanager to sent alerts to a discord channel.
1 parent f0ac0db commit 3cf9076

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
layout: post
3+
title: Discord as OpenShift alert receiver
4+
subtitle: How to configure discord as a receiver for alertmanager
5+
tags: [openshift, prometheus, alertmanager, discord, receiver, shorts, k8s]
6+
author: cmeissner
7+
---
8+
9+
Having alerts sent to a channel like Slack, E-Mail or Pagerduty is easy configured in OpenShift.
10+
11+
![Alertmanager receiver types](/assets/img/alertmanager_receiver_types.png)
12+
13+
Although there is an option to configure a webhook as a receiver type, it is not possible to use this for a discord webhook.
14+
15+
## Setup Discord
16+
17+
To use Discord as an alert target, you need to create an own instance. In that instance, you create a webhook as followed.
18+
19+
- Open `Server Settings``Integrations``Webhooks`
20+
- Click `New Webhook`
21+
- To configure the webhook you have to click on the angle bracket
22+
23+
![Discord webhook configuration](/assets/img/discord_webhook_configuration.png)
24+
25+
Here you can set the `Name` of the Bot and the `Channel` where the messages should be sent to
26+
- `Copy Webhook URL` by clicking the button of the same name
27+
28+
## Setup Alertmanager Receiver
29+
30+
As it is not possible yet to configure discord as a receiver type, you need to configure it in the YAML view in the Web UI or directly via console as followed.
31+
32+
- Export the existing configuration
33+
34+
```shell
35+
$ oc -n openshift-monitoring extract secret/alertmanager-main --keys=alertmanager.yaml
36+
alertmanager.yaml
37+
```
38+
39+
This will create a file `alertmanager.yaml`, which is used for the next step of configuration.
40+
41+
- Add a discord receiver type to your receivers
42+
43+
```yaml
44+
receivers:
45+
- name: default
46+
discord_configs:
47+
- webhook_url: >-
48+
<Webhook URL>
49+
- name: Watchdog
50+
```
51+
52+
Replace `<Webhook URL>` with the one you copied in while creating the webhook in the step before.
53+
54+
- Update your alertmanager configuration
55+
56+
```shell
57+
oc -n openshift-monitoring create secret generic alertmanager-main --from-file=alertmanager.yaml --dry-run=client -o=yaml | oc -n openshift-monitoring replace secret --filename=-
58+
```
59+
60+
The `alertmanager-main-0` pod will recognize the change of the `alertmanager.yaml` and reload the configuration.
61+
62+
You can monitor if the configuration was reloaded by observing the logs of the pod
63+
64+
```shell
65+
$ oc -n openshift-monitoring logs -f alertmanager-main-0
66+
ts=2023-12-27T17:51:43.531Z caller=coordinator.go:113 level=info component=configuration msg="Loading configuration file" file=/etc/alertmanager/config_out/alertmanager.env.yaml
67+
ts=2023-12-27T17:51:43.531Z caller=coordinator.go:126 level=info component=configuration msg="Completed loading of configuration file" file=/etc/alertmanager/config_out/alertmanager.env.yaml
68+
```
37.8 KB
Loading
78.5 KB
Loading

0 commit comments

Comments
 (0)