-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarms_fetch.go
53 lines (47 loc) · 1.51 KB
/
alarms_fetch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package cloudwatch
import (
"context"
"github.com/OpsHelmInc/cloudquery/client"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
"github.com/cloudquery/plugin-sdk/schema"
)
func fetchCloudwatchAlarms(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
var config cloudwatch.DescribeAlarmsInput
c := meta.(*client.Client)
svc := c.Services().Cloudwatch
for {
response, err := svc.DescribeAlarms(ctx, &config)
if err != nil {
return err
}
res <- response.MetricAlarms
if aws.ToString(response.NextToken) == "" {
break
}
config.NextToken = response.NextToken
}
return nil
}
func resolveCloudwatchAlarmDimensions(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
alarm := resource.Item.(types.MetricAlarm)
dimensions := make(map[string]*string)
for _, d := range alarm.Dimensions {
dimensions[*d.Name] = d.Value
}
return resource.Set("dimensions", dimensions)
}
func resolveCloudwatchAlarmTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
cl := meta.(*client.Client)
svc := cl.Services().Cloudwatch
alarm := resource.Item.(types.MetricAlarm)
input := cloudwatch.ListTagsForResourceInput{
ResourceARN: alarm.AlarmArn,
}
output, err := svc.ListTagsForResource(ctx, &input)
if err != nil {
return err
}
return resource.Set(c.Name, client.TagsToMap(output.Tags))
}