Skip to content

Commit 32599b7

Browse files
committed
Add auto-discovery for Directory Services(MicrosoftAD)
Signed-off-by: Ruslan Mustaev <ruslan.mustaev@orionhealth.com>
1 parent 26c8bf8 commit 32599b7

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Only the latest version gets security updates. We won't support older versions.
6363
* `AWS/Cognito` - Cognito
6464
* `AWS/DataSync` - DataSync
6565
* `AWS/DDoSProtection` - Distributed Denial of Service (DDoS) protection service
66+
* `AWS/DirectoryService` - Directory Services (MicrosoftAD)
6667
* `AWS/DMS` - Database Migration Service
6768
* `AWS/DocDB` - DocumentDB (with MongoDB compatibility)
6869
* `AWS/DX` - Direct Connect

examples/ds.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1alpha1
2+
discovery:
3+
jobs:
4+
- type: AWS/DirectoryService
5+
regions:
6+
- us-east-1
7+
period: 300
8+
length: 300
9+
metrics:
10+
- name: "Bytes Sent/sec"
11+
statistics: [Average]
12+
- name: "% Processor Time"
13+
statistics: [Average]
14+
- name: "DS Directory Searches/Sec"
15+
statistics: [Average]
16+
- name: "Database Cache % Hit"
17+
statistics: [Average]
18+
- name: "% Free Space"
19+
statistics: [Sum]

pkg/config/services.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ var SupportedServices = serviceConfigs{
243243
regexp.MustCompile(":agent/(?P<AgentId>[^/]+)"),
244244
},
245245
},
246+
{
247+
Namespace: "AWS/DirectoryService",
248+
Alias: "ds",
249+
ResourceFilters: []*string{
250+
aws.String("ds:directory"),
251+
},
252+
DimensionRegexps: []*regexp.Regexp{
253+
regexp.MustCompile(":directory/(?P<Directory_ID>[^/]+)"),
254+
},
255+
},
246256
{
247257
Namespace: "AWS/DMS",
248258
Alias: "dms",
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package maxdimassociator
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
8+
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/config"
9+
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/logging"
10+
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model"
11+
)
12+
13+
var directory = &model.TaggedResource{
14+
ARN: "arn:aws:ds::012345678901:directory/d-abc123",
15+
Namespace: "AWS/DirectoryService",
16+
}
17+
18+
func TestAssociatorDS(t *testing.T) {
19+
type args struct {
20+
dimensionRegexps []model.DimensionsRegexp
21+
resources []*model.TaggedResource
22+
metric *model.Metric
23+
}
24+
25+
type testCase struct {
26+
name string
27+
args args
28+
expectedSkip bool
29+
expectedResource *model.TaggedResource
30+
}
31+
32+
testcases := []testCase{
33+
{
34+
name: "should match Virtual Interface with VirtualInterfaceId dimension",
35+
args: args{
36+
dimensionRegexps: config.SupportedServices.GetService("AWS/DirectoryService").ToModelDimensionsRegexp(),
37+
resources: []*model.TaggedResource{directory},
38+
metric: &model.Metric{
39+
MetricName: "Current Bandwidth",
40+
Namespace: "AWS/DirectoryService",
41+
Dimensions: []model.Dimension{
42+
{Name: "Metric Category", Value: "NTDS"},
43+
{Name: "Domain Controller IP", Value: "123.123.123.123"},
44+
{Name: "Directory ID", Value: "d-abc123"},
45+
},
46+
},
47+
},
48+
expectedSkip: false,
49+
expectedResource: directory,
50+
},
51+
}
52+
53+
for _, tc := range testcases {
54+
t.Run(tc.name, func(t *testing.T) {
55+
associator := NewAssociator(logging.NewNopLogger(), tc.args.dimensionRegexps, tc.args.resources)
56+
res, skip := associator.AssociateMetricToResource(tc.args.metric)
57+
require.Equal(t, tc.expectedSkip, skip)
58+
require.Equal(t, tc.expectedResource, res)
59+
})
60+
}
61+
}

0 commit comments

Comments
 (0)