From 35d75853eca8dc28dee31dfd268d92b7797af5a4 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Thu, 28 Nov 2024 12:35:15 -0700 Subject: [PATCH] check_curl: fix "echo: write error: Broken pipe" --- check_curl.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/check_curl.sh b/check_curl.sh index 4d38c14..e00ce92 100755 --- a/check_curl.sh +++ b/check_curl.sh @@ -16,7 +16,7 @@ usage() { -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. - -S Sanitize HTML when printing to console. Good for Icinga2 Web. + -S Sanitize HTML when printing to console. Good for Icinga2 Web. (not functional) -n Don't return any perfdata if the status code was not 200. -a Specify the username and password for authentication in the format username:password" exit 3 @@ -443,16 +443,16 @@ fi BODY_CONTAINS="" if [ -n "$CRIT_STRING" ]; then BODY=$(curl -s $FOLLOW_REDIRECTS $INSECURE $HEADERS $RESOLVE $TIMEOUT $AUTHENTICATION "$URL") - if ! echo "$BODY" | grep -Fq "$CRIT_STRING"; then - if $SANITIZE_HTML; then - BODY=$(echo "$BODY" | sed 's//\>/g') - fi - CRIT_STRING_MSG="response body does not contain the required string" - ERROR_MSG="${ERROR_MSG}${CRIT_STRING_MSG}; " - EXIT_CODE=2 - else - BODY_CONTAINS=", and contained substring" - fi + if ! grep -Fq "$CRIT_STRING" <<< "$BODY"; then + # if $SANITIZE_HTML; then + # BODY=$(echo "$BODY" | sed 's//\>/g') + # fi + CRIT_STRING_MSG="response body does not contain the required string" + ERROR_MSG="${ERROR_MSG}${CRIT_STRING_MSG}; " + EXIT_CODE=2 + else + BODY_CONTAINS=", and contained substring" + fi fi # Prepare perfdata_str