diff --git a/check_dns.sh b/check_dns.sh index cf108b7..848c543 100755 --- a/check_dns.sh +++ b/check_dns.sh @@ -1,7 +1,7 @@ #!/bin/bash # Default values -dns_server="1.1.1.1" +dns_server="" query_domain="" warning_time=200 critical_time=250 @@ -20,16 +20,23 @@ while getopts "s:d:w:c:" flag; do esac done -# Check if DNS server is provided -if [ -z "$dns_server" ]; then - echo "Error: DNS server not provided" +if [[ -z $query_domain && ${query_domain+x} ]]; then + echo "Error: query domain not provided." echo "Usage: $0 -s -d -w -c " exit 1 fi # Perform DNS resolution check and measure the time start_time=$(date +%s%N) -result=$(dig @$dns_server $query_domain +short) + +if [[ -z "$dns_server" ]]; then + # The DNS server was not provided. + result=$(dig "$query_domain" +short) + dns_server="the default server" +else + result=$(dig @$dns_server "$query_domain" +short) +fi + end_time=$(date +%s%N) response_time=$(((end_time - start_time) / 1000000)) perfdata="response_time=${response_time}ms;${warning_time};${critical_time};0;"