Added dns-down.sh
This commit is contained in:
parent
17d10ddaad
commit
3e804ec345
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Dependencies: curl, openssl, dig
|
||||
|
||||
dns_server=1.1.1.1 # DNS server to test query
|
||||
dns_port=53 # DNS UDP port (Default is 53)
|
||||
gotify_server="https://push.gotify.example" # Gotify server address (including http:// or https://)
|
||||
gotify_api_key="###############" # Gotify server application token for this script
|
||||
|
||||
# To do: Add sanity checks for the configuration variables
|
||||
# Stateful notifications (only send one notification when it goes down, one when it comes backup up, and reminders every x hours)
|
||||
# Log notification push errors to ~/.offline_error and print them at login with .bashrc
|
||||
|
||||
|
||||
# First argument is the message to be pushed, second argument is the message priority (integer from 0 to 10, 0 being low priority and 10 being high)
|
||||
gotify_send () {
|
||||
if [ "$2" -ge 0 ] && [ "$2" -le 10 ]; then # Message priority integer sanity check. Default to 5 on failure.
|
||||
priority=$2
|
||||
else
|
||||
>&2 echo "\"$2\" isn't a valid priority. Defaulting priority to 5."
|
||||
priority=5
|
||||
fi
|
||||
curl -s -X POST "$gotify_server/message?token=$gotify_api_key" -F "title=Message from: $HOSTNAME" -F "message=$1" -F "priority=$priority"
|
||||
return $?
|
||||
}
|
||||
|
||||
|
||||
if dig @$dns_server -p $dns_port google.com > /dev/null ; then # Default timeout is 5 seconds
|
||||
exit 0
|
||||
else
|
||||
gotify_send "DNS Server $dns_server#$dns_port isn't responding to queries" 4
|
||||
exit 1
|
||||
fi
|
Loading…
Reference in New Issue