1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| IFS=$'\n' PROFILE=default REGION=us-east-1 for tg in $(aws --profile=$PROFILE --region=$REGION elbv2 describe-target-groups | jq -r '.TargetGroups[] | "\(.TargetGroupName) \(.TargetGroupArn) \(.LoadBalancerArns)"'); do tg_name=$(echo $tg | awk '{print $1}') tg_arn=$(echo $tg | awk '{print $2}') tg_lb_arns=$(echo $tg | awk '{print $3}')
if [ $(echo $tg_lb_arns | jq -r '. | length') -eq 0 ]; then continue fi
tg_targets=$(aws --profile=$PROFILE --region=$REGION elbv2 describe-target-health --target-group-arn $tg_arn) tg_targets_len=$(echo $tg_targets | jq -r '.TargetHealthDescriptions | length') if [ $tg_targets_len -eq 0 ]; then echo "tg_name: $tg_name" echo "tg_lb_arns: $tg_lb_arns" echo "tg_targets_len: $tg_targets_len" echo "--------------------------------" fi
echo $tg_targets | jq -r '.TargetHealthDescriptions[] | .TargetHealth.State' | grep -q "healthy" if [ $? -ne 0 ]; then echo "tg_name: $tg_name" echo "tg_lb_arns: $tg_lb_arns" echo "tg_targets_len: $tg_targets_len" echo "--------------------------------" fi done
|