Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CL-508 Adding support for CloudWatch Insight Rules #24

Merged
merged 2 commits into from
May 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions resources/cloudwatch-insight-rules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type CloudWatchInsightRule struct {
svc *cloudwatch.CloudWatch
name *string
}

func init() {
register("CloudWatchInsightRule", ListCloudWatchInsightRules)
}

func ListCloudWatchInsightRules(sess *session.Session) ([]Resource, error) {
svc := cloudwatch.New(sess)
resources := []Resource{}

params := &cloudwatch.DescribeInsightRulesInput{
MaxResults: aws.Int64(25),
}

for {
output, err := svc.DescribeInsightRules(params)
if err != nil {
return nil, err
}

for _, rules := range output.InsightRules {
resources = append(resources, &CloudWatchInsightRule{
svc: svc,
name: rules.Name,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *CloudWatchInsightRule) Remove() error {
_, err := f.svc.DeleteInsightRules(&cloudwatch.DeleteInsightRulesInput{
RuleNames: []*string{f.name},
})

return err
}

func (f *CloudWatchInsightRule) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", f.name)
return properties
}

func (f *CloudWatchInsightRule) String() string {
return *f.name
}
Loading