services avalability check

This commit is contained in:
Oleg Sheynin 2024-10-31 17:21:25 -04:00
parent 1387893a14
commit c699fe437d
3 changed files with 60 additions and 24 deletions

View File

@ -1 +1 @@
1.7.6.fx1,host avalability check
1.7.7,services avalability check

View File

@ -72,26 +72,3 @@ for Host in ${Hosts[@]} ; do
host_alert "Host $Host is not available on port $PortSSH"
fi
done
# for Domain in $DOMAINS; do
# echo "Processing domain: $Domain"
# for host in $HOSTS; do
# # Construct the fully qualified hostname
# FQHN="${host}.${Domain}"
# # Get SSH port for the host, or use default if not specified
# SSH_PORT=$(echo "$JSON_CONFIG" | jq -r --arg domain "$Domain" --arg host "$host" '.[$domain][$host].ssh_port // '"$DEFAULT_SSH_PORT"'')
# echo "Checking host: $FQHN on port $SSH_PORT"
# # Use nc to check if the specified port is open
# if nc -z -w5 "$FQHN" "$SSH_PORT"; then
# echo "Host $FQHN is available on port $SSH_PORT"
# else
# echo "Host $FQHN is not available on port $SSH_PORT"
# fi
# echo "----------------------------------------"
# done

View File

@ -0,0 +1,59 @@
#!/bin/bash
# "Jenkins" {
# "to_check": "Yes",
# "protocol": "http",
# "host": "cvtt-build.cvtt.vpn",
# "port": 8080
# },
RootDir="${HOME}/prod"
# RootDir=/home/oleg/develop/cvtt2 ###### D E B U G
AlertChannel=Alerts-CVTT
Sender=${RootDir}/ops/utils/send_mmost.sh
ConfigUrl=http://cloud23.cvtt.vpn:6789/admin/cvtt_services
SERVICES_CONFIG=$(curl -s ${ConfigUrl} | ${HOME}/bin/hjson -j)
echo $Sender
echo $AlertChannel
function service_alert() {
alert="${1}"
if [ "${alert}" != "" ]
then
#it may contain quotes
alert=$(echo "${alert}" | sed 's/"/\\"/g')
echo -e "### :boom: SERVICE ALERT\n${alert}" | ${Sender} ${AlertChannel}
fi
}
User=oleg
Hosts=()
DEFAULT_TO_CHECK=Yes
mapfile -t SvcNames < <(echo ${SERVICES_CONFIG} | jq -r '. | keys[]')
DEFAULT_TO_CHECK=Yes
for SvcName in "${SvcNames[@]}" ; do
echo "SvcName=$SvcName"
ToCheck=$(echo "$SERVICES_CONFIG" | jq -r --arg svcname "$SvcName" '.[$svcname].to_check // "Yes"')
if [ "${ToCheck}" == "No" ]; then
continue
fi
Host=$(echo "$SERVICES_CONFIG" | jq -r --arg svcname "$SvcName" '.[$svcname].host ')
Port=$(echo "$SERVICES_CONFIG" | jq -r --arg svcname "$SvcName" '.[$svcname].port ')
echo "Checking \"$SvcName\" (${Host}:${Port})"
# Use nc to check if the specified port is open
if ! nc -z -w5 "$Host" "$Port"; then
msg="Service \"${SvcName}\" (${Host}:${Port}) is not available"
echo ${msg}
service_alert "${msg}"
fi
done