forked from mehatab/fettle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
health-check.sh
executable file
·69 lines (61 loc) · 1.81 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
#!/bin/bash
commit=true
origin=$(git remote get-url origin)
if [[ $origin == *statsig-io/statuspage* ]]
then
commit=false
fi
declare -a KEYSARRAY
declare -a URLSARRAY
urlsConfig="public/urls.cfg"
echo "Reading $urlsConfig"
while IFS='=' read -r key url
do
echo " $key=$url"
KEYSARRAY+=("$key")
URLSARRAY+=("$url")
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..3}
do
response=$(curl -o /dev/null -s -w '%{http_code} %{time_total}' --silent --output /dev/null "$url")
http_code=$(echo "$response" | cut -d ' ' -f 1)
time_total=$(echo "$response" | cut -d ' ' -f 2)
echo " $http_code $time_total"
if [ "$http_code" -eq 200 ] || [ "$http_code" -eq 202 ] || [ "$http_code" -eq 301 ] || [ "$http_code" -eq 302 ] || [ "$http_code" -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
mkdir -p public/status
echo "$dateTime, $result, $time_total" >> "public/status/${key}_report.log"
tail -2000 "public/status/${key}_report.log" > "public/status/${key}_report.log.tmp"
mv "public/status/${key}_report.log.tmp" "public/status/${key}_report.log"
else
echo " $dateTime, $result, $time_total"
fi
done
if [[ $commit == true ]]
then
echo "committing logs"
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add -A --force public/status/
git commit -am '[Automated] Update Health Check Logs'
git push
fi