check_dns: use system default DNS server if none was provided
This commit is contained in:
parent
3fd8751595
commit
f6ad41298e
17
check_dns.sh
17
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 <dns_server> -d <query_domain> -w <warning_time> -c <critical_time>"
|
||||
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;"
|
||||
|
|
Loading…
Reference in New Issue