A lightweight Bash script designed for Linux environments (Ubuntu/Alpine/LXC) to monitor the Tailscale backend state and send real-time alerts via Telegram when a node requires re-authentication or goes offline.
- Real-time Monitoring: Detects if Tailscale is
Running,NeedsLogin, orStopped. - Reliable Parsing: Uses
jqfor accurate JSON data extraction. - Smart Notifications: Sends formatted Telegram alerts including Hostname and Timestamp.
- LXC/Docker Compatible: Works within Proxmox containers and virtual machines.
- Tailscale installed and configured.
- jq installed (for JSON parsing):
- Ubuntu/Debian:
sudo apt update && sudo apt install jq -y - Alpine:
apk add jq
- Ubuntu/Debian:
- curl installed (for sending Telegram messages).
To send notifications, you need a Telegram Bot and your personal Chat ID.
- Search for @BotFather on Telegram.
- Send
/newbotand follow the instructions to name your bot. - Save the API Token provided (e.g.,
12345678:AAH...).
- Search for your new bot's username and press Start.
- Visit the following URL in your browser (replace
YOUR_TOKENwith your API Token):https://api.telegram.org/botYOUR_TOKEN/getUpdates - Look for
"id":in the JSON response (e.g.,987654321). This is your Chat ID.- Note: If sending to a group, add the bot to the group and use a bot like @IDBot to get the group ID (it will start with a
-).
- Note: If sending to a group, add the bot to the group and use a bot like @IDBot to get the group ID (it will start with a
- Create the script file:
sudo nano /usr/local/bin/tailscale-monitor.sh
- Make it executable:
sudo chmod +x /usr/local/bin/tailscale-monitor.sh
- Make it executable:
To monitor Tailscale automatically every 5 minutes:
crontab -e
- Add the following line at the bottom:
*/5 * * * * /usr/local/bin/tailscale-monitor.sh > /dev/null 2>&1