Telegram bot for monitoring the availability of network services.
·
Report Bug
·
Request Feature
Monitoring the availability of network services is an important task for any project. At the same time, it is not always necessary to deploy universal solutions like Prometheus, a fairly simple solution. It is for such cases that this bot was created.
The bot will allow you to monitor the availability of HTTP(S) and TCP services and notify Telegram about changes in their status.
The project is in the MVP stage.
Follow the instructions below to run a bot using Docker.
To run a bot, it is enough to have Docker or another environment for running containers.
- Register a new bot and get a token for it: https://core.telegram.org/bots/features#creating-a-new-bot
- Create a channel or group to which notifications will be sent
- Add the bot to the channel/group as an administrator with the ability to send messages
- Copy the configuration file config.example.yml to your working directory as
config.yml - Make changes to the configuration file:
- specify the bot token;
- specify the channel/group ID, you can find out the ID, for example, by following the link like https://api.telegram.org/bot/getUpdates?allowed_updates=[] after adding the bot to a channel/group and finding the value of
my_chat_member.chat.id; - list the services to monitor (or configure a storage backend).
- Run the docker container:
docker run -d -v "$(pwd)/config.yml:/app/config.yml:ro" --name tgbot capcom6/service-monitor-tgbot:latest
Note: By default, the service list is read from the same YAML file (file storage backend). To use Redis or another backend, see the Storage Backends section and set the
storage.dsnfield orSTORAGE__DSNenvironment variable.
The bot uses a flexible template system for customizing notification messages. Templates support Go template syntax and can be customized in the configuration file under the messages section.
Available templates:
| Template | Variables | Description |
|---|---|---|
online |
Name - name of the serviceChangedAt - when the service entered this stateDuration - how long the service has been in this state |
message when a service goes "online" |
offline |
Name - name of the serviceError - error messageChangedAt - when the service entered this stateDuration - how long the service has been in this state |
message when a service goes "offline" |
services_list |
. - list of all services:Name - name of the serviceState - state of the serviceError - error messageChangedAt - when the service entered this stateDuration - how long the service has been in this state |
message with a list of all services |
The bot supports the following commands:
/status- Get the current status of all monitored services
The bot supports pluggable storage backends for loading the list of monitored services. The backend is selected via DSN in the storage.dsn config field (or STORAGE__DSN environment variable).
| Scheme | Backend | Use Case |
|---|---|---|
file |
YAML file (default) | Simple setups, static configs |
redis |
Redis key | Dynamic service lists, distributed management |
File DSN format: file:///path/to/services.yml
Redis DSN format: redis://[[user]:pass@]host:port[/db][?key=<key>&channel=<channel>]
Default key: service-monitor:services, default channel: service-monitor:reload.
services:
- name: Google
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 3
httpGet:
scheme: https
host: google.com
path: /
port: 443
httpHeaders:
- name: X-Header
value: valueservices:
- name: MySQL
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 3
tcpSocket:
host: localhost
port: 3306- Add Changelog
- Add the ability to change the text of messages
- Send notifications to multiple channels/groups
- Display event time in notifications
- Online/offline time count
- Active bot mode
- Request current state of services
- SLA report
- The event log
- Separation of bot and monitoring service
- Dynamic list of services
- Service discovery
- Resource groups
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the Apache-2.0 license. See LICENSE.txt for more information.
Project Link: https://github.com/capcom6/service-monitor-tgbot

