diff --git a/release_version.txt b/release_version.txt index d4892f3..b2720c5 100644 --- a/release_version.txt +++ b/release_version.txt @@ -1 +1 @@ -1.8.7,prepare equity simulation data +1.8.8,host checking improving diff --git a/scripts/healthcheck/hosts_check.sh b/scripts/healthcheck/hosts_check.sh index 2b3f44c..2b3f265 100755 --- a/scripts/healthcheck/hosts_check.sh +++ b/scripts/healthcheck/hosts_check.sh @@ -5,7 +5,8 @@ # "users": ["oleg"], # "type": "cloud", # "ssh_port": 7822, -# # "to_check": "No" +# # "to_check": false +# "timeout_sec": 5 # }, RootDir="${HOME}/prod" @@ -46,6 +47,7 @@ function host_alert() { User=oleg Hosts=() DEFAULT_SSH_PORT=22 +DEFAULT_TIMEOUT=5 Domains=("${Domains[@]}" "$(get_domains)") for Domain in ${Domains[@]} ; do @@ -56,16 +58,22 @@ for Host in ${Hosts[@]} ; do host=$(echo $Host | cut -d'.' -f1) Domain=$(echo $Host | cut -d'.' -f2-) - ToCheck=$(echo "$HOSTS_CONFIG" | jq -r --arg domain "$Domain" --arg host "$host" '.[$domain][$host].to_check // "Yes"') - if [ "${ToCheck^^}" == "NO" ]; then + # ToCheck=$(echo "$HOSTS_CONFIG" | jq -r --arg domain "$Domain" --arg host "$host" '.[$domain][$host].to_check // "Yes"') + # if [ "${ToCheck^^}" == "NO" ]; then + # continue + # fi + ToCheck=$(echo "$HOSTS_CONFIG" | jq -r --arg domain "$Domain" --arg host "$host" '.[$domain][$host].to_check // true') + if [ "$ToCheck" != "true" ]; then continue fi + PortSSH=$(echo "$HOSTS_CONFIG" | jq -r --arg domain "$Domain" --arg host "$host" '.[$domain][$host].ssh_port // '"$DEFAULT_SSH_PORT"'') + Timeout=$(echo "$HOSTS_CONFIG" | jq -r --arg domain "$Domain" --arg host "$host" '.[$domain][$host].timeout_sec // '"$DEFAULT_TIMEOUT"'') echo "Checking host: $Host on port $PortSSH" # Use nc to check if the specified port is open - if ! nc -z -w5 "$Host" "$PortSSH"; then + if ! nc -z -w ${Timeout} "$Host" "$PortSSH"; then echo "Host $Host is not available on port $PortSSH" host_alert "Host $Host is not available on port $PortSSH" fi