Merge origin/main into main

This commit is contained in:
tyuXX 2026-11-19 13:15:34 +00:00
commit 161bf5e8cb
20 changed files with 1592 additions and 116 deletions

107
README.md
View file

@ -1,113 +1,58 @@
# R u ded? (`rud`)
**R u ded? (`rud`)** is a performant, lightweight, self-contained uptime monitor and health checker written in Go by **tyuXX** for **GsDistance.org** ([git.gsdistance.org/tyuXX/RUD](https://git.gsdistance.org/tyuXX/RUD)).
Lightweight uptime monitor and health checker written in Go by [tyuXX] ([git.gsdistance.org/tyuXX/RUD](https://git.gsdistance.org/tyuXX/RUD)).
It compiles to a single zero-dependency binary, runs concurrent checks across multiple protocols, evaluates declarative alert rules, and serves a **single HTTP endpoint** whose minimal status page and JSON health output are configured entirely through a single human-readable [`rud.json`](file:///home/devuser/workspace/RUD/rud.json) file.
Mainly created for use in GsDistance.org.
---
## Features
- **Single `rud.json` Configuration**: Intuitive, human-readable JSON file loaded at startup. Automatically generates a sensible default `rud.json` if missing.
- **Strict Config-Driven Minimalist UI**: Renders **only** the UI elements, bars, and metrics declared in `rud.json` (plus a subtle `'Powered by R u ded?'` attribution footer), with all CSS and live-refresh JS inlined into a single fast response.
- **Single HTTP Endpoint (HTML + JSON)**:
- Browser requests receive the clean, minimal status page with automatic background updates.
- Requests with `Accept: application/json` or `?format=json` receive structured JSON status and metrics.
- Configurable HTTP status codes per state (defaults HTML to `200` so Cloudflare Tunnel never intercepts your status page with a 5xx error screen).
- **Multi-Method Health Checks**:
- `http` / `https`: Status codes, custom request headers, body regex matching, latency, TLS options.
- `tcp`: Port connectivity and handshake latency.
- `ping`: Direct ICMP echo reachability and RTT latency.
- `dns`: Record resolution (`A`, `AAAA`, `CNAME`, `MX`, `TXT`, `NS`), custom resolvers, and regex validation.
- `cmd`: Custom shell commands or scripts with exit code and output regex verification.
- **Declarative Event & Alert Engine**: Combine monitor boolean triggers (`all` or `any` of monitor IDs in a state), sustained durations (e.g., `"for": "5h"`), and metric thresholds (`uptime_pct`, `latency_ms`, `consecutive_failures`) using `"and"` / `"or"` logic to trigger outbound webhooks or execute commands.
- **Interactive CLI Config Builder (`rud config`)**: Built-in zero-dependency CLI to create new configurations from starter templates or a quick-start wizard, edit existing `rud.json` files (including nested `AND`/`OR` event condition trees, Discord/Slack/ntfy/Gotify webhook presets, and theme presets), test monitors live, validate/lint (`rud validate`), and save atomically with optional `.bak` backups.
- **In-Memory Ring Buffer + Optional Persistence**: Maximum speed in-memory circular buffer by default, with optional atomic disk persistence across restarts.
- **Docker & Cloudflare Tunnel Ready**: Includes a multi-stage `Dockerfile`, a direct `docker-compose.yml`, and a zero-exposed-port `docker-compose.cloudflared.yml`.
Compiles to a single static binary, checks `http`/`https`, `tcp`, `ping`, `dns`, and `cmd` targets, sends declarative alerts (webhooks/commands), and serves a minimal status page plus JSON health output — all configured through one `rud.json` file. Full check history is kept in daily JSONL logs (zstd-compressed) and a SQLite stats database, viewable per-monitor at `/monitor`.
---
## Quick Start
### 1. Run as a Standalone Binary
### Standalone binary
```bash
# Build the self-contained binary
go build -trimpath -ldflags="-s -w" -o rud .
# (Optional) Build or edit rud.json interactively
./rud config -config rud.json
# (Optional) Generate a default rud.json non-interactively
./rud -init -config rud.json
# Validate & lint rud.json, or run one-shot live checks
./rud validate -config rud.json
./rud test -config rud.json
# Run R u ded? (auto-generates rud.json if not present)
./rud -config rud.json
./rud config -config rud.json # interactive config builder (new or edit)
./rud validate -config rud.json # validate & lint configuration
./rud test -config rud.json # run one-shot live checks
./rud -config rud.json # run server (auto-generates rud.json if missing)
```
Then open `http://localhost:8080/` (HTML), `http://localhost:8080/monitor` (per-monitor history & charts), or `http://localhost:8080/?format=json` (JSON).
#### CLI Subcommands
- `./rud config [-config path] [-new] [-plain] [-no-color]`: Interactive configuration builder (arrow-key navigation on TTYs with automatic numbered fallback; `-new` forces the starter template / quick-start wizard).
- `./rud validate [-config path] [-strict]`: Validates schema, regexes, URLs, and alert templates, and reports lint warnings (unknown JSON fields, dangling monitor IDs). `-strict` treats lint warnings as errors.
- `./rud test [-config path] [-json] [-no-retry] [monitor-ids...]`: Executes live monitor checks once and prints results (exits non-zero if any tested monitor is `down`).
- `./rud -init -config rud.json`: Non-interactively writes a default `rud.json` and exits.
### Docker Compose
Query the single endpoint:
```bash
# Minimal HTML Status Page
curl http://localhost:8080/
# Structured JSON Output (via query parameter or Accept header)
curl "http://localhost:8080/?format=json"
curl -H "Accept: application/json" http://localhost:8080/
docker compose up -d --build # exposes port 8080, persists ./data
```
### Docker Compose + Cloudflare Tunnel (no exposed ports)
```bash
cp .env.example .env # set TUNNEL_TOKEN=...
docker compose -f docker-compose.cloudflared.yml up -d --build
```
Point your tunnel's public hostname at `http://rud:8080`.
---
### 2. Run with Docker Compose (Direct Port Exposure)
## Configuration
Uses [`docker-compose.yml`](./docker-compose.yml) to expose port `8080` directly on the host:
```bash
docker compose up -d --build
```
Edit `./rud.json` and restart the container to apply changes:
```bash
docker compose restart rud
```
---
### 3. Run with Docker Compose + Cloudflare Tunnel (Zero Exposed Host Ports)
Uses [`docker-compose.cloudflared.yml`](./docker-compose.cloudflared.yml) to run `rud` and `cloudflared` on an isolated internal Docker bridge network (`rud_tunnel_net`) with **no ports bound to the host**:
1. Copy `.env.example` to `.env` and set your Cloudflare Tunnel token:
```bash
cp .env.example .env
# Set TUNNEL_TOKEN=... in .env
```
2. In your Cloudflare Zero Trust dashboard, configure your tunnel's Public Hostname service URL to point to:
```text
http://rud:8080
```
3. Start the stack:
```bash
docker compose -f docker-compose.cloudflared.yml up -d --build
```
---
## Configuration Documentation
See [**`CONFIGURATION.md`**](./CONFIGURATION.md) for the complete reference covering every section, check method, declarative event condition, and UI element in `rud.json`.
See [**`CONFIGURATION.md`**](./CONFIGURATION.md) for the full `rud.json` reference — monitors, check methods, alert events, page elements, and storage/history options.
---
## License
MIT License — Created by **tyuXX** for **GsDistance.org** ([https://git.gsdistance.org/tyuXX/RUD](https://git.gsdistance.org/tyuXX/RUD)).
MIT — Created by **tyuXX** for **GsDistance.org**.