shell - 删除eureka上状态异常的节点

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"
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} == "OUT_OF_SERVICE" || ${status} == "DOWN" ]];then
        echo `date` ${status} curl -s -X DELETE http://${eureka_domain}/eureka/apps/${app}/${instanceId}
        curl -s -X DELETE http://${eureka_domain}/eureka/apps/${app}/${instanceId}
#    elif [[ ${status} == "DOWN" ]];then
#        http_code=$(curl -o /dev/null -s -w %{http_code} ${statusPageUrl})
#        if [[ ${http_code} != "200" ]];then
#            echo curl -s -X DELETE http://${eureka_domain}/eureka/apps/${app}/${instanceId}
##            curl -s -X DELETE http://${eureka_domain}/eureka/apps/${app}/${instanceId}
#        fi
    fi
done

标题:shell - 删除eureka上状态异常的节点
地址:https://blog.njqhome.com:8443/articles/2021/07/05/1625474026505.html