This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
/
elbv2.go
106 lines (86 loc) · 2.7 KB
/
elbv2.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
package awsdata
import (
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/elbv2"
"github.com/manywho/awsinventory/internal/inventory"
"github.com/sirupsen/logrus"
)
const (
// AssetTypeALB is the value used in the AssetType field when fetching ALBs
AssetTypeALB string = "ALB"
// AssetTypeNLB is the value used in the AssetType field when fetching NLBs
AssetTypeNLB string = "NLB"
// AssetTypeGLB is the value used in the AssetType field when fetching GLBs
AssetTypeGLB string = "GLB"
// ServiceELBV2 is the key for the ELBV2 service
ServiceELBV2 string = "elbv2"
)
func (d *AWSData) loadELBV2s(region string) {
defer d.wg.Done()
elbv2Svc := d.clients.GetELBV2Client(region)
log := d.log.WithFields(logrus.Fields{
"region": region,
"service": ServiceELBV2,
})
log.Info("loading data")
var loadBalancers []*elbv2.LoadBalancer
done := false
params := &elbv2.DescribeLoadBalancersInput{}
for !done {
out, err := elbv2Svc.DescribeLoadBalancers(params)
if err != nil {
log.Errorf("failed to describe load balancers: %s", err)
return
}
loadBalancers = append(loadBalancers, out.LoadBalancers...)
if out.NextMarker == nil {
done = true
} else {
params.Marker = out.NextMarker
}
}
log.Info("processing data")
for _, l := range loadBalancers {
var assettype string
if aws.StringValue(l.Type) == "application" {
assettype = AssetTypeALB
} else if aws.StringValue(l.Type) == "network" {
assettype = AssetTypeNLB
} else if aws.StringValue(l.Type) == "gateway" {
assettype = AssetTypeGLB
}
var public bool
if aws.StringValue(l.Scheme) == "internet-facing" {
public = true
} else if aws.StringValue(l.Scheme) == "internal" {
public = false
}
var ips []string
for _, az := range l.AvailabilityZones {
for _, lbAddress := range az.LoadBalancerAddresses {
if aws.StringValue(lbAddress.IpAddress) != "" {
ips = append(ips, aws.StringValue(lbAddress.IpAddress))
}
if aws.StringValue(lbAddress.IPv6Address) != "" {
ips = append(ips, aws.StringValue(lbAddress.IPv6Address))
}
if aws.StringValue(lbAddress.PrivateIPv4Address) != "" {
ips = append(ips, aws.StringValue(lbAddress.PrivateIPv4Address))
}
}
}
d.rows <- inventory.Row{
UniqueAssetIdentifier: aws.StringValue(l.LoadBalancerName),
IPv4orIPv6Address: strings.Join(ips, "\n"),
Virtual: true,
Public: public,
DNSNameOrURL: aws.StringValue(l.DNSName),
Location: region,
AssetType: assettype,
SerialAssetTagNumber: aws.StringValue(l.LoadBalancerArn),
VLANNetworkID: aws.StringValue(l.VpcId),
}
}
log.Info("finished processing data")
}