You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
2.3 KiB
Bash
105 lines
2.3 KiB
Bash
#!/bin/sh
|
|
|
|
###############################################################
|
|
# CONSTANTS
|
|
###############################################################
|
|
|
|
STATE_OK=0
|
|
STATE_WARNING=1
|
|
STATE_CRITICAL=2
|
|
STATE_UNKNOWN=3
|
|
STATE_DEPENDENT=4
|
|
|
|
###############################################################
|
|
# PARAMETER PARSING
|
|
###############################################################
|
|
|
|
usage1="Usage: $0 -h [host] -p [port] -testurl [testurl] -testtime [testtime] -fcsubscribe [fcsubscribe_yn]"
|
|
|
|
exitstatus=$STATE_WARNING #default
|
|
while test -n "$1"; do
|
|
case "$1" in
|
|
-h)
|
|
host=$2
|
|
shift
|
|
;;
|
|
-p)
|
|
port=$2
|
|
shift
|
|
;;
|
|
-testurl)
|
|
testurl=$2
|
|
shift
|
|
;;
|
|
-testtime)
|
|
testtime=$2
|
|
shift
|
|
;;
|
|
-fcsubscribe)
|
|
fcsubscribe=$2
|
|
shift
|
|
;;
|
|
*)
|
|
echo "Unknown argument: $1"
|
|
echo $usage1;
|
|
exit $STATE_UNKNOWN
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
|
|
###############################################################
|
|
# CHECK PARAMETERS
|
|
###############################################################
|
|
|
|
function checkParam
|
|
{
|
|
if [[ -z $1 ]]; then
|
|
echo $usage1
|
|
exit $STATE_UNKNOWN
|
|
fi
|
|
}
|
|
|
|
checkParam $host
|
|
checkParam $port
|
|
checkParam $testurl
|
|
checkParam $testtime
|
|
checkParam $fcsubscribe
|
|
|
|
###############################################################
|
|
# ACTUAL CODE EXECUTION
|
|
###############################################################
|
|
|
|
TEMPFILE=/tmp/.tmp-$RANDOM-$RANDOM-$RANDOM-$RANDOM.tmp
|
|
|
|
STATUS_CODE=$(2>&1 curl --silent -w "%{http_code}" -o $TEMPFILE http://$host:$port/check?url=$testurl\&time=$testtime\&fcsubscribe=$fcsubscribe)
|
|
|
|
###############################################################
|
|
# RETURN STATUS CODE
|
|
###############################################################
|
|
|
|
if [[ $STATUS_CODE -eq 000 ]]; then
|
|
echo WARNING - Unable to communicate with StreamPulse host
|
|
exit $STATE_WARNING
|
|
fi
|
|
|
|
cat $TEMPFILE
|
|
rm -f $TEMPFILE
|
|
|
|
if [[ $STATUS_CODE -eq 404 ]]; then
|
|
exit $STATE_WARNING
|
|
fi
|
|
|
|
if [[ $STATUS_CODE -eq 500 ]]; then
|
|
exit $STATE_CRITICAL
|
|
fi
|
|
|
|
if [[ $STATUS_CODE -eq 200 ]]; then
|
|
exit $STATE_OK;
|
|
fi
|
|
|
|
if [[ $STATUS_CODE -eq 503 ]]; then
|
|
exit $STATE_WARNING
|
|
fi
|