-
Notifications
You must be signed in to change notification settings - Fork 4
/
lb.go
52 lines (44 loc) · 1.29 KB
/
lb.go
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/elbv2"
"github.com/juju/loggo"
)
// logging
var lbLogger = loggo.GetLogger("lb")
type LB struct{}
func (l *LB) getTargets() ([]string, error) {
var targets []string
svc := elbv2.New(session.New())
input := &elbv2.DescribeTargetGroupsInput{}
pageNum := 0
err := svc.DescribeTargetGroupsPages(input,
func(page *elbv2.DescribeTargetGroupsOutput, lastPage bool) bool {
pageNum++
for _, target := range page.TargetGroups {
targets = append(targets, aws.StringValue(target.TargetGroupArn))
}
return pageNum <= 20
})
if err != nil {
autoscalingLogger.Errorf(err.Error())
}
return targets, nil
}
func (l *LB) getTargetHealth(targetGroupArn string) (map[string]string, error) {
targetHealth := make(map[string]string)
svc := elbv2.New(session.New())
input := &elbv2.DescribeTargetHealthInput{
TargetGroupArn: aws.String(targetGroupArn),
}
result, err := svc.DescribeTargetHealth(input)
if err != nil {
lbLogger.Errorf("%v", err.Error())
return targetHealth, err
}
for _, target := range result.TargetHealthDescriptions {
targetHealth[aws.StringValue(target.Target.Id)] = aws.StringValue(target.TargetHealth.State)
}
return targetHealth, nil
}