forked from ssangyongsport/statsigstatus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
health-check.sh
67 lines (60 loc) · 1.75 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
# 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 read -r line
do
echo " $line"
IFS='=' read -ra TOKENS <<< "$line"
KEYSARRAY+=(${TOKENS[0]})
URLSARRAY+=(${TOKENS[1]})
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)
if [ "$response" -eq 200 ] || [ "$response" -eq 202 ] || [ "$response" -eq 301 ] || [ "$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 4000 last log entries. Feel free to modify this to meet your needs.
echo "$(tail -4000 logs/${key}_report.log)" > "logs/${key}_report.log"
else
echo " $dateTime, $result"
fi
done
if [[ $commit == true ]]
then
# Let's make Vijaye the most productive person on GitHub.
git config --global user.name 'Vijaye Raji'
git config --global user.email '[email protected]'
git add -A --force logs/
git commit -am '[Automated] Update Health Check Logs'
git push
fi