From bd40b276d83e7d86e397a0fb67816bab7e60cdc6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zden=C4=9Bk=20=C5=A0ustr?= Date: Thu, 6 Oct 2011 13:20:13 +0000 Subject: [PATCH] Simple cmd-line based nagios probe test --- org.glite.testsuites.ctb/LB/tests/lb-run-tests.sh | 1 + .../LB/tests/lb-test-nagios-probe.sh | 139 +++++++++++++++++++++ org.glite.testsuites.ctb/LB/tests/test-common.sh | 2 + 3 files changed, 142 insertions(+) create mode 100755 org.glite.testsuites.ctb/LB/tests/lb-test-nagios-probe.sh diff --git a/org.glite.testsuites.ctb/LB/tests/lb-run-tests.sh b/org.glite.testsuites.ctb/LB/tests/lb-run-tests.sh index b58cebb..fedf97e 100755 --- a/org.glite.testsuites.ctb/LB/tests/lb-run-tests.sh +++ b/org.glite.testsuites.ctb/LB/tests/lb-run-tests.sh @@ -214,6 +214,7 @@ echo sh ./lb-test-changeacl.sh \$OUTPUT_OPT >> arrange_lb_test_user.sh echo sh ./lb-test-statistics.sh \$OUTPUT_OPT >> arrange_lb_test_user.sh echo sh ./lb-test-threaded.sh \$OUTPUT_OPT >> arrange_lb_test_user.sh echo sh ./lb-test-harvester.sh \$OUTPUT_OPT >> arrange_lb_test_user.sh +echo sh ./lb-test-nagios-probe.sh \$OUTPUT_OPT >> arrange_lb_test_user.sh echo perl ./lb-test-purge.pl --i-want-to-purge $remotehost:9000 \$OUTPUT_OPT >> arrange_lb_test_user.sh echo 'echo ""' >> arrange_lb_test_user.sh echo 'echo ""' >> arrange_lb_test_user.sh diff --git a/org.glite.testsuites.ctb/LB/tests/lb-test-nagios-probe.sh b/org.glite.testsuites.ctb/LB/tests/lb-test-nagios-probe.sh new file mode 100755 index 0000000..48b06ba --- /dev/null +++ b/org.glite.testsuites.ctb/LB/tests/lb-test-nagios-probe.sh @@ -0,0 +1,139 @@ +#!/bin/bash +# +# Copyright (c) Members of the EGEE Collaboration. 2004-2010. +# See http://www.eu-egee.org/partners for details on the copyright holders. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# show help and usage +progname=`basename $0` +showHelp() +{ +cat << EndHelpHeader +Script for testing correct job registration + +Prerequisities: + - LB server + - environment variables set: + + GLITE_WMS_QUERY_SERVER + +Tests called: + + L&B's nagios probe + +Returned values: + Exit TEST_OK: Test Passed + Exit TEST_ERROR: Test Failed + Exit 2: Wrong Input + +EndHelpHeader + + echo "Usage: $progname [OPTIONS]" + echo "Options:" + echo " -h | --help Show this help message." + echo " -o | --output 'file' Redirect all output to the 'file' (stdout by default)." + echo " -t | --text Format output as plain ASCII text." + echo " -c | --color Format output as text with ANSI colours (autodetected by default)." + echo " -x | --html Format output as html." +} + +# read common definitions and functions +COMMON=lb-common.sh +if [ ! -r ${COMMON} ]; then + printf "Common definitions '${COMMON}' missing!" + exit 2 +fi +source ${COMMON} + +logfile=$$.tmp +flag=0 +while test -n "$1" +do + case "$1" in + "-h" | "--help") showHelp && exit 2 ;; + "-o" | "--output") shift ; logfile=$1 flag=1 ;; + "-t" | "--text") setOutputASCII ;; + "-c" | "--color") setOutputColor ;; + "-x" | "--html") setOutputHTML ;; + esac + shift +done + +# redirecting all output to $logfile +touch $logfile +if [ ! -w $logfile ]; then + echo "Cannot write to output file $logfile" + exit $TEST_ERROR +fi + +DEBUG=2 + +## +# Starting the test +##################### + +{ +test_start + + +printf "Checking if the probe is available..." + +PROBE="$GLITE_LOCATION/usr/libexec/grid-monitoring/probes/emi.lb/LB-probe" + +if [ -f "$PROBE" ]; then + test_done + + # check_binaries + printf "Testing if all binaries are available" + check_binaries $GRIDPROXYINFO $SYS_GREP $SYS_SED $SYS_AWK $SYS_CAT + if [ $? -gt 0 ]; then + test_failed + else + test_done + fi + + printf "Testing credentials" + check_credentials_and_generate_proxy + if [ $? != 0 ]; then + test_end + exit 2 + fi + + printf "Running the nagios probe..." + PROBEOUTPUT=`${PROBE} -H $GLITE_WMS_QUERY_SERVER 2> /dev/null` + PROBECODE=$? + + printf " \"$PROBEOUTPUT\", ret. code $PROBECODE" + $SYS_ECHO $PROBEOUTPUT | $SYS_GREP -E "^OK" > /dev/null 2> /dev/null + if [ $? -eq 0 -a $PROBECODE -eq 0 ]; then + test_done + else + if [ "$PROBEOUTPUT" != "" -a $PROBECODE -ne 0 ]; then + test_warning + else + test_failed + fi + fi + +else + printf " Probe not available" + test_skipped +fi + +test_end +} + +exit $TEST_OK + diff --git a/org.glite.testsuites.ctb/LB/tests/test-common.sh b/org.glite.testsuites.ctb/LB/tests/test-common.sh index 2befda6..520fb27 100644 --- a/org.glite.testsuites.ctb/LB/tests/test-common.sh +++ b/org.glite.testsuites.ctb/LB/tests/test-common.sh @@ -80,6 +80,7 @@ test_running="${spacefill}${begin_green}running${end_green}" test_failed="${spacefill}${begin_red}-TEST FAILED-${end_red}" test_missed="${spacefill}${begin_red}missing${end_red}" test_skipped="${spacefill}${begin_yellow}skipped${end_yellow}" +test_warning="${spacefill}${begin_yellow}warning${end_yellow}" test_dead="${spacefill}${begin_red}dead${end_red}" test_unused="${spacefill}${begin_bold}unused${end_bold}" test_unknown="${spacefill}${begin_yellow}unknown${end_yellow}" @@ -93,6 +94,7 @@ function test_running() { printf "${test_running}${lf}"; } function test_failed() { printf "${test_failed}${lf}"; } function test_missed() { printf "${test_missed}${lf}"; } function test_skipped() { printf "${test_skipped}${lf}"; } +function test_warning() { printf "${test_warning}${lf}"; } function test_dead() { printf "${test_dead}${lf}"; } function test_unused() { printf "${test_unused}${lf}"; } function test_unknown { printf "${test_unknown}${lf}"; } -- 1.8.2.3