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

Merge branch 'add-systemdunit' into 'master'

check_http - handle empty response

See merge request !164
parents 1798e040 42c2576f
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
SYNTAX:
$_self [-h]
$_self [-m METHOD] -u URL \\
$_self [-m METHOD] -u URL [-c PARAMS]\\
[-b REGEX] [-j FILTER] [-n REGEX] \\
[-r REGEX] \\
[-s STATUSCODE] \\
......@@ -48,7 +48,8 @@ PARAMETERS:
Define request:
-u URL Set url to fetch; eg. https://www.example.com/
-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:
-s STATUSCODE exact Statuscode to check; 3 digits; by default critical
......@@ -112,7 +113,7 @@ sNotInBody=$( ph.getValueWithParam '' n "$@")
sJq=$( ph.getValueWithParam '' j "$@")
sLabel=$( ph.getValueWithParam "" l "$@")
curlParams+=" -si -X $sMethod"
curlParams+=" -si -X $sMethod --connect-timeout 10"
sProblems=
sOK=
......@@ -123,11 +124,13 @@ if [ -z "$sUrl" ]; then
fi
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 )
# echo "$out" | grep -n ^$'\r'; echo "cut header and body on line $iHeaderEnd"
_header=$(echo "$out" | sed -n "1,${iHeaderEnd}p")
_body=$( echo "$out" | sed -n "${iHeaderEnd},\$p")
......@@ -135,10 +138,6 @@ if [ -n "$sJq" ]; then
_body=$( jq "$sJq" <<< "$_body" 2>/dev/null )
fi
# echo "HEADER"; echo "$_header"
# echo "BODY"; echo "$_body"
# --- test status
typeset -i iHttpStatus
iHttpStatus=$( grep -i "^HTTP/[0-9\.]* " <<< "${_header}" | awk '{ print $2 }')
......@@ -201,6 +200,8 @@ if [ -n "$sNotInBody" ]; then
fi
fi
# --- output
test -n "$sProblems" && sProblems="Problems:\n$sProblems\n"
test -n "$sOK" && sOK="Found:\n$sOK"
......@@ -211,8 +212,6 @@ test -n "$sLabel" && (
)
test -n "$sLabel" || ph.status "$sMethod $sUrl ($iHttpStatus)"
echo
echo Command: curl $curlParams "$sUrl"
echo
echo -e "${sProblems}${sOK}"
......
......@@ -47,7 +47,8 @@ PARAMETERS:
Define request:
-u URL Set url to fetch; eg. https://www.example.com/
-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:
-s STATUSCODE exact Statuscode to check; 3 digits; by default critical
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment