Receive notifications via Telegram or Gotify whenever a client connects or disconnects from a WireGuard tunnel.
Follow these steps to set up the notification service on your WireGuard server.
Start by cloning this repository onto your server:
git clone https://github.com/yourusername/wireguard-client-connection-notification.git
-
Rename the configuration file template:
mv .config-example .config
-
Edit the
.config
file to include your notification settings. Make sure to configure either Telegram or Gotify server details.
-
Grant execution permissions to the main script:
sudo chmod +x /path/to/wireguard-client-connection-notification/wg-clients-guardian.sh
-
Add the script to the root user's cron job to run it periodically. Elevated privileges are required to access WireGuard tunnel information.
-
Open the root crontab editor:
sudo crontab -e
-
Add the following line to execute the script every minute:
* * * * * cd /path/to/wireguard-client-connection-notification && /path/to/wireguard-client-connection-notification/wg-clients-guardian.sh /path/to/wireguard-client-connection-notification/.config > /dev/null 2>&1
-
Once everything is set up, the script will check for client connections or disconnections every minute and send a notification through your configured method.
This project was inspired by and built upon the work done by the PiVPN project. Special thanks to the PiVPN team for their clientSTAT.sh
script, which served as a foundation for understanding and managing WireGuard client connections. You can find the original script here.