From 2cfde1249c6bd92fa7033e9d7e14d2bd711a0e4b Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Wed, 6 Sep 2023 12:20:58 +0200 Subject: [PATCH] check_http update jq handling --- check_http | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/check_http b/check_http index 4888bbb..dbd64b1 100755 --- a/check_http +++ b/check_http @@ -115,6 +115,7 @@ sLabel=$( ph.getValueWithParam "" l "$@") curlParams+=" -si -X $sMethod --connect-timeout 10" sProblems= +sInfos= sOK= if [ -z "$sUrl" ]; then @@ -136,6 +137,13 @@ else if [ -n "$sJq" ]; then _body=$( jq "$sJq" <<< "$_body" 2>/dev/null ) + if [ -z "$_body" ]; then + ph.setStatus critical + sProblems+="- jq filter [$sJq] was applied and resulted in an empty result.\n" + else + sInfos+="- jq filter [$sJq] was applied.\n" + sInfos+="${_body}" + fi fi # --- test status @@ -205,6 +213,7 @@ fi # --- output test -n "$sProblems" && sProblems="Problems:\n$sProblems\n" test -n "$sOK" && sOK="Found:\n$sOK" +test -n "$sInfos" && sInfos="\nHints:\n$sInfos" test -n "$sLabel" && ( ph.status "$sLabel" @@ -213,7 +222,7 @@ test -n "$sLabel" && ( test -n "$sLabel" || ph.status "$sMethod $sUrl ($iHttpStatus)" echo -echo -e "${sProblems}${sOK}" +echo -e "${sProblems}${sOK}${sInfos}" test -n "${sProblems}" && (echo "RESPONSE HEADER:"; echo; echo "$_header") -- GitLab