Compare commits

...

6 Commits

Author SHA1 Message Date
Julian-Samuel Gebühr ec44565558 Reduce automatic upload to difference between web interface
and add a bit more explanation why this might be helpful
2023-05-12 12:25:07 +02:00
Julian-Samuel Gebühr e6777b9bf6 Remove test locally from readme
This is a very edge case that is more puzzeling than helpful
2023-05-12 12:22:10 +02:00
spatterlight fd70866be0
Update README.md 2023-05-11 20:21:06 +00:00
spatterlight aa0a25e8b0
Update README.md 2023-05-10 18:28:55 +00:00
spatterlight 400156386c
Update CHANGELOG.md 2023-04-27 17:06:21 +00:00
spatterlight 42d95c7c9d
Update README.md 2023-04-27 16:43:37 +00:00
2 changed files with 31 additions and 48 deletions

View File

@ -1,3 +1,7 @@
# April 2023
Raw mode defaults to unordered list, for improved readability.
# March 2023
Change `!url` to display the full webhook url not just the base
@ -9,4 +13,4 @@ Change `!url` to display the full webhook url not just the base
# September 2022
* Add [uptime-kuma](https://github.com/louislam/uptime-kuma) example
* Add [uptime-kuma](https://github.com/louislam/uptime-kuma) example

View File

@ -3,50 +3,52 @@
# 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)
This means that you no longer have to use E-Mail or Slack to receive alerts.
# Getting Started
## Getting Started
## OPTION 1: Use provided alertbot
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.
## 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)
## OPTION 2: Selfhost alertbot
## Self-host an Instance
**Prerequisites:**
* A Matrix server where you have access to a maubot instance: Please [refer to the docs](https://docs.mau.fi/maubot/usage/setup/index.html) for setting up one
* 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
**Getting the code**
**Build the Bot**
Clone this repository to your local computer and install maubot to have access to the maubot CLI
The bot is built using the maubot command line tool `mbc`, you can either build it locally or remotely.
Build it locally, and afterwards navigate to the Maubot Administration Interface and upload the .mpb file.
```shell
pip install maubot
git clone https://github.com/moan0s/alertbot
cd alertbot
pip install maubot
mbc build
```
**Login to your maubot instance**
It's possible to upload the build to you maubot instance from the CLI. This is especially helpful when developing.
First login to your instance, then add the `-u` flag to upload after build.
```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`.
**Configure the Bot**
Next, once the plugin is installed, set up a [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.
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`.
# Setup Alertmanager
## Setup Alertmanager
This configuration will send all your alerts to the room `!zOcbWjsWzdREnihgeC:example.com` (if the bot has access to it).
Put in your own room-id (`!roomid`) behind the webhook base url (`!url`):
@ -68,39 +70,13 @@ route:
```
# Setup Grafana
## 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
```
# Local testing Setup
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.
## Connect
Run the local server and connect via (29316 is the local maubot port)
`ssh -N -R 4242:localhost:29316 webhook.example.com`
## Send some data with
## Send Test Alerts
Use an example from the `alert_examples/` to test your setup
```shell
@ -110,3 +86,6 @@ curl --header "Content-Type: application/json" \
https://webhook.example.com/_matrix/maubot/plugin/maubot/webhook/!zOcbWjsWzdREnihreC:example.com
```
## Matrix Room
This project has a dedicated [chat room](https://matrix.to/#/#alertbot:hyteck.de)