-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathisUpPingPong
More file actions
executable file
·61 lines (58 loc) · 1.71 KB
/
Copy pathisUpPingPong
File metadata and controls
executable file
·61 lines (58 loc) · 1.71 KB
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
#!/bin/bash
: ${URL_TO_WATCH:="http://dev.jhrb.us:8080"}
: ${WATCH_RESOLUTION:="2"}
[[ ! -z "${2}" ]] && WATCH_RESOLUTION=${2}
echo ${WATCH_RESOLUTION}
: ${URL_STARTED:="#othertools"} #Who needs to know the successful start?
: ${URL_FAILED:="@wizardofmath"} #Who needs to know when it fails?
if [ -z $SLACK_WEBHOOK_TOKEN ]; then
echo "Need a webhook token..." 2>&1
exit 0
fi
message(){
local MESSAGE=${2}
local SLACK_FROM=$(whoami)
local SLACK_TO=${1}
curl -s -X POST https://hooks.slack.com/services/${SLACK_WEBHOOK_TOKEN} -d "{ \"text\": \"${MESSAGE}\" , \"channel\": \"${SLACK_TO}\" , \"username\" : \"${SLACK_FROM}-Bot\" }"
}
isServerUp(){
COUNTER=0
while [[ "$(curl -s --max-time 1 ${URL_TO_WATCH}/ping)" != "pong" ]]
do
[[ $COUNTER -gt ${1} ]] && break
let COUNTER=COUNTER+1
sleep 1
done
if [[ "$(curl -s --max-time 1 ${URL_TO_WATCH}/ping)" == "pong" ]];then
return 0
else
return 1
fi
}
sendResponse(){
if [[ "${1}" == "0" ]];then
message ${URL_STARTED} "Server is running URL: ${URL_TO_WATCH} :+1:"
elif [[ "${1}" == "1" ]]
then
message ${URL_FAILED} "${URL_TO_WATCH} Is down! :-1:"
fi
}
if [[ "${1}" == "watch" ]]
then
message ${URL_STARTED} "I am watching ${URL_TO_WATCH} forever. \`RES:${WATCH_RESOLUTION}\`"
isServerUp ${WATCH_RESOLUTION}
WAS_UP=${?}
sendResponse ${WAS_UP}
while [[ 1 == 1 ]]
do
isServerUp ${WATCH_RESOLUTION}
UP=${?}
[[ "${WAS_UP}" != "${UP}" ]] && sendResponse ${UP}
WAS_UP=${UP}
sleep 5
done
else
message ${URL_STARTED} "I'll Let you know when ${URL_TO_WATCH} is up."
isServerUp 7200
sendResponse ${?}
fi