Last active
October 18, 2016 09:00
-
-
Save andypotanin/e1876800b56acc63c462 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Check all response codes for Docker containers. | |
## | |
## | |
## source <(curl -s https://gist.githubusercontent.com/andypotanin/e1876800b56acc63c462/raw) | |
function app.check { | |
for app in $( docker ps -q -f=status=running ); do | |
_hostname=$(docker inspect -f '{{ .Config.Hostname }}' $app); | |
_domainname=$(docker inspect -f '{{ .Config.Domainname }}' $app); | |
_name=$(docker inspect -f '{{ .Name }}' $app); | |
#_code=$(curl --max-time 10 --silent --output /dev/null -H "X-Forwarded-Proto:https" -H 'host:${_hostname}.${_domainname}' -w "%{http_code}" $(docker port $app 80)); | |
#echo "curl -X HEAD --max-time 10 --silent --output /dev/null -H "X-Forwarded-Proto:https" -H 'host:${_hostname}' -w "%{http_code}" $(docker port $app 80)" | |
_code=$(curl -X HEAD --max-time 10 --silent --output /dev/null -L \ | |
-H "Connection: close" \ | |
-H "X-Request-Type: varnish-probe" \ | |
-H "X-Forwarded-Proto:https" \ | |
-H "host:${_hostname}" \ | |
-w "%{http_code}" $(docker port ${_name} 80)); | |
#echo "Code: [${_code}]." | |
## No response, e.g. Nginx down. | |
if [ "${_code}" == "000" ]; then | |
echo -e " * \e[1;31m [$_code] \e[0m - ${_name} (TCP Failure)" | |
fi | |
if [ "${_code}" == "500" ] || [ "${_code}" == "502" ]; then | |
echo -e " * \e[1;34m [$_code] \e[0m - ${_name} " | |
fi | |
if [ "${_code}" == "200" ]; then | |
echo -e " * \e[1;32m [$_code] \e[0m - ${_name} " | |
fi | |
if [ "${_code}" == "302" ]; then | |
echo -e " * \e[1;32m [$_code] \e[0m - ${_name} " | |
# echo -e " * \e[1;34m [$_code] \e[0m - ${_name} " | |
fi; | |
if [ "${_code}" == "301" ]; then | |
echo -e " * \e[1;32m [$_code] \e[0m - ${_name} " | |
# echo -e " * \e[1;34m [$_code] \e[0m - ${_name} " | |
fi; | |
done | |
} | |
#app.check |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment