Skip to content

Commit

Permalink
Add fix for trusted advisor metadata coming in unexpected order (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish25 authored Sep 2, 2021
1 parent 8bad266 commit e4e07f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## v0.1.2 ( 9 August 2021)
## v0.1.4 ( 1 September 2021)

* Add fix for trusted advisor metadata coming in unexpected order

## v0.1.3 ( 9 August 2021)

* Add --exclude-regions option to health command
* Add --include-regions option to health command
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.3
v0.1.4
25 changes: 21 additions & 4 deletions pkg/cloudig/trustedadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,27 @@ func processTrustedAdvisorResults(results map[*support.TrustedAdvisorCheckDescri
for _, resource := range result.FlaggedResources {
if resource.Metadata != nil {
if !awslocal.SdkStringContains(resource.Metadata, aws.String("Green")) && aws.BoolValue(resource.IsSuppressed) == false {
flaggedResource := aws.StringValue(resource.Metadata[1])
if aws.StringValue(resource.Metadata[2]) != "" && aws.StringValue(check.Metadata[1]) == "Region" {
flaggedResourceMeta := aws.StringValue(resource.Metadata[2])
flaggedResource = strings.Join([]string{flaggedResource, flaggedResourceMeta}, "/")
var flaggedResource string
// if not region, important flagged resource will be in field 1
if len(resource.Metadata) > 1 {
flaggedResource = aws.StringValue(resource.Metadata[1])
} else if len(resource.Metadata) == 1 {
// only pick metadata 0 if no other option
flaggedResource = aws.StringValue(resource.Metadata[0])
}

// clarify which region flaggedResource is part of
regionIndex := -1
for i, metadata := range check.Metadata {
// Convers Region and Region/AZ and other variations
if strings.Contains(aws.StringValue(metadata), "Region") {
regionIndex = i
break
}
}
if regionIndex > -1 && len(resource.Metadata) >= (regionIndex+1) && aws.StringValue(resource.Metadata[regionIndex]) != "" {
// important resource is after region in metadata
flaggedResource = strings.Join([]string{aws.StringValue(resource.Metadata[regionIndex]), aws.StringValue(resource.Metadata[regionIndex+1])}, "/")
}
finding.FlaggedResources = append(finding.FlaggedResources, flaggedResource)
}
Expand Down

0 comments on commit e4e07f3

Please sign in to comment.