host checking improving
This commit is contained in:
parent
10105ad639
commit
8510226599
@ -1 +1 @@
|
||||
1.8.7,prepare equity simulation data
|
||||
1.8.8,host checking improving
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user