-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwazzup-web.sh
executable file
·39 lines (30 loc) · 943 Bytes
/
wazzup-web.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
#!/bin/bash
TOKEN=<bot_token>
CHAT_ID=<chat_id>
API=https://api.telegram.org/bot$TOKEN/sendMessage
SERVER=<web_url>
LOG_FILE=<path_to_log_file>
LOG_LINES=10
MESSAGE_HEAD='SERVER IS DOWN!'
AVAILABLE_STATUS_CODE='200|301'
DATE=`date +"%m.%d.%Y"`
TIME=`date +"%H:%M:%S"`
STATUS=`wget --spider -S $SERVER 2>&1 | grep "HTTP/" | awk '{print $2,$3,$4}'`
LOG=`tail -n $LOG_LINES $LOG_FILE`
MESSAGE="${MESSAGE_HEAD}
----------------------------------------------------
Date : ${DATE}
Time : ${TIME}
----------------------------------------------------
Server : ${SERVER}
Status : ${STATUS}
----------------------------------------------------
Log :
${LOG}
----------------------------------------------------"
if curl -s --head --request GET $SERVER | grep -E $AVAILABLE_STATUS_CODE > /dev/null; then
echo "Server is UP"
else
curl -s -X POST $API -d chat_id=$CHAT_ID -d text="$MESSAGE"
echo "Server is DOWN"
fi