summaryrefslogtreecommitdiffstats
path: root/rgmanager/src/resources/utils/rhev-check.sh
blob: 0529c31e214d1556bd6f76358421a0ca7b47f0d6 (plain)
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
#!/bin/sh

MYNAME=`basename $0`

do_log()
{
	declare severity=$1

	shift
	echo "<$severity> $*"
	clulog -s $severity "$*"
}

if [ -z "$1" ]; then
	do_log 4 No host specified.
	exit 1
fi

do_log 6 "Checking RHEV status on $1"

tries=3
http_code=

while [ $tries -gt 0 ]; do

	# Record start/end times so we can calculate the difference
	start_time=$(date +%s)
	http_code="$(curl -m 10 -sk https://$1/RHEVManagerWeb/HealthStatus.aspx -D - | head -1 | cut -f2 -d' ')"

	if [ "$http_code" = "200" ]; then
		exit 0
	fi

	# Reduce sleep time if the attempt took a noticeable amount
	# of time.
	end_time=$(date +%s)
	delta=$(((end_time - start_time)))
	sleep_time=$(((90 - delta)))

	((tries-=1))

	# if we're going to retry and we have a nonzero sleep time,
	# go to sleep.
	if [ $tries -gt 0 ] && [ $sleep_time -gt 0 ]; then
		sleep $sleep_time
	fi
done

if [ -n "$http_code" ]; then
	do_log 3 "RHEV Status check on $1 failed; last HTTP code: $http_code"
else
	do_log 3 "RHEV Status check on $1 failed"
fi

exit 1