-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitore.sh
126 lines (95 loc) · 4 KB
/
monitore.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
set -euo pipefail
DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
. "$DIR/custom-setup.sh"
STATUS_WEBSITE="https://status.dysnomia.studio"
# ==========================
# Services list
# ==========================
declare -A ServicesWithOkCode;
declare -A ServicesWithNotFoundCode;
### Websites/Webservices
# Achieve.games
ServicesWithOkCode["https://achieve.games"]='."Websites / Webservices"."Achieve.games"'
# Achieve.games
ServicesWithOkCode["https://alchemistry-leaderboard.dysnomia.studio/leaderboard/game"]='."Websites / Webservices"."Alchemistry Leaderboard"'
# Dehash.me
ServicesWithOkCode["https://dehash.me"]='."Websites / Webservices"."Dehash.me"'
# Dysnomia
ServicesWithOkCode["https://dysnomia.studio"]='."Websites / Webservices"."Dysnomia"'
# Galactae
ServicesWithOkCode["https://galactae.eu"]='."Websites / Webservices"."Galactae - Website"'
ServicesWithOkCode["https://galactae.com"]='."Websites / Webservices"."Galactae - Website"'
ServicesWithOkCode["https://galactae.space"]='."Websites / Webservices"."Galactae - Website"'
ServicesWithOkCode["https://00-dev.galactae.eu"]='."Websites / Webservices"."Galactae - Dev Client"'
ServicesWithNotFoundCode["https://00-srv.galactae.eu"]='."Websites / Webservices"."Galactae - Dev Server"'
ServicesWithOkCode["https://01-milkyway.galactae.eu"]='."Websites / Webservices"."Galactae - Milkyway Client"'
ServicesWithNotFoundCode["https://01-srv.galactae.eu"]='."Websites / Webservices"."Galactae - Milkyway Server"'
### CDN
ServicesWithOkCode["https://01.cdn.elanis.eu/portfolio/img/Elanis.png"]='."CDN"."Elanis"'
ServicesWithOkCode["https://cdn.galactae.eu"]='."CDN"."Galactae"'
### Services
ServicesWithOkCode["https://bugs.dysnomia.studio"]='."Services"."Bug Tracker"'
### Nodes
declare -A Nodes
#Nodes["https://helium.dysnomia.studio"]='."Nodes"."Helium"'
Nodes["https://lithium.dysnomia.studio"]='."Nodes"."Lithium"'
Nodes["https://beryllium.dysnomia.studio"]='."Nodes"."Beryllium"'
# ==========================
# Script
# DO NOT EDIT BELOW THIS LINE
# ==========================
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
check_website () {
domainName=$(echo $1 | awk -F[/:] '{print $4}')
ip=$(dig +short $domainName @1.1.1.1 | tail -n 1)
curl --resolve "$domainName:443:$ip" --user-agent "Dysnomia-monitoring" -s -o /dev/null -w "%{http_code}" $1
}
check_website_insecure () {
domainName=$(echo $1 | awk -F[/:] '{print $4}')
ip=$(dig +short $domainName @1.1.1.1 | tail -n 1)
curl --resolve "$domainName:443:$ip" --insecure --user-agent "Dysnomia-monitoring" -s -o /dev/null -w "%{http_code}" $1
}
setStatus () {
jq -c "$1 = \"$2\"" "$SCRIPT_DIR/status.json" > tmp.status.json && mv tmp.status.json "$SCRIPT_DIR/status.json"
}
if [ $(check_website "$STATUS_WEBSITE") != "200" ]; then
echo "Error: Cannot reach internet !";
exit -1;
fi
for service in "${!ServicesWithOkCode[@]}"
do
echo "Checking $service ..."
if [ $(check_website "$service") != "200" ]; then
echo "$service not ok !";
setStatus "${ServicesWithOkCode[$service]}" "down"
else
setStatus "${ServicesWithOkCode[$service]}" "up"
fi
done
for service in "${!ServicesWithNotFoundCode[@]}"
do
echo "Checking $service ..."
if [ $(check_website "$service") != "404" ]; then
echo "$service not ok !";
setStatus "${ServicesWithNotFoundCode[$service]}" "down"
else
setStatus "${ServicesWithNotFoundCode[$service]}" "up"
fi
done
for node in "${!Nodes[@]}"
do
echo "Checking $node ..."
let httpCode=$(check_website_insecure "$node")
echo "Http code: $httpCode"
if [ "$httpCode" != "302" ] && [ "$httpCode" != "404" ]; then
echo "$node not ok !";
setStatus "${Nodes[$node]}" "down"
else
setStatus "${Nodes[$node]}" "up"
fi
done
cd "$SCRIPT_DIR"
git add status.json
git commit -m "Automatic monitoring update - $(date)";
git push -u origin master