From 1dff832d86960de619cd7169621bfa31508ede0b Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Wed, 6 Sep 2023 12:32:00 +0200
Subject: [PATCH] update jq filtering

---
 check_http | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/check_http b/check_http
index dbd64b1..3cfa1d2 100755
--- a/check_http
+++ b/check_http
@@ -135,14 +135,20 @@ else
     _header=$(echo "$out" | sed -n "1,${iHeaderEnd}p")
     _body=$(  echo "$out" | sed -n "${iHeaderEnd},\$p")
 
+    # --- jq filter
     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"
+            sProblems+="- jq filter [$sJq] was applied and resulted in an empty result. The reponse from url was no JSON.\n"
         else
-            sInfos+="- jq filter [$sJq] was applied.\n"
-            sInfos+="${_body}"
+            if [ "$_body" = "null" ]; then
+                ph.setStatus critical
+                sProblems+="- jq filter [$sJq] does not match on responded JSON.\n"
+            else
+                sOK+="- jq filter [$sJq] matches.\n"
+                sInfos+="Content aufter jq filter: ${_body}"
+            fi
         fi
     fi
 
-- 
GitLab