Better Uptime is a monitoring service for websites, cronjobs, etc. It works great, but with the free version I can only receive notifications via emails which is anoying. Since I'm in the process of learning Python, I thought I might as well code something useful.
So here is the plan: I connected the program to my email account, and when it receives a new mail from Better Uptime, it downloads that email, filters all the informarmations and store it in a database. Then a discord bot notifies me of the alert in a channel in my personnal server.
- In your mail inbox, create a rule that moves all emails from
[email protected]
to a specific folder - Create a Discord Application here
- Create a bot for your Application
- Add it to your server with the required permissions (Read Messages/View Channels, Send Messages, Manage Messages)
- Download the
docker-compose.yml
and.env.example
files from the root of the repo - Rename
.env.example
to.env
and fill in the variables - Deploy your stack with
docker compose up -d
- Done ! Now the bot will notify you for every incident
I said in my first log that I planned to implement a message cleanup feature, and here it is ! Basically, every time the loop runs it checks all the alert messages and deletes the ones that are more than 30 days old, except if the incident isn't resolved. Also, I added some commands to start and stop the loop and to shut down the bot completely. Maybe in the future I will find more commands ideas.
Today, I realized that the library I used to communicate with the IMAP server needed a license after a 30 days trial. When I saw that the license was almost $300 per year, I decided to use another library. I tested multiple ones and settled on imap_tools which is a sort of "interface" with the imaplib integrated in Python that simplifies the configuration.
I also added the status feature I talked about in the last update.
I connected all the different modules that I developed separately up until now and everything works ! Unfortunately, I couldn't use my first idea where I edit the original alert message into a resolution message, as I wouldn't be able to get notified again. So to work around that, the bot replies to the alert message with a separate resolution message and links it in the alert message (and changes the alert message color to orange). As this is going to significantly add clutter in the discord channel, so I'm thinking of adding a function that checks for old, resolved alert messages, and delete them.
But first I want to implement a status feature. So when an incident is ongoing, the status of the bot changes to red (do not disturb) and a text under his name shows "Ongoing incident" or something like that.