From f35671bdd76dcc9b50ae60d765c9bac0a5c66c84 Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Mon, 31 Aug 2020 07:29:46 -0600 Subject: [PATCH] Cherry-pick #20736 to 7.9: Fill cloud.account.name with accountID if account alias doesn't exist (#20835) * Fill cloud.account.name with accountID if account alias doesn't exist (#20736) * Fill cloud.account.name with accountID if account alias doesn't exist (cherry picked from commit bae7b381b0df69063344ccb7541bbbb7d8e058d6) --- CHANGELOG.next.asciidoc | 1 + x-pack/metricbeat/module/aws/aws.go | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index ffb111bd9b1..6daae9f746f 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -108,6 +108,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Updates vm_compute metricset with more info on guest metrics. {pull}20448[20448] - Add fallback for PdhExpandWildCardPathW failing in perfmon metricset. {issue}20139[20139] {pull}20630[20630] - Fix resource tags in aws cloudwatch metricset {issue}20326[20326] {pull}20385[20385] +- Fill cloud.account.name with accountID if account alias doesn't exist. {pull}20736[20736] *Packetbeat* diff --git a/x-pack/metricbeat/module/aws/aws.go b/x-pack/metricbeat/module/aws/aws.go index 983d44ee47b..1d7b059a2df 100644 --- a/x-pack/metricbeat/module/aws/aws.go +++ b/x-pack/metricbeat/module/aws/aws.go @@ -103,19 +103,24 @@ func NewMetricSet(base mb.BaseMetricSet) (*MetricSet, error) { default: awsConfig.Region = "us-east-1" } + svcIam := iam.New(awscommon.EnrichAWSConfigWithEndpoint( config.AWSConfig.Endpoint, "iam", "", awsConfig)) req := svcIam.ListAccountAliasesRequest(&iam.ListAccountAliasesInput{}) output, err := req.Send(context.TODO()) if err != nil { base.Logger().Warn("failed to list account aliases, please check permission setting: ", err) + metricSet.AccountName = metricSet.AccountID } else { + // When there is no account alias, account ID will be used as cloud.account.name + if len(output.AccountAliases) == 0 { + metricSet.AccountName = metricSet.AccountID + } + // There can be more than one aliases for each account, for now we are only // collecting the first one. - if output.AccountAliases != nil { - metricSet.AccountName = output.AccountAliases[0] - base.Logger().Debug("AWS Credentials belong to account name: ", metricSet.AccountName) - } + metricSet.AccountName = output.AccountAliases[0] + base.Logger().Debug("AWS Credentials belong to account name: ", metricSet.AccountName) } // Get IAM account id