LoginSignup
0
1

More than 5 years have passed since last update.

[AWS]ELBの状態を取得したい

Last updated at Posted at 2017-02-07

一発でELBの状態を取得したかったので、作ってみました。
ぶら下がっているEC2の詳細情報は前回の記事で作ったEC2取得ワンライナーの出力結果
から取得するようにしてるので、もっと良い方法があれば教えてください

echo "++++ ELB info ++++" 
    aws --profile ${_title} --region ${_region} elb describe-load-balancers | jq -r '.LoadBalancerDescriptions[]|("ELB-DNSName : " + .DNSName + " ELBName : " + .LoadBalancerName ,.Instances[])' | sed 's/{//g' | sed 's/}//g' | sed '/^$/d' | sed 's/"InstanceId"://' |\
    while read line
    do
      echo $line | grep "^ELB-DNSName :"
         if [ $? = 1 ]
         then
              _host=`echo $line| cut -d '"' -f 2`
              _data=`grep $_host /home/ec2-user/.output/${_title}_ec2 | sed 's/ - /-/g' | awk -F" " '{if($6 == NULL){printf "%-61s %-21s %-15s %-15s\n", $2,$3,$4,$5}else{printf "%-38s %-21s %-15s %-15s %-15s\n", $2,$3,$4,$5,$6}}'`
              _health=`aws --profile ${_title} --region ${_region} elb describe-instance-health --load-balancer-name $_elb_name --instances $_host | jq -r '.InstanceStates[]|("State : " + .State)'`
              echo -e "\t$line  ${_data}${_health} "
         else
              echo $line
              _elb_name=`echo $line | awk '{print $6}'`
         fi

      done

出力されると以下のようにぶら下がっている風な感じで出力されます
(もっとかっこいい出力の仕方を考えています。。。)

++++ ELB info ++++
ELB-DNSName : test-33333.ap-northeast-1.elb.amazonaws.com ELBName : test
        "i-000000000000000"  test-test                         52.xxx.xxx.xxx        10.xxx.xxx.xxx    t2.xxx        running        State : InService
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1