Skip to content

Instantly share code, notes, and snippets.

@ySnoopyDogy
Created February 16, 2024 00:34
Show Gist options
  • Save ySnoopyDogy/3a811fe36468ae1c05d46145443ca20a to your computer and use it in GitHub Desktop.
Save ySnoopyDogy/3a811fe36468ae1c05d46145443ca20a to your computer and use it in GitHub Desktop.
Alert DNS resolution problems in Discord
#!/bin/bash
WEBHOOK_URL="https://discord.com/api/v10/webhooks/XXX/XXX"
NAME_TO_CHECK="luancaliel.dev"
TEST_FREQUENCY="2"
USER_TO_MENTION="435228312214962204"
alert_debounce=true
healthy=true
send_webhook() {
if [ "$alert_debounce" = true ]; then
return
fi
local message=$1
alert_debounce=true
timestamp=$(date '+%d/%m/%Y %H:%M:%S')
payload='{"content": "'$message'\n\n'$timestamp' <@'$USER_TO_MENTION'>", "allowed_mentions": {"users": ["'$USER_TO_MENTION'"]}}'
curl -X POST -H "Content-Type: application/json" -d "$payload" "$WEBHOOK_URL"
}
while true; do
result=$(dig +short $NAME_TO_CHECK)
if [ -z "$result" ]; then
if [ "$healthy" = true ]; then
alert_debounce=false
fi
healthy=false
send_webhook "# :warning: DNS resolution\n\nDNS resolution returned no IPs when resolving $NAME_TO_CHECK"
else
if [ "$healthy" = false ]; then
alert_debounce=false
fi
healthy=true
send_webhook "# :white_check_mark: DNS resolution\n\nDNS resolution is OK!"
fi
sleep $TEST_FREQUENCY
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment