telegram bot hosted on lainlounge servers for remote system monitoring
Find a file
hax b6792931dc Updoot secure system monitor with service management
Key Improvements:

Error Handling:
Used try-except blocks to catch errors from subprocesses and file operations, logging issues.

Thread Safety:
Introduced queue.Queue for thread-safe operations when handling ping results.

Subprocess Optimizations:
Used subprocess.run() for cleaner, more modern handling of subprocesses.
Avoided shell=True for security reasons unless absolutely necessary.

Service Management:
Improved service status checking by using systemctl is-active and using exit statuses for reliability.

User Authorization:
Checked user authorization in relevant commands like /restart, /reboot, and /ping.

Logging:
Introduced logging for all major operations to track activity and errors.

Polling Timeout:
Added timeouts and error handling to prevent the bot from hanging during long polling.

This updoot is bring more security, robustness, and scalability, ready to handle various edge cases that might occur in our system monitoring.

Signed-off-by: hax <hax@lainlounge.xyz>
2024-10-25 00:29:37 +00:00
lainmonitor.py Updoot secure system monitor with service management 2024-10-25 00:29:37 +00:00
LICENSE Initial commit 2024-10-04 18:55:32 +00:00
README.md Particular title removed 2024-10-04 19:10:08 +00:00
requirements.txt uploaded sou 2024-10-04 18:58:46 +00:00

LainMonitor

LainMonitor is a Telegram bot designed to monitor your system by providing real-time information about the system's status, services, and disk usage. It can also check connectivity to a specific Tailscale IP address.

Features

  • Retrieve system hostname, uptime, and status of essential services such as:
    • Zerotier
    • Prosody
    • PostgreSQL
    • Tailscale
  • Check disk usage
  • Ping a Tailscale IP to verify connectivity
  • Use via Telegram commands like /status, /ping, and /help

Dependencies

  • Telebot - A Python library for Telegram bot API.

Installation

  1. Clone this repository:

    git clone https://git.lainlounge.xyz/hornet/lainmonitor.git
    cd lainmonitor
    
  2. Install the required Python library:

    pip install pyTelegramBotAPI
    
  3. Replace the placeholder in the code with your Telegram bot token:

    TOKEN = 'PLACE_YOUR_TOKEN_HERE'
    
  4. Set up permissions for the bot to check system services (run as a user with sudo access).

Usage

Running Directly

You can run the bot directly using Python:

python3 lainmonitor.py

Running as a Service

To run LainMonitor as a service, follow these steps:

  1. Create a systemd service file:
    sudo nano /etc/systemd/system/lainmonitor.service
    
  2. Add the following configuration:
    [Unit]
    Description=LainMonitor Telegram Bot
    After=network.target
    
    [Service]
    ExecStart=/usr/bin/python3 /path/to/lainmonitor.py
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    
  3. Enable and start the service:
    sudo systemctl enable lainmonitor
    sudo systemctl start lainmonitor
    

Telegram Bot Commands

  • /start: Initialize the bot and receive a welcome message.
  • /help: Display available commands.
  • /status: Get the system hostname, status, uptime, and the status of monitored services.
  • /ping: Ping a Tailscale IP and return the connectivity status.
  • /reboot: (Work in progress) Placeholder for a reboot command.

Author

Created by hornetmaidan

Feel free to contribute or suggest features!