shell - 删除eureka状态为UP,但实际不可用的节点

2022-12-21
#!/bin/bash
eureka_path="/tmp/eureka"
mkdir -p ${eureka_path}
eureka_info=${eureka_path}/info
eureka_domain="8999.pro.xxx.corp:8999"
#eureka_domain="192.168.10.14:8999"
timeout=1

function checkHttpCode() {
    for ((i=1;i<=3;i++))
    do
        http_code=$(curl -o /dev/null --connect-timeout ${timeout} -m ${timeout}  -s -w %{http_code} ${statusPageUrl})
        if [[ ${http_code} != "200" ]];then
            sleep 1
        else
            continue
        fi
        echo ${statusPageUrl} ${http_code}
    done
}

curl -s -H 'Content-Type:application/json' -H 'Accept:application/json' http://${eureka_domain}/eureka/apps | jq .applications.application| jq  '.[]|.instance' |jq -r '.[]' > ${eureka_info}


key_names="instanceId status app statusPageUrl healthCheckUrl"
for key_name in ${key_names}
do
    key_file=${eureka_path}/${key_name}
    cat ${eureka_info} | jq -r ".${key_name}" > ${eureka_path}/${key_name}
    old_files="${old_files} ${key_file}"
done
paste ${old_files} > ${eureka_path}/result

cat ${eureka_path}/result | while read line
do
    line=($line)
    instanceId=${line[0]}
    status=${line[1]}
    app=${line[2]}
    statusPageUrl=${line[3]}
    if [[ ${status} == "UP" ]];then
        if [[ ${app} == "RPA_MONITOR" || ${app} == "BL_NUM_SERVER" ]];then
            continue
        else
            checkHttpCode
            if [[ ${http_code} != "200" ]];then
                echo `date` ${statusPageUrl} ${http_code} curl -s -X DELETE http://${eureka_domain}/eureka/apps/${app}/${instanceId}
                curl -s -X DELETE http://${eureka_domain}/eureka/apps/${app}/${instanceId}
            fi
        fi
    fi
done

标题:shell - 删除eureka状态为UP,但实际不可用的节点
地址:https://blog.njqhome.com:8443/articles/2021/07/05/1625473986376.html