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"],
|
# "users": ["oleg"],
|
||||||
# "type": "cloud",
|
# "type": "cloud",
|
||||||
# "ssh_port": 7822,
|
# "ssh_port": 7822,
|
||||||
# # "to_check": "No"
|
# # "to_check": false
|
||||||
|
# "timeout_sec": 5
|
||||||
# },
|
# },
|
||||||
|
|
||||||
RootDir="${HOME}/prod"
|
RootDir="${HOME}/prod"
|
||||||
@ -46,6 +47,7 @@ function host_alert() {
|
|||||||
User=oleg
|
User=oleg
|
||||||
Hosts=()
|
Hosts=()
|
||||||
DEFAULT_SSH_PORT=22
|
DEFAULT_SSH_PORT=22
|
||||||
|
DEFAULT_TIMEOUT=5
|
||||||
Domains=("${Domains[@]}" "$(get_domains)")
|
Domains=("${Domains[@]}" "$(get_domains)")
|
||||||
|
|
||||||
for Domain in ${Domains[@]} ; do
|
for Domain in ${Domains[@]} ; do
|
||||||
@ -56,16 +58,22 @@ for Host in ${Hosts[@]} ; do
|
|||||||
host=$(echo $Host | cut -d'.' -f1)
|
host=$(echo $Host | cut -d'.' -f1)
|
||||||
Domain=$(echo $Host | cut -d'.' -f2-)
|
Domain=$(echo $Host | cut -d'.' -f2-)
|
||||||
|
|
||||||
ToCheck=$(echo "$HOSTS_CONFIG" | jq -r --arg domain "$Domain" --arg host "$host" '.[$domain][$host].to_check // "Yes"')
|
# ToCheck=$(echo "$HOSTS_CONFIG" | jq -r --arg domain "$Domain" --arg host "$host" '.[$domain][$host].to_check // "Yes"')
|
||||||
if [ "${ToCheck^^}" == "NO" ]; then
|
# 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
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PortSSH=$(echo "$HOSTS_CONFIG" | jq -r --arg domain "$Domain" --arg host "$host" '.[$domain][$host].ssh_port // '"$DEFAULT_SSH_PORT"'')
|
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"
|
echo "Checking host: $Host on port $PortSSH"
|
||||||
|
|
||||||
# Use nc to check if the specified port is open
|
# 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"
|
echo "Host $Host is not available on port $PortSSH"
|
||||||
host_alert "Host $Host is not available on port $PortSSH"
|
host_alert "Host $Host is not available on port $PortSSH"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user