README.md aktualisiert

Signed-off-by: hax <hax@lainlounge.org>
This commit is contained in:
h@x 2025-07-22 09:15:06 +00:00
parent ce133c03ee
commit e7275ac1de

146
README.md
View file

@ -1,79 +1,105 @@
# 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.
LainMonitor is a Telegram bot designed to provide realtime monitoring of both the local system and remote network clients (OPNsense firewalls and generic SSH hosts). It aggregates key metrics via SSH and REST APIs, and delivers concise reports through Telegram commands.
## 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](https://github.com/eternnoir/pyTelegramBotAPI) - A Python library for Telegram bot API.
* **Local System Monitoring**
* Hostname and overall online/offline status
* Uptime (humanreadable)
* Load averages (1, 5, 15 minute)
* Memory usage (via `free -h`)
* Disk usage (via `df -h`)
* **Remote Client Monitoring**
* **OPNsense Firewalls** (multiple hosts with perhost trustonfirstuse SSL)
* System health status
* Uptime
* Memory and disk statistics
* Load averages
* **Generic SSH Hosts**
* Hostname, uptime, load, memory, and disk via SSH
* **Security & Resilience**
* Trustonfirstuse SSL: automatically fetches and caches firewall certificates
* Concurrency: parallel polling of remote hosts with `ThreadPoolExecutor`
* Error handling: pertask exceptions are logged and do not interrupt overall data gathering
* Access control: only whitelisted Telegram chat IDs can invoke commands
* Automatic bot restart on failure with backoff retry loop
## Commands
* `/status` or `/ping` — Returns a combined report of local and remote metrics
## Installation
1. Clone this repository:
```bash
git clone https://git.lainlounge.xyz/hornet/lainmonitor.git
cd lainmonitor
```
2. Install the required Python library:
```bash
pip install pyTelegramBotAPI
```
3. Replace the placeholder in the code with your Telegram bot token:
```python
TOKEN = 'PLACE_YOUR_TOKEN_HERE'
```
4. Set up permissions for the bot to check system services (run as a user with `sudo` access).
1. **Clone repository**
```bash
git clone https://git.lainlounge.xyz/hornet/lainmonitor.git
cd lainmonitor
```
2. **Install dependencies**
```bash
pip install -r requirements.txt
```
3. **Configure**
* Copy `config.py.example` to `config.py`
* Populate `config.TOKEN` with your Telegram bot token
* Add your Telegram chat IDs to `config.ALLOWED_CHATS`
* Define each host under `config.HOSTS` with correct credentials and API settings
4. **Prepare SSL directory** (created automatically at runtime):
```bash
mkdir certs
```
## Usage
### Running Directly
You can run the bot directly using Python:
* **Run directly**
```bash
python3 lainmonitor.py
```
```bash
python3 lainmonitor.py
```
### Running as a Service
To run LainMonitor as a service, follow these steps:
1. Create a systemd service file:
```bash
sudo nano /etc/systemd/system/lainmonitor.service
```
2. Add the following configuration:
```ini
[Unit]
Description=LainMonitor Telegram Bot
After=network.target
* **Run as a service** (systemd)
[Service]
ExecStart=/usr/bin/python3 /path/to/lainmonitor.py
Restart=on-failure
```ini
[Unit]
Description=LainMonitor Telegram Bot
After=network.target
[Install]
WantedBy=multi-user.target
```
3. Enable and start the service:
```bash
sudo systemctl enable lainmonitor
sudo systemctl start lainmonitor
```
[Service]
ExecStart=/usr/bin/python3 /path/to/lainmonitor.py
Restart=on-failure
## 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.
[Install]
WantedBy=multi-user.target
```
```bash
sudo systemctl enable lainmonitor
sudo systemctl start lainmonitor
```
## Dependencies
* `pyTelegramBotAPI` (Telebot) — Telegram Bot API client
* `paramiko` — SSH connectivity
* `requests` — HTTP/REST API client
## Author
Created by **hornetmaidan**
Feel free to contribute or suggest features!
**h@x**
## Original Script written by:
**hornetmaidan**
Contributions and feedback are welcome! :-)