-
Notifications
You must be signed in to change notification settings - Fork 0
/
health-check.sh
74 lines (63 loc) · 1.9 KB
/
health-check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# In the original repository we'll just print the result of status checks,
# without committing. This avoids generating several commits that would make
# later upstream merges messy for anyone who forked us.
commit=true
origin=$(git remote get-url origin)
if [[ $origin == *statsig-io/statuspage* ]]
then
commit=false
fi
KEYSARRAY=()
URLSARRAY=()
urlsConfig="./urls.cfg"
echo "Reading $urlsConfig"
while IFS='=' read -r key url
do
# Trim any leading/trailing whitespaces
key=$(echo "$key" | xargs)
url=$(echo "$url" | xargs)
# Skip empty lines or lines without a valid URL
if [[ -n "$key" && -n "$url" ]]; then
echo "Key: $key, URL: $url"
KEYSARRAY+=("$key")
URLSARRAY+=("$url")
fi
done < "$urlsConfig"
echo "***********************"
echo "Starting health checks with ${#KEYSARRAY[@]} configs:"
mkdir -p logs
for (( index=0; index < ${#KEYSARRAY[@]}; index++))
do
key="${KEYSARRAY[index]}"
url="${URLSARRAY[index]}"
echo "===> $key=$url"
for i in 1 2 3 4;
do
response=$(curl --write-out '%{http_code}' --silent --output /dev/null $url)
echo $response
if [[ "$key" == "gis" ]]; then
title=$(curl -H "referer: $REFERER" -H "X-Esri-Authorization: Bearer $GIS_TOKEN" -s $url)
if [[ "$title" =~ [eE]rror ]]; then
response=500
fi
fi
if [ "$response" -eq 200 ] || [ "$response" -eq 202 ] || [ "$response" -eq 301 ] || [ "$response" -eq 302 ] || [ "$response" -eq 307 ]; then
result="success"
else
result="failed"
fi
if [ "$result" = "success" ]; then
break
fi
sleep 5
done
dateTime=$(date +'%Y-%m-%d %H:%M')
if [[ $commit == true ]]
then
echo $dateTime, $result >> "logs/${key}_report.log"
# By default we keep 2000 last log entries. Feel free to modify this to meet your needs.
echo "$(tail -2000 logs/${key}_report.log)" > "logs/${key}_report.log"
else
echo " $dateTime, $result"
fi
done