forked from hornet/lainmonitor
2.5 KiB
2.5 KiB
LainMonitor
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
-
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
/statusor/ping— Returns a combined report of local and remote metrics
Installation
-
Clone repository
git clone https://git.lainlounge.xyz/hornet/lainmonitor.git cd lainmonitor -
Install dependencies
pip install -r requirements.txt -
Configure
- Copy
config.py.exampletoconfig.py - Populate
config.TOKENwith your Telegram bot token - Add your Telegram chat IDs to
config.ALLOWED_CHATS - Define each host under
config.HOSTSwith correct credentials and API settings
- Copy
-
Prepare SSL directory (created automatically at runtime):
mkdir certs
Usage
-
Run directly
python3 lainmonitor.py -
Run as a service (systemd)
[Unit] Description=LainMonitor Telegram Bot After=network.target [Service] ExecStart=/usr/bin/python3 /path/to/lainmonitor.py Restart=on-failure [Install] WantedBy=multi-user.targetsudo systemctl enable lainmonitor sudo systemctl start lainmonitor
Dependencies
pyTelegramBotAPI(Telebot) — Telegram Bot API clientparamiko— SSH connectivityrequests— HTTP/REST API client
Author
h@x
Original Script written by:
hornetmaidan
Contributions and feedback are welcome! :-)