maubot-alertbot/README.md

91 lines
3.2 KiB
Markdown
Raw Normal View History

2022-08-24 18:40:51 +00:00
![Alertbot banner](assets/alertbanner.png)
# Alertbot
This bot uses the webhook functionality of monitoring/alerting solutions like Grafana or Alertmanager to forward alerts to matrix rooms.
2023-04-27 16:43:37 +00:00
This means that you no longer have to use E-Mail or Slack to receive alerts.
2022-08-24 18:40:51 +00:00
2023-04-27 16:43:37 +00:00
You can either [invite](#invite-the-official-instance) an official instance of the bot, or [self-host](#self-host-an-instance) it on your own matrix server.
2022-07-11 10:35:24 +00:00
2023-04-27 16:43:37 +00:00
## Invite the Official Instance
* Create a Matrix room and invite @alertbot:hyteck.de
* Send `!url` to the room. The bot will answer with the webhook URL
* Put the Webhook URL into your monitoring solution (see below)
2023-04-27 16:43:37 +00:00
## Self-host an Instance
2022-07-11 10:35:24 +00:00
**Prerequisites:**
2023-04-27 16:43:37 +00:00
* A Matrix server where you have access to a maubot instance
* Refer to the [docs](https://docs.mau.fi/maubot/usage/setup/index.html) for setting up one
* or use [spantaleev/matrix-docker-ansible-deploy](https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/docs/configuring-playbook-bot-matrix-registration-bot.md) which has built-in maubot support
* An instance of alertmanager or grafana or a similar alerting program that is able to send webhooks
2022-07-11 10:35:24 +00:00
2023-04-27 16:43:37 +00:00
**Build the Bot**
2022-07-11 10:35:24 +00:00
2023-04-27 16:43:37 +00:00
Clone this repository and build it into a maubot plugin file (.mbp). Navigate to the Maubot Administration Interface and upload the .mpb file.
2022-07-11 10:35:24 +00:00
```shell
git clone https://github.com/moan0s/alertbot
2022-08-24 18:45:57 +00:00
cd alertbot
2022-07-11 10:35:24 +00:00
pip install maubot
2023-04-27 16:43:37 +00:00
mbc build
2022-07-11 10:35:24 +00:00
```
2023-04-27 16:43:37 +00:00
**Configure the Bot**
2022-07-11 10:35:24 +00:00
2023-04-27 16:43:37 +00:00
Next, once the plugin is installed, set up an [client](https://docs.mau.fi/maubot/usage/basic.html#creating-clients) and then create an [instance](https://docs.mau.fi/maubot/usage/basic.html#creating-instances) which connects the client and plugin.
2022-07-11 10:35:24 +00:00
2023-04-27 16:43:37 +00:00
Finally, invite the bot to an encrypted room where alerts should be sent and query the bot for the room id with the command `!roomid`.
2022-07-11 10:35:24 +00:00
2023-04-27 16:43:37 +00:00
## Setup Alertmanager
2022-07-11 10:35:24 +00:00
This configuration will send all your alerts to the room `!zOcbWjsWzdREnihgeC:example.com` (if the bot has access to it).
2022-09-09 20:57:55 +00:00
Put in your own room-id (`!roomid`) behind the webhook base url (`!url`):
2022-07-11 10:35:24 +00:00
```yaml
receivers:
- name: alertbot
webhook_configs:
- url: https://synapse.hyteck.de/_matrix/maubot/plugin/alertbot/webhook/!zOcbWjsWzdREnihgeC:example.com
route:
group_by:
- alertname
- cluster
- service
group_interval: 5m
group_wait: 30s
receiver: alertbot
repeat_interval: 3h
```
2023-04-27 16:43:37 +00:00
## Setup Grafana
2022-08-24 18:40:51 +00:00
The grafana setup is fairly simple and can be used to forward grafana alerts to matrix.
![Screenshot of the Grafana Setup](assets/grafana.png)
2023-04-27 16:43:37 +00:00
## Run Locally
2022-07-11 06:44:05 +00:00
You might want to test the bot on your local machine but send webhooks to a public server. To do that use a domain
2022-08-24 18:45:14 +00:00
e.g. webbhook.example.com and configure nginx as reverse proxy for port 4242 for this domain.
2022-07-11 06:44:05 +00:00
2023-04-27 16:43:37 +00:00
**Connect**
2022-07-11 06:44:05 +00:00
Run the local server and connect via (29316 is the local maubot port)
2022-08-24 18:45:14 +00:00
`ssh -N -R 4242:localhost:29316 webhook.example.com`
2022-07-11 06:44:05 +00:00
2023-04-27 16:43:37 +00:00
## Send Test Alerts
2022-07-11 06:44:05 +00:00
2022-08-24 18:45:14 +00:00
Use an example from the `alert_examples/` to test your setup
2022-07-11 06:44:05 +00:00
```shell
curl --header "Content-Type: application/json" \
--request POST \
2022-08-24 18:45:14 +00:00
--data "@alert_examples/prometheus.json" \
https://webhook.example.com/_matrix/maubot/plugin/maubot/webhook/!zOcbWjsWzdREnihreC:example.com
2022-07-11 06:44:05 +00:00
```
2023-04-27 16:43:37 +00:00
## Matrix Room
This project has a dedicated [chat room](https://matrix.to/#/#alertbot:hyteck.de)