Skip to content

Instantly share code, notes, and snippets.

@larryclaman
Last active September 2, 2021 15:45
Show Gist options
  • Save larryclaman/0d679e2f845d479bbb5836e42fd2e9c8 to your computer and use it in GitHub Desktop.
Save larryclaman/0d679e2f845d479bbb5836e42fd2e9c8 to your computer and use it in GitHub Desktop.
Fixed polling.sh
#!/bin/bash
declare -i duration=10
declare hasUrl=""
declare endpoint
declare -i status200count=0
endpoint="https://openhack0cy6inq0poi-staging.azurewebsites.net/api/healthcheck/poi"
healthcheck() {
declare url=$1
result=$(curl --http1.1 -i $url 2>/dev/null | grep HTTP/1.1)
echo $result
}
for i in {1..12}
do
result=`healthcheck $endpoint`
declare status
if [[ -z $result ]]; then
status="N/A"
echo "Site not found"
else
status=${result:9:3}
timestamp=$(date "+%Y%m%d-%H%M%S")
if [[ -z $hasUrl ]]; then
echo "$timestamp | $status "
else
echo "$timestamp | $status | $endpoint "
fi
if [ $status -eq 200 ]; then
((status200count=status200count + 1))
if [ $status200count -gt 5 ]; then
break
fi
fi
sleep $duration
fi
done
if [ $status200count -gt 5 ]; then
echo "API UP"
# APISTATUS is a pipeline variable
APISTATUS="Up"
else
echo "API DOWN"
APISTATUS="Down"
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment