-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtargetgroups.go
110 lines (98 loc) · 3.75 KB
/
targetgroups.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"encoding/json"
"log"
"github.com/aws/aws-sdk-go/service/elbv2"
)
type targetGroupList struct {
*elbv2.DescribeTargetGroupsOutput
}
type targetGroupNodes []targetGroupNode
type targetGroupNode struct {
UID string `json:"uid,omitempty"`
Type []string `json:"dgraph.type,omitempty"`
Name string `json:"name,omitempty"` // This field is only for Ratel Viz
Region string `json:"Region,omitempty"`
OwnerID string `json:"OwnerId,omitempty"`
OwnerName string `json:"OwnerName,omitempty"`
Service string `json:"Service,omitempty"`
TargetGroupArn string `json:"TargetGroupArn,omitempty"`
TargetGroupName string `json:"TargetGroupName,omitempty"`
TargetType string `json:"TargetType,omitempty"`
HealthCheckPath string `json:"HealthCheckPath,omitempty"`
HealthCheckProtocol string `json:"HealthCheckProtocol,omitempty"`
HealthCheckPort string `json:"HealthCheckPort,omitempty"`
HealthyThresholdCount int64 `json:"HealthCheckIntervalSeconds,omitempty"`
Port int64 `json:"Port,omitempty"`
UnhealthyThresholdCount int64 `json:"UnhealthyThresholdCount,omitempty"`
Protocol string `json:"Protocol,omitempty"`
Vpc vpcNode `json:"_Vpc,omitempty"`
LoadBalancer loadBalancerNodes `json:"_LoadBalancer,omitempty"`
}
func (c *connector) listTargetGroups() targetGroupList {
defer c.waitGroup.Done()
log.Println("List TargetGroups")
response, err := elbv2.New(c.awsSession).DescribeTargetGroups(&elbv2.DescribeTargetGroupsInput{})
if err != nil {
log.Fatal(err)
}
return targetGroupList{response}
}
func (list targetGroupList) addNodes(c *connector) {
defer c.waitGroup.Done()
if len(list.TargetGroups) == 0 {
return
}
log.Println("Add TargetGroup Nodes")
a := make(targetGroupNodes, 0, len(list.TargetGroups))
for _, i := range list.TargetGroups {
var b targetGroupNode
b.Service = "elbv2"
b.Region = c.awsRegion
b.OwnerID = c.awsAccountID
b.OwnerName = c.awsAccountName
b.Type = []string{"TargetGroup"}
b.Name = *i.TargetGroupName
b.TargetGroupName = *i.TargetGroupName
b.TargetGroupArn = *i.TargetGroupArn
b.TargetType = *i.TargetType
if i.HealthCheckPath != nil {
b.HealthCheckPath = *i.HealthCheckPath
b.HealthCheckProtocol = *i.HealthCheckProtocol
b.HealthCheckPort = *i.HealthCheckPort
b.HealthyThresholdCount = *i.HealthyThresholdCount
b.UnhealthyThresholdCount = *i.UnhealthyThresholdCount
}
b.Port = *i.Port
b.Protocol = *i.Protocol
a = append(a, b)
}
c.dgraphAddNodes(a)
c.stats.NumberOfNodes += len(a)
m := make(map[string]targetGroupNodes)
n := make(map[string]string)
json.Unmarshal(c.dgraphQuery("TargetGroup"), &m)
for _, i := range m["list"] {
n[i.TargetGroupArn] = i.UID
}
c.ressources["TargetGroups"] = n
}
func (list targetGroupList) addEdges(c *connector) {
defer c.waitGroup.Done()
if len(list.TargetGroups) == 0 {
return
}
log.Println("Add TargetGroup Edges")
a := targetGroupNodes{}
for _, i := range list.TargetGroups {
b := targetGroupNode{
UID: c.ressources["TargetGroups"][*i.TargetGroupArn],
Vpc: vpcNode{UID: c.ressources["Vpcs"][*i.VpcId]},
}
for _, i := range i.LoadBalancerArns {
b.LoadBalancer = append(b.LoadBalancer, loadBalancerNode{UID: c.ressources["LoadBalancersV2"][*i]})
}
a = append(a, b)
}
c.dgraphAddNodes(a)
}