check_curl: add expected status code option
This commit is contained in:
parent
50e052f380
commit
1d1e7a486c
|
@ -15,6 +15,7 @@ usage() {
|
|||
-M Set the HTTP mode (default: GET)
|
||||
-t Timeout in seconds
|
||||
-s Ignore the response status code.
|
||||
-e Specify the exact response code that should be returned. Cannot be used with -s option.
|
||||
-e Expected status code.
|
||||
-S Sanitize HTML when printing to console. Good for Icinga2 Web.
|
||||
-n Don't return any perfdata if the status code was not 200."
|
||||
|
@ -67,6 +68,10 @@ while getopts "u:w:c:C:LH:M:IpR:st:e:hSn" opt; do
|
|||
RESOLVE="--resolve $OPTARG"
|
||||
;;
|
||||
s)
|
||||
if [ -n "$EXPECTED_STATUS_CODE" ]; then
|
||||
echo "Cannot use -s option with -e option"
|
||||
exit 3
|
||||
fi
|
||||
IGNORE_STATUS="yes"
|
||||
;;
|
||||
t)
|
||||
|
@ -87,6 +92,13 @@ while getopts "u:w:c:C:LH:M:IpR:st:e:hSn" opt; do
|
|||
n)
|
||||
DISABLE_PERFDATA=true
|
||||
;;
|
||||
e)
|
||||
if [ "$IGNORE_STATUS" = "yes" ]; then
|
||||
echo "Cannot use -e option with -s option"
|
||||
exit 3
|
||||
fi
|
||||
EXPECTED_STATUS_CODE="$OPTARG"
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
usage
|
||||
|
@ -399,11 +411,11 @@ perfdata="response_time=${RESPONSE_TIME_MS}ms;${WARN_TIME};${CRIT_TIME};0;"
|
|||
|
||||
# Check HTTP code
|
||||
if [ -n "$EXPECTED_STATUS_CODE" ]; then
|
||||
if [ "$HTTP_CODE" -ne "$EXPECTED_STATUS_CODE" ]; then
|
||||
if [ "$HTTP_CODE" != "$EXPECTED_STATUS_CODE" ]; then
|
||||
echo "CRITICAL - server returned HTTP code $HTTP_CODE, expected $EXPECTED_STATUS_CODE"
|
||||
exit 2
|
||||
fi
|
||||
elif [ "$IGNORE_STATUS" != "yes" ] && [ "$HTTP_CODE" -ne 200 ]; then
|
||||
elif [ "$IGNORE_STATUS" != "yes" ] && [ "$HTTP_CODE" != 200 ]; then
|
||||
echo "CRITICAL - server returned HTTP code $HTTP_CODE"
|
||||
exit 2
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue