forked from hornet/lainmonitor
README.md aktualisiert
Signed-off-by: hax <hax@lainlounge.org>
This commit is contained in:
parent
ce133c03ee
commit
e7275ac1de
1 changed files with 86 additions and 60 deletions
146
README.md
146
README.md
|
|
@ -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 real‑time 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 (human‑readable)
|
||||
* Load averages (1, 5, 15 minute)
|
||||
* Memory usage (via `free -h`)
|
||||
* Disk usage (via `df -h`)
|
||||
|
||||
* **Remote Client Monitoring**
|
||||
|
||||
* **OPNsense Firewalls** (multiple hosts with per‑host trust‑on‑first‑use SSL)
|
||||
|
||||
* System health status
|
||||
* Uptime
|
||||
* Memory and disk statistics
|
||||
* Load averages
|
||||
* **Generic SSH Hosts**
|
||||
|
||||
* Hostname, uptime, load, memory, and disk via SSH
|
||||
|
||||
* **Security & Resilience**
|
||||
|
||||
* Trust‑on‑first‑use SSL: automatically fetches and caches firewall certificates
|
||||
* Concurrency: parallel polling of remote hosts with `ThreadPoolExecutor`
|
||||
* Error handling: per‑task 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! :-)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue