Skip to content

Instantly share code, notes, and snippets.

@fradee
Created April 8, 2020 17:45
Show Gist options
  • Save fradee/f201e6a928854d602b5c737a890d9489 to your computer and use it in GitHub Desktop.
Save fradee/f201e6a928854d602b5c737a890d9489 to your computer and use it in GitHub Desktop.
#!/bin/bash -
PATH=/usr/bin
##################################################
# Check Internet access through the NAT gateway.
CHECK_URL="www.google.com"
PROTOCOL="https://"
http_response=$(curl --retry-delay 3 --retry 5 -sIf $PROTOCOL$CHECK_URL)
exit_code=$?
case $exit_code in
0)
http_status=$(echo $http_response | head -n 1 | awk '{print $2}')
;;
6)
http_status=" Couldn't resolve host"
;;
7)
http_status=" Failed to connect to host"
;;
22)
http_status=" HTTP page not retrieved"
;;
*)
http_status=" See official documentation"
;;
esac
##################################################
# Print output for consul dashboard
echo "CURL - Results of cheking connection to "$CHECK_URL" over AWS NAT Gateway:"
echo " -- CURL exit code: $exit_code"
echo " -- HTTP response code: $http_status"
if [[ $exit_code -ne 0 ]]; then traceroute -4 $CHECK_URL; fi
##################################################
# 0 = OK
# 1 = WARNING
if [[ $exit_code -ne 0 ]]; then exit 1; fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment