Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main-src > by-pkgid > e536fc0c6270ec1d92a0fd41bb1f8360 > files > 56

rgmanager-2.0.52-28.el5_8.2.src.rpm

From 73afe8a5a6b08b5ff57b70927716942a2e6d2c49 Mon Sep 17 00:00:00 2001
From: Lon Hohberger <lhh@redhat.com>
Date: Fri, 4 Jun 2010 18:54:21 -0400
Subject: [PATCH] resource-agents: Add RHEVM status program

Resolves: rhbz#583788

Signed-off-by: Lon Hohberger <lhh@redhat.com>
---
 rgmanager/src/utils/Makefile         |    6 +++-
 rgmanager/src/utils/rhev-check.sh.in |   55 ++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletions(-)
 create mode 100644 rgmanager/src/utils/rhev-check.sh.in

diff --git a/rgmanager/src/utils/Makefile b/rgmanager/src/utils/Makefile
index 4cc16a9..6f04f90 100644
--- a/rgmanager/src/utils/Makefile
+++ b/rgmanager/src/utils/Makefile
@@ -22,7 +22,7 @@ CFLAGS+= -DPACKAGE_VERSION=\"${RELEASE}\"
 
 LDFLAGS+= -L${libdir} -L../../../cman/lib -L../../../ccs/lib -lcman -lpthread -ldl -lncurses -L../clulib -lclulib -lccs
 
-TARGETS=clubufflush clufindhostname clustat clusvcadm clulog clunfslock
+TARGETS=clubufflush clufindhostname clustat clusvcadm clulog clunfslock rhev-check.sh
 
 all: ${TARGETS}
 
@@ -55,6 +55,10 @@ clunfslock: clunfslock.sh
 	cp clunfslock.sh clunfslock
 	chmod 755 clunfslock
 
+rhev-check.sh: rhev-check.sh.in
+	cp rhev-check.sh.in rhev-check.sh
+	chmod 755 rhev-check.sh
+
 clean:
 	rm -f *.o $(TARGETS)
 
diff --git a/rgmanager/src/utils/rhev-check.sh.in b/rgmanager/src/utils/rhev-check.sh.in
new file mode 100644
index 0000000..7baad17
--- /dev/null
+++ b/rgmanager/src/utils/rhev-check.sh.in
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+MYNAME=`basename $0`
+
+do_log()
+{
+	declare severity=$1
+
+	shift
+	echo "<$severity> $*"
+	clulog -l 6 -n "$MYNAME" -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=$(((5 - 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
+		echo 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
-- 
1.6.2.5