With this tutorial you can setup your server to send an alert to telegram when a client is connected or disconnected from the tunnel.
The script sends a message to telegram if the client hasn't activity with the server for x (15 default) minutes.
Prerequisites
- Server with Wireguard and root privileges (read this post to install wireguard)
- curl
sudo apt install curl
- Telegram Bot (how to create a bot)
Installation
- download this script
- Edit the file
wg-clients-guardian.sh
and change:
TIME_LIMIT=15 (alert will be sent after 15 minutes of inactivity)
TELEGRAM_CHAT_ID="your-chat-id"
TELEGRAM_BOT_ID="your-bot-api-key"
- Add execution privilege to
wg-clients-guardian.sh
sudo -s
chmod +x /path/to/wireguard-client-connection-notification/wg-clients-guardian.sh
- create the cron job
* * * * * cd /path/to/wireguard-client-connection-notification/wg-clients-guardian.sh && /path/to/wireguard-client-connection-notification/wg-clients-guardian.sh > /dev/null 2>&1
Do you want to receive an email instead of a telegram notification?
Change this lines: 98,99
MESSAGE="🐉 Wireguard: \`$CLIENT_NAME $SEND_NOTIFICATION from $REMOTE_IP\`"
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_ID}/sendMessage" -F chat_id=$TELEGRAM_CHAT_ID -F text="$MESSAGE" -F parse_mode="MarkdownV2" > /dev/null 2>&1
whit
MESSAGE="Wireguard: $CLIENT_NAME $SEND_NOTIFICATION from $REMOTE_IP"
echo "$MESSAGE" | mail -s subject your@email.com
Note: requires mail package sudo apt install mail
Top comments (0)