Skip to content

Commit 8dd7d66

Browse files
Adding anomaly detection support.
1 parent 244c173 commit 8dd7d66

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws"
5+
"github.com/aws/aws-sdk-go/aws/session"
6+
"github.com/aws/aws-sdk-go/service/cloudwatch"
7+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
8+
)
9+
10+
type CloudWatchAnomalyDetector struct {
11+
svc *cloudwatch.CloudWatch
12+
detector *cloudwatch.AnomalyDetector
13+
}
14+
15+
func init() {
16+
register("CloudWatchAnomalyDetector", ListCloudWatchAnomalyDetectors)
17+
}
18+
19+
func ListCloudWatchAnomalyDetectors(sess *session.Session) ([]Resource, error) {
20+
svc := cloudwatch.New(sess)
21+
resources := []Resource{}
22+
23+
params := &cloudwatch.DescribeAnomalyDetectorsInput{
24+
MaxResults: aws.Int64(25),
25+
}
26+
27+
for {
28+
output, err := svc.DescribeAnomalyDetectors(params)
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
for _, detector := range output.AnomalyDetectors {
34+
resources = append(resources, &CloudWatchAnomalyDetector{
35+
svc: svc,
36+
detector: detector,
37+
})
38+
}
39+
40+
if output.NextToken == nil {
41+
break
42+
}
43+
44+
params.NextToken = output.NextToken
45+
}
46+
47+
return resources, nil
48+
}
49+
50+
func (f *CloudWatchAnomalyDetector) Remove() error {
51+
_, err := f.svc.DeleteAnomalyDetector(&cloudwatch.DeleteAnomalyDetectorInput{
52+
SingleMetricAnomalyDetector: f.detector.SingleMetricAnomalyDetector,
53+
})
54+
55+
return err
56+
}
57+
58+
func (f *CloudWatchAnomalyDetector) Properties() types.Properties {
59+
properties := types.NewProperties()
60+
properties.Set("MetricName", f.detector.SingleMetricAnomalyDetector.MetricName)
61+
return properties
62+
}
63+
64+
func (f *CloudWatchAnomalyDetector) String() string {
65+
return *f.detector.SingleMetricAnomalyDetector.MetricName
66+
}

0 commit comments

Comments
 (0)