-
Notifications
You must be signed in to change notification settings - Fork 0
/
probe.sh
56 lines (35 loc) · 1.03 KB
/
probe.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
#!/bin/sh
sleep_time=10
IFS='
'
function print_log () {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
print_log "Starting the probe process"
if [ "$#" -ne 1 ]; then
print_log "Invalid endpoint. Usage: $0 <http-endpoint>"
exit 1
fi
endpoint=$1
domain=$(echo $endpoint | awk -F/ '{ print $3 }')
print_log "Target endpoint: $endpoint"
while [ 1 ]; do
print_log "Sending the probe"
print_log "Trying to resolve domain: $domain"
records=$(dig +short $domain)
records_len=$(echo $records | wc -w)
if [ $records_len -eq 0 ]; then
print_log "Domain could not be resolved"
fi
for record in $records; do
print_log "Record found: $record"
done
response=$(curl --max-time 5 --silent --output /dev/null --write-out "%{http_code}" "$endpoint")
if [ $response -eq 000 ]; then
print_log "Service not available"
else
print_log "HTTP response code: $response"
fi
print_log "Waiting for ${sleep_time}s before sending the next probe"
sleep $sleep_time
done