maubot-alertbot/README.md

105 lines
3.1 KiB
Markdown
Raw Normal View History

2022-08-24 14:40:51 -04: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.
This means that you no longer have to use E-Mail or Slack to receive alerts. See the setup below for how to use it or
join the [Alertbot room on matrix](https://matrix.to/#/#alertbot:hyteck.de)
2022-07-11 06:35:24 -04:00
# Getting Started
**Prerequisites:**
* A maubot instance: Please [refer to the docs](https://docs.mau.fi/maubot/usage/setup/index.html) for setting up one
* An instance of alertmanager or grafana or a similar alerting program that is able to send webhooks
2022-07-11 06:35:24 -04:00
**Getting the code**
Clone this repository to your local computer and install maubot to have access to the maubot CLI
```shell
git clone https://github.com/moan0s/alertbot
2022-08-24 14:45:57 -04:00
cd alertbot
2022-07-11 06:35:24 -04:00
pip install maubot
```
**Login to your maubot instance**
```shell
mbc login
```
**Build&Upload the plugin**
```shell
mbc build -u
```
You now have the plugin installed. Now you have to set up an instance of the bot in the maubot manager and invite it to
the room where the alerts should be sent. Also find out the room id by asking the bot for it with `!roomid`.
2022-08-24 14:40:51 -04:00
# Setup Alertmanager
2022-07-11 06:35:24 -04:00
This configuration will send all your alerts to the room `!zOcbWjsWzdREnihgeC:example.com` (if the bot has access to it).
2022-09-09 16:57:55 -04:00
Put in your own room-id (`!roomid`) behind the webhook base url (`!url`):
2022-07-11 06:35:24 -04: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
```
2022-08-24 14:40:51 -04:00
# Setup Grafana
The grafana setup is fairly simple and can be used to forward grafana alerts to matrix.
![Screenshot of the Grafana Setup](assets/grafana.png)
# Test your setup
It can be a bit annoying to trigger an alert (e.g. by shutting down a server) to test if your configuration is right and if the bot works as intended.
Therefore, you find a few example alerts in `alert_examples/` which allow you to test the bot.
Use them with the following command (but adjust the webhook URL):
```bash
curl --header "Content-Type: application/json" \
--request POST \
--data "@alert_examples/data.json" \
https://webhook.example.com/_matrix/maubot/plugin/maubot/webhook/!zOcbWjsWzdREnihreC:example.com
```
2022-07-11 06:35:24 -04:00
# Local testing Setup
2022-07-11 02:44:05 -04:00
2022-08-24 14:45:14 -04:00
Also you might want to test the bot on your local machine but send webhooks to a public server. To do that use a domain
e.g. webbhook.example.com and configure nginx as reverse proxy for port 4242 for this domain.
2022-07-11 02:44:05 -04:00
2022-08-24 14:40:51 -04:00
## Connect
2022-07-11 02:44:05 -04:00
Run the local server and connect via (29316 is the local maubot port)
2022-08-24 14:45:14 -04:00
`ssh -N -R 4242:localhost:29316 webhook.example.com`
2022-07-11 02:44:05 -04:00
2022-08-24 14:40:51 -04:00
## Send some data with
2022-07-11 02:44:05 -04:00
2022-08-24 14:45:14 -04:00
Use an example from the `alert_examples/` to test your setup
2022-07-11 02:44:05 -04:00
```shell
curl --header "Content-Type: application/json" \
--request POST \
2022-08-24 14:45:14 -04:00
--data "@alert_examples/prometheus.json" \
https://webhook.example.com/_matrix/maubot/plugin/maubot/webhook/!zOcbWjsWzdREnihreC:example.com
2022-07-11 02:44:05 -04:00
```