Skip to content
Snippets Groups Projects
Commit 4e62949f authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

check_hhtp - handle empty response

parent dc06fdb7
No related branches found
No related tags found
1 merge request!164check_http - handle empty response
...@@ -33,7 +33,7 @@ Additionally you can verify the response by ...@@ -33,7 +33,7 @@ Additionally you can verify the response by
SYNTAX: SYNTAX:
$_self [-h] $_self [-h]
$_self [-m METHOD] -u URL \\ $_self [-m METHOD] -u URL [-c PARAMS]\\
[-b REGEX] [-j FILTER] [-n REGEX] \\ [-b REGEX] [-j FILTER] [-n REGEX] \\
[-r REGEX] \\ [-r REGEX] \\
[-s STATUSCODE] \\ [-s STATUSCODE] \\
...@@ -48,7 +48,8 @@ PARAMETERS: ...@@ -48,7 +48,8 @@ PARAMETERS:
Define request: Define request:
-u URL Set url to fetch; eg. https://www.example.com/ -u URL Set url to fetch; eg. https://www.example.com/
-m METHOD Set a method, eg. HEAD; default: GET -m METHOD Set a method, eg. HEAD; default: GET
-c PARAMS additional curl params -c PARAMS additional curl params; curl will be executed
with '[PARAMS] -si -X [METHOD] --connect-timeout 10 [URL]'
What to check: What to check:
-s STATUSCODE exact Statuscode to check; 3 digits; by default critical -s STATUSCODE exact Statuscode to check; 3 digits; by default critical
...@@ -112,7 +113,7 @@ sNotInBody=$( ph.getValueWithParam '' n "$@") ...@@ -112,7 +113,7 @@ sNotInBody=$( ph.getValueWithParam '' n "$@")
sJq=$( ph.getValueWithParam '' j "$@") sJq=$( ph.getValueWithParam '' j "$@")
sLabel=$( ph.getValueWithParam "" l "$@") sLabel=$( ph.getValueWithParam "" l "$@")
curlParams+=" -si -X $sMethod" curlParams+=" -si -X $sMethod --connect-timeout 10"
sProblems= sProblems=
sOK= sOK=
...@@ -123,11 +124,13 @@ if [ -z "$sUrl" ]; then ...@@ -123,11 +124,13 @@ if [ -z "$sUrl" ]; then
fi fi
out=$( curl $curlParams "$sUrl" ) out=$( curl $curlParams "$sUrl" )
if [ -z "$out" ]; then
ph.setStatus critical
sProblems+="- Url [${sUrl}] not reachable - response is empty;\n"
iHttpStatus='???'
else
iHeaderEnd=$( echo "$out" | grep -n ^$'\r' | cut -f 1 -d ':' | head -1 ) iHeaderEnd=$( echo "$out" | grep -n ^$'\r' | cut -f 1 -d ':' | head -1 )
# echo "$out" | grep -n ^$'\r'; echo "cut header and body on line $iHeaderEnd"
_header=$(echo "$out" | sed -n "1,${iHeaderEnd}p") _header=$(echo "$out" | sed -n "1,${iHeaderEnd}p")
_body=$( echo "$out" | sed -n "${iHeaderEnd},\$p") _body=$( echo "$out" | sed -n "${iHeaderEnd},\$p")
...@@ -135,10 +138,6 @@ if [ -n "$sJq" ]; then ...@@ -135,10 +138,6 @@ if [ -n "$sJq" ]; then
_body=$( jq "$sJq" <<< "$_body" 2>/dev/null ) _body=$( jq "$sJq" <<< "$_body" 2>/dev/null )
fi fi
# echo "HEADER"; echo "$_header"
# echo "BODY"; echo "$_body"
# --- test status # --- test status
typeset -i iHttpStatus typeset -i iHttpStatus
iHttpStatus=$( grep -i "^HTTP/[0-9\.]* " <<< "${_header}" | awk '{ print $2 }') iHttpStatus=$( grep -i "^HTTP/[0-9\.]* " <<< "${_header}" | awk '{ print $2 }')
...@@ -201,6 +200,8 @@ if [ -n "$sNotInBody" ]; then ...@@ -201,6 +200,8 @@ if [ -n "$sNotInBody" ]; then
fi fi
fi
# --- output # --- output
test -n "$sProblems" && sProblems="Problems:\n$sProblems\n" test -n "$sProblems" && sProblems="Problems:\n$sProblems\n"
test -n "$sOK" && sOK="Found:\n$sOK" test -n "$sOK" && sOK="Found:\n$sOK"
...@@ -211,8 +212,6 @@ test -n "$sLabel" && ( ...@@ -211,8 +212,6 @@ test -n "$sLabel" && (
) )
test -n "$sLabel" || ph.status "$sMethod $sUrl ($iHttpStatus)" test -n "$sLabel" || ph.status "$sMethod $sUrl ($iHttpStatus)"
echo
echo Command: curl $curlParams "$sUrl"
echo echo
echo -e "${sProblems}${sOK}" echo -e "${sProblems}${sOK}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment