check_local_elasticsearch_service.sh: chnage --max-timeout and --connect-timeout for curl request.

This commit is contained in:
Christoph 2023-04-21 11:10:50 +02:00
parent bb87b9c2b8
commit 90fa1d507e
2 changed files with 54 additions and 14 deletions

View File

@ -189,6 +189,8 @@ reboot_system() {
#
DEFAULT_NUMBER_LINES=20
DEFAULT_TIME_OUT=20
DEFAULT_CONNECT_TIMEOUT=5
DEFAULT_LOCAL_ES_SERVICE_TO_CHECK="http://127.0.0.1:9200"
#DEFAULT_CONFLICTING_SCRIPTS="/root/bin/monitoring/check_webservice_load.sh"
@ -211,12 +213,18 @@ done
[[ -n "$content_type" ]] || content_type='Content-Type: text/plain;\n charset="utf-8"'
[[ -n "$TIME_OUT" ]] || TIME_OUT=$DEFAULT_TIME_OUT
TIME_OUT_MAX="$(expr ${TIME_OUT} + 5)"
[[ -n "$CONNECT_TIMEOUT" ]] || CONNECT_TIMEOUT=$DEFAULT_CONNECT_TIMEOUT
#[[ -n "$CONFLICTING_SCRIPTS" ]] || CONFLICTING_SCRIPTS="$DEFAULT_CONFLICTING_SCRIPTS"
[[ -n "$CONFLICTING_SCRIPTS" ]] || CONFLICTING_SCRIPTS=""
[[ -n "$LOCAL_ES_SERVICE_TO_CHECK" ]] || LOCAL_ES_SERVICE_TO_CHECK="${DEFAULT_LOCAL_ES_SERVICE_TO_CHECK}"
CURL_COMMAND="curl -I --max-time $TIME_OUT --connect-timeout $CONNECT_TIMEOUT $LOCAL_ES_SERVICE_TO_CHECK"
# -------------
# --- Check some prerequisites
# -------------
@ -343,17 +351,32 @@ ES_SERVICE_DOWN=false
if [[ -n "$LOCAL_ES_SERVICE_TO_CHECK" ]] ; then
echo ""
echo "$CURL_COMMAND"
echo ""
echononl "Check local Elasticsearch service \033[1m$LOCAL_ES_SERVICE_TO_CHECK\033[m .."
declare -i i=0
while [[ $i -lt 3 ]] ; do
response="$(curl --max-time $TIME_OUT_MAX --connect-timeout $TIME_OUT \
-I -k -L --write-out %{http_code} --silent --output /dev/null $LOCAL_ES_SERVICE_TO_CHECK \
2> ${LOCK_DIR}/error.log)"
# 200 - OK
if [[ $response -eq 200 ]] ; then
# response="$(curl --max-time $TIME_OUT_MAX --connect-timeout $TIME_OUT \
# -I -k -L --write-out %{http_code} --silent --output /dev/null $LOCAL_ES_SERVICE_TO_CHECK \
# 2> ${LOCK_DIR}/error.log)"
#
# # 200 - OK
# if [[ $response -eq 200 ]] ; then
# echo_ok
# if [[ -f "$RESTART_CHECK_FILE" ]] ; then
# rm -f "$RESTART_CHECK_FILE"
# fi
# clean_up 0
# fi
#if $(curl -I --max-time $TIME_OUT --connect-timeout $CONNECT_TIMEOUT $LOCAL_ES_SERVICE_TO_CHECK 2> /dev/null \
# | grep -q -E "200 OK"> /dev/null 2>&1) ; then
if $(${CURL_COMMAND} 2> /dev/null | grep -q -E "200 OK" 2> /dev/null) ; then
echo_ok
if [[ -f "$RESTART_CHECK_FILE" ]] ; then
rm -f "$RESTART_CHECK_FILE"
@ -580,3 +603,4 @@ if $LOGGING ; then
echo ""
fi
clean_up 0

View File

@ -10,6 +10,30 @@
# -
#LOCAL_ES_SERVICE_TO_CHECK=""
# - TIME_OUT
# -
# - Maximum time in seconds that is aalowed for the whole curl request
# -
# - Defaults to:
# TIME_OUT=20
# -
#TIME_OUT=20
# - CONNECT_TIMEOUT
# -
# - Maximum time in seconds that you allow curl's connection to take.
# -
# - Note:
# - This only limits the connection phase, so if curl connects within
# - the given period it will continue - if not it will exit.
# -
# - Defaults to:
# - CONNECT_TIMEOUT=5
# -
#CONNECT_TIMEOUT=5
# - LOG_FILES_TO_MONITOR[:<n>]
# -
# - Print out the last lines from theses given logfiles
@ -27,14 +51,6 @@
# -
#LOG_FILES_TO_MONITOR=""
# - TIME_OUT
# -
# - Timeout for curl request of each website
# -
# - Defaults to: TIME_OUT=20
# -
#TIME_OUT=20
# - CONFLICTING_SCRIPTS
# -