-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckWebServer.sh
36 lines (31 loc) · 1.4 KB
/
checkWebServer.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
#!/bin/bash
touch checkWebServers.txt
nameServer=(google.com amazon.fr)
publicNames=(GOOGLE AMAZON)
for i in "${!nameServer[@]}"
do
response=$(curl -sL -w %{http_code} -I https://${nameServer[$i]} -o /dev/null --connect-timeout 25 -m 25)
if [ "$response" != "200" ] && [ "$response" != "403" ] && [ "$response" != "503" ]
then
response2=$(curl -sL -w %{http_code} -I https://${nameServer[$i]} -o /dev/null --connect-timeout 25 -m 25)
if [ "$response2" != "200" ] && [ "$response2" != "403" ] && [ "$response2" != "503" ]
then
# fail part
if [[ "$(cat checkWebServers.txt)" != *"-$i-"* ]]
then
curl --location --request POST 'https://api.telegram.org/bot<Bot ID>/sendMessage' \
--header 'Content-Type: application/json' \
--data-raw '{"chat_id" : "-<Chat ID>","text" : "/!\\Server Emergency :/!\\\nWeb Service '"${publicNames[$i]}"' is down!\nFurther investigation need to be done"}'
echo -n "-$i-" >> checkWebServers.txt
fi
fi
else
if [[ "$(cat checkWebServers.txt)" == *"-$i-"* ]]
then
curl --location --request POST 'https://api.telegram.org/bot<Bot ID>/sendMessage' \
--header 'Content-Type: application/json' \
--data-raw '{"chat_id" : "-<Chat ID>","text" : "Web Service '"${publicNames[$i]}"' is back online!"}'
echo -n "$(cat checkWebServers.txt | sed "s/-$i-//g")" > checkWebServers.txt
fi
fi
done