diff --git a/README.md b/README.md index 216cd682a..9f05aeffd 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ Only the latest version gets security updates. We won't support older versions. * `AWS/Cognito` - Cognito * `AWS/DataSync` - DataSync * `AWS/DDoSProtection` - Distributed Denial of Service (DDoS) protection service + * `AWS/DirectoryService` - Directory Services (MicrosoftAD) * `AWS/DMS` - Database Migration Service * `AWS/DocDB` - DocumentDB (with MongoDB compatibility) * `AWS/DX` - Direct Connect diff --git a/examples/ds.yml b/examples/ds.yml new file mode 100644 index 000000000..e68495558 --- /dev/null +++ b/examples/ds.yml @@ -0,0 +1,19 @@ +apiVersion: v1alpha1 +discovery: + jobs: + - type: AWS/DirectoryService + regions: + - us-east-1 + period: 300 + length: 300 + metrics: + - name: "Bytes Sent/sec" + statistics: [Average] + - name: "% Processor Time" + statistics: [Average] + - name: "DS Directory Searches/Sec" + statistics: [Average] + - name: "Database Cache % Hit" + statistics: [Average] + - name: "% Free Space" + statistics: [Sum] diff --git a/pkg/config/services.go b/pkg/config/services.go index 0e12d6427..c761f9db4 100644 --- a/pkg/config/services.go +++ b/pkg/config/services.go @@ -243,6 +243,16 @@ var SupportedServices = serviceConfigs{ regexp.MustCompile(":agent/(?P[^/]+)"), }, }, + { + Namespace: "AWS/DirectoryService", + Alias: "ds", + ResourceFilters: []*string{ + aws.String("ds:directory"), + }, + DimensionRegexps: []*regexp.Regexp{ + regexp.MustCompile(":directory/(?P[^/]+)"), + }, + }, { Namespace: "AWS/DMS", Alias: "dms", diff --git a/pkg/job/maxdimassociator/associator_directoryservice_test.go b/pkg/job/maxdimassociator/associator_directoryservice_test.go new file mode 100644 index 000000000..c29dfc0b5 --- /dev/null +++ b/pkg/job/maxdimassociator/associator_directoryservice_test.go @@ -0,0 +1,61 @@ +package maxdimassociator + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/config" + "github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/logging" + "github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model" +) + +var directory = &model.TaggedResource{ + ARN: "arn:aws:ds::012345678901:directory/d-abc123", + Namespace: "AWS/DirectoryService", +} + +func TestAssociatorDirectoryService(t *testing.T) { + type args struct { + dimensionRegexps []model.DimensionsRegexp + resources []*model.TaggedResource + metric *model.Metric + } + + type testCase struct { + name string + args args + expectedSkip bool + expectedResource *model.TaggedResource + } + + testcases := []testCase{ + { + name: "should match directory id with Directory ID dimension", + args: args{ + dimensionRegexps: config.SupportedServices.GetService("AWS/DirectoryService").ToModelDimensionsRegexp(), + resources: []*model.TaggedResource{directory}, + metric: &model.Metric{ + MetricName: "Current Bandwidth", + Namespace: "AWS/DirectoryService", + Dimensions: []model.Dimension{ + {Name: "Metric Category", Value: "NTDS"}, + {Name: "Domain Controller IP", Value: "123.123.123.123"}, + {Name: "Directory ID", Value: "d-abc123"}, + }, + }, + }, + expectedSkip: false, + expectedResource: directory, + }, + } + + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + associator := NewAssociator(logging.NewNopLogger(), tc.args.dimensionRegexps, tc.args.resources) + res, skip := associator.AssociateMetricToResource(tc.args.metric) + require.Equal(t, tc.expectedSkip, skip) + require.Equal(t, tc.expectedResource, res) + }) + } +}