update check_curl

This commit is contained in:
Cyberes 2024-03-30 21:22:09 -06:00
parent c1fb13bad0
commit 2c014863db
1 changed files with 16 additions and 4 deletions

View File

@ -16,7 +16,8 @@ usage() {
-t Timeout in seconds -t Timeout in seconds
-s Ignore the response status code. -s Ignore the response status code.
-e Expected status code. -e Expected status code.
-S Sanitize HTML when printing to console. Good for Icinga2 Web." -S Sanitize HTML when printing to console. Good for Icinga2 Web.
-n Don't return any perfdata if the status code was not 200."
exit 3 exit 3
} }
@ -33,9 +34,10 @@ TIMEOUT="30"
HTTP_METHOD="-X GET" HTTP_METHOD="-X GET"
EXPECTED_STATUS_CODE="" EXPECTED_STATUS_CODE=""
SANITIZE_HTML=false SANITIZE_HTML=false
DISABLE_PERFDATA=false
# Parse arguments # Parse arguments
while getopts "u:w:c:C:LH:M:IpR:st:e:hS" opt; do while getopts "u:w:c:C:LH:M:IpR:st:e:hSn" opt; do
case $opt in case $opt in
u) u)
URL="$OPTARG" URL="$OPTARG"
@ -82,6 +84,9 @@ while getopts "u:w:c:C:LH:M:IpR:st:e:hS" opt; do
S) S)
SANITIZE_HTML=true SANITIZE_HTML=true
;; ;;
n)
DISABLE_PERFDATA=true
;;
*) *)
echo "Invalid option: -$OPTARG" >&2 echo "Invalid option: -$OPTARG" >&2
usage usage
@ -415,7 +420,7 @@ fi
# Check critical string # Check critical string
BODY_CONTAINS=" " BODY_CONTAINS=" "
if [ -n "$CRIT_STRING" ]; then if [ -n "$CRIT_STRING" ]; then
BODY=$(curl -s $FOLLOW_REDIRECTS $INSECURE $HEADERS $RESOLVE $TIMEOUT $URL) BODY=$(curl -s $FOLLOW_REDIRECTS $INSECURE "$HEADERS" "$RESOLVE" "$TIMEOUT" "$URL")
# shellcheck disable=SC2076 # shellcheck disable=SC2076
if ! [[ $BODY =~ "$CRIT_STRING" ]]; then if ! [[ $BODY =~ "$CRIT_STRING" ]]; then
if $SANITIZE_HTML; then if $SANITIZE_HTML; then
@ -429,5 +434,12 @@ if [ -n "$CRIT_STRING" ]; then
fi fi
# All checks passed # All checks passed
echo "OK - response time was $RESPONSE_TIME seconds, code $HTTP_CODE.${BODY_CONTAINS}-> $URL | $perfdata"
if $DISABLE_PERFDATA && [ "$HTTP_CODE" != 200 ]; then
perfdata_str=""
else
perfdata_str="| $perfdata"
fi
echo "OK - response time was $RESPONSE_TIME seconds, code $HTTP_CODE.${BODY_CONTAINS}-> $URL $perfdata_str"
exit 0 exit 0