diff --git a/check_local_elasticsearch_service.sh b/check_local_elasticsearch_service.sh index 4191662..bd7c709 100755 --- a/check_local_elasticsearch_service.sh +++ b/check_local_elasticsearch_service.sh @@ -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 + diff --git a/conf/check_local_elasticsearch_service.conf.sample b/conf/check_local_elasticsearch_service.conf.sample index 7935f29..459302c 100644 --- a/conf/check_local_elasticsearch_service.conf.sample +++ b/conf/check_local_elasticsearch_service.conf.sample @@ -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[:] # - # - 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 # -