From 3e804ec345925094202098daa3c60846ebe96a4a Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 10 Jan 2021 01:17:57 +1030 Subject: [PATCH] Added dns-down.sh --- dns-down.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 dns-down.sh diff --git a/dns-down.sh b/dns-down.sh new file mode 100644 index 0000000..b3739cf --- /dev/null +++ b/dns-down.sh @@ -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