Skip to content

A simple Telegram bot designed to gather basic information about the status of your local servers, writing on Python

License

Notifications You must be signed in to change notification settings

orenlab/pytmbot

Repository files navigation

pytmbot

pyTMbot

A simple Telegram bot designed to gather basic information about the status of your local servers. The bot operates synchronously. It does not use webhooks.

Security Rating Vulnerabilities Quality Gate Status Bugs Maintainability Rating Code Smells Duplicated Lines (%) Codacy Badge Production Docker CI

The bot was written using the pyTelegramBotAPI. Use psutil and docker-py libraries for gather information.

💡 Features

  • Load average information
  • Summary memory usage information (with swap)
  • Sensors information
  • Summary process information
  • Uptime information
  • File system base information
  • Containers (so far, only Docker and only on Linux) base information
  • Ability to check for bot software updates: /check_bot_updates (Available in the alpine-dev version)
  • Jinja2 is used for creating templates.
  • Bot logs are available in the Docker logging system.
  • Emoji are used :)

Screenshots are available here: screenshots.md. Video demo see in YouTube Shorts here

🕸 Requirements

Initially, the bot was designed to ensure its correct operation only within the Docker container. I have not tested it running on a local system, either inside or outside a virtual environment. Therefore, please make sure that Docker is installed on your system.

Full list of Python dependencies see in requirements.txt

🔌 Installation, setup and run bot

🛡 Secure

The bot has an authorization mechanism. That is based on a unique value we can get from the message's variable from_user.id, which is the Telegram user ID. By comparing this value with the user.id values specified in the bot's settings (which is done at the initial stage of configuring the bot), we can determine the behavior of the bot.

All failed attempts to authorize are logged with an ERROR flag.

🌲 Bot tree

├── Dockerfile                              - Main Dockerfile
├── LICENSE                                 - Licence file
├── README.md                               - Main README
├── SECURITY.md                             - Security policy
├── app
│   ├── __init__.py                         
│   ├── core
│   │   ├── __init__.py                     - Bot core
│   │   ├── adapters
│   │   │   ├── __init__.py
│   │   │   ├── docker_adapter.py           - Docker adapter
│   │   │   ├── podman_adapter.py           - Podman adapter (in development)
│   │   │   └── psutil_adapter.py           - Psutil adapter
│   │   ├── exceptions.py                   - Custom exceptions
│   │   ├── handlers
│   │   │   ├── __init__.py
│   │   │   ├── default_handlers
│   │   │   │   ├── __init__.py             - Import all defaults handlers
│   │   │   │   ├── check_bot_update.py     - Check pyTMbot updates
│   │   │   │   ├── containers_handler.py   - Container handler
│   │   │   │   ├── fs_handler.py           - Filesystem handler
│   │   │   │   ├── load_avg_handler.py     - Load average handler
│   │   │   │   ├── memory_handler.py       - Memory handler
│   │   │   │   ├── process_handler.py      - Process handler
│   │   │   │   ├── sensors_handler.py      - Sensors handler
│   │   │   │   ├── start_handler.py        - Main, start handler
│   │   │   │   └── uptime_handlers.py      - Uptime handler
│   │   │   ├── handler.py                  - Base handler class (abc)
│   │   │   ├── handlers_aggregator.py      - Main handlers aggregator
│   │   │   └── inline_handlers
│   │   │       ├── __init__.py
│   │   │       └── swap_handler.py         - Swap inline handler
│   │   ├── jinja2
│   │   │   ├── __init__.py
│   │   │   └── jinja2.py                   - Main jinja2 class
│   │   ├── keyboards
│   │   │   ├── __init__.py
│   │   │   └── keyboards.py                - Main keyboards class  
│   │   ├── logs.py                         - Custom logger
│   │   ├── middleware
│   │   │   ├── __init__.py
│   │   │   └── auth.py                     - Auth middleware class
│   │   └── settings
│   │       ├── __init__.py
│   │       ├── bot_settings.py             - Class to load configuration from .pytmbotenv
│   │       ├── keyboards.py                - Keyboards settings
│   │       └── loggers.py                  - Logger templates
│   ├── main.py                             - Main bot class
│   ├── templates
│   │   ├── bot_update.jinja2               - Bot update jinja2 template
│   │   ├── containers.jinja2               - Containers jinja2 template 
│   │   ├── fs.jinja2                       - Filesystem jinja2 template
│   │   ├── index.jinja2                    - Start jinja2 template
│   │   ├── load_average.jinja2             - Load average jinja2 template
│   │   ├── memory.jinja2                   - Memory jinja2 template
│   │   ├── none.jinja2                     - Docker jinja2 template
│   │   ├── process.jinja2                  - Process jinja2 template
│   │   ├── sensors.jinja2                  - Sensors jinja2 template
│   │   ├── swap.jinja2                     - Swap jinja2 template
│   │   └── uptime.jinja2                   - Uptime jinja2 template
│   └── utilities
│       ├── __init__.py
│       └── utilities.py                    - Some utility
├── bot_cli
│   ├── cfg_templates
│   │   └── env.py                          - Template for initial setup
│   └── fs.py                               - Filesystem utility
├── docker-compose.yml                      - Docker Compose file (used main Dockerfile)
├── docs
│   ├── installation.md                     - Installation guide
│   ├── roadmap.md                          - Roadmap guide
│   └── screenshots.md                      - Bots screenshot
├── hub.Dockerfile                          - Dockerfile for Docker CI/CD based on Alpine
├── poetry.lock                             - Poetry file
├── pyproject.toml                          - Poetry file
├── requirements.txt                        - Requirements for build Docker image
├── setup_bot.py                            - Initial setup bot script
├── setup_req.txt                           - Setup requirements
├── tests
│   └── bot_tests.py                        - Bots tests

📈 Roadmap

👾 Known issues

  • You tell me :)

🧬 Authors

🚀 About Me

I am a novice Python developer. This is my first publicly available project in this great programming language.

📜 License

MIT License