You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`ffshmon` monitors a WireGuard connection and attempts to recover it when the VPN check fails. It checks the configured FastD service, tests the WireGuard interface through Mullvad, regenerates the WireGuard configuration once after a failure, and alerts the NOC if recovery fails.
4
+
5
+
It also provides a Prometheus endpoint with the latest up/down status.
6
+
7
+
## Requirements
8
+
9
+
- Linux with `systemd` and `systemctl`
10
+
- Python 3.10 or newer
11
+
-`curl`
12
+
- A WireGuard interface named `exit` by default
13
+
- A FastD service named `fastd@ffsh.service` by default
14
+
-`/opt/wg-conf-gen/wg-conf-gen.py` for automatic configuration recovery
15
+
- SMTP access to the configured mail host for failure alerts
16
+
17
+
## Installation
18
+
19
+
Create a virtual environment and install the Python dependencies:
Run the existing scheduled check with mail credentials and a log file:
29
+
30
+
```bash
31
+
.venv/bin/python wireguard.py check \
32
+
--user noc@example.org \
33
+
--password 'mail-password' \
34
+
--log /var/log/ffshmon.log
35
+
```
36
+
37
+
The command exits after one health cycle. If the FastD service is down, the connection probe is skipped and the status is considered down. If the probe fails, `ffshmon` regenerates the WireGuard configuration and retries once. A second failure stops FastD and WireGuard and sends an email alert.
38
+
39
+
## Prometheus endpoint
40
+
41
+
Start the long-running monitor with:
42
+
43
+
```bash
44
+
.venv/bin/python wireguard.py serve \
45
+
--user noc@example.org \
46
+
--password 'mail-password' \
47
+
--log /var/log/ffshmon.log
48
+
```
49
+
50
+
By default, the process:
51
+
52
+
- Runs an immediate health check, then repeats every 60 seconds.
53
+
- Listens on `127.0.0.1:8000`.
54
+
- Exposes the latest completed result at `/metrics`.
55
+
- Does not run a new health check when Prometheus scrapes the endpoint.
56
+
57
+
Example request:
58
+
59
+
```bash
60
+
curl http://127.0.0.1:8000/metrics
61
+
```
62
+
63
+
The relevant metric is:
64
+
65
+
```text
66
+
wireguard_up{interface="exit"} 1.0
67
+
```
68
+
69
+
A value of `1` means the latest check succeeded. A value of `0` means the FastD service or WireGuard connectivity check is down.
70
+
71
+
The listener and polling interval can be changed with `--host`, `--port`, and `--interval`:
72
+
73
+
```bash
74
+
.venv/bin/python wireguard.py serve \
75
+
--user noc@example.org \
76
+
--password 'mail-password' \
77
+
--log /var/log/ffshmon.log \
78
+
--host 127.0.0.1 \
79
+
--port 8000 \
80
+
--interval 60
81
+
```
82
+
83
+
## Prometheus configuration
84
+
85
+
Add a scrape job for the host running `ffshmon`:
86
+
87
+
```yaml
88
+
scrape_configs:
89
+
- job_name: ffshmon
90
+
static_configs:
91
+
- targets: ["127.0.0.1:8000"]
92
+
```
93
+
94
+
If Prometheus runs on another host, bind `serve` to an appropriate reachable address and protect the endpoint with firewall rules or a reverse proxy. The endpoint has no built-in authentication.
95
+
96
+
## Running as a service
97
+
98
+
Run `serve` as a supervised systemd service so the endpoint remains available. A minimal unit could look like this:
Avoid storing real credentials directly in a world-readable unit file. Use a protected environment file or another systemd credential mechanism in production.
0 commit comments