This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
/
alarms.go
175 lines (170 loc) · 5.52 KB
/
alarms.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package lightsail
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/lightsail"
"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
//go:generate cq-gen --resource alarms --config gen.hcl --output .
func Alarms() *schema.Table {
return &schema.Table{
Name: "aws_lightsail_alarms",
Description: "Describes an alarm",
Resolver: fetchLightsailAlarms,
Multiplex: client.ServiceAccountRegionMultiplexer("lightsail"),
IgnoreError: client.IgnoreAccessDeniedServiceDisabled,
DeleteFilter: client.DeleteAccountRegionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"arn"}},
IgnoreInTests: true,
Columns: []schema.Column{
{
Name: "account_id",
Description: "The AWS Account ID of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSAccount,
},
{
Name: "region",
Description: "The AWS Region of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSRegion,
},
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) of the alarm",
Type: schema.TypeString,
},
{
Name: "comparison_operator",
Description: "The arithmetic operation used when comparing the specified statistic and threshold",
Type: schema.TypeString,
},
{
Name: "contact_protocols",
Description: "The contact protocols for the alarm, such as Email, SMS (text messaging), or both",
Type: schema.TypeStringArray,
},
{
Name: "created_at",
Description: "The timestamp when the alarm was created",
Type: schema.TypeTimestamp,
},
{
Name: "datapoints_to_alarm",
Description: "The number of data points that must not within the specified threshold to trigger the alarm",
Type: schema.TypeBigInt,
},
{
Name: "evaluation_periods",
Description: "The number of periods over which data is compared to the specified threshold",
Type: schema.TypeBigInt,
},
{
Name: "availability_zone",
Description: "The Availability Zone",
Type: schema.TypeString,
Resolver: schema.PathResolver("Location.AvailabilityZone"),
},
{
Name: "metric_name",
Description: "The name of the metric associated with the alarm",
Type: schema.TypeString,
},
{
Name: "monitored_resource_info_arn",
Description: "The Amazon Resource Name (ARN) of the resource being monitored",
Type: schema.TypeString,
Resolver: schema.PathResolver("MonitoredResourceInfo.Arn"),
},
{
Name: "monitored_resource_name",
Description: "The name of the Lightsail resource being monitored",
Type: schema.TypeString,
Resolver: schema.PathResolver("MonitoredResourceInfo.Name"),
},
{
Name: "monitored_resource_resource_type",
Description: "The Lightsail resource type of the resource being monitored",
Type: schema.TypeString,
Resolver: schema.PathResolver("MonitoredResourceInfo.ResourceType"),
},
{
Name: "name",
Description: "The name of the alarm",
Type: schema.TypeString,
},
{
Name: "notification_enabled",
Description: "Indicates whether the alarm is enabled",
Type: schema.TypeBool,
},
{
Name: "notification_triggers",
Description: "The alarm states that trigger a notification",
Type: schema.TypeStringArray,
},
{
Name: "period",
Description: "The period, in seconds, over which the statistic is applied",
Type: schema.TypeBigInt,
},
{
Name: "resource_type",
Description: "The Lightsail resource type (eg, Alarm)",
Type: schema.TypeString,
},
{
Name: "state",
Description: "The current state of the alarm",
Type: schema.TypeString,
},
{
Name: "statistic",
Description: "The statistic for the metric associated with the alarm",
Type: schema.TypeString,
},
{
Name: "support_code",
Description: "The support code",
Type: schema.TypeString,
},
{
Name: "threshold",
Description: "The value against which the specified statistic is compared",
Type: schema.TypeFloat,
},
{
Name: "treat_missing_data",
Description: "Specifies how the alarm handles missing data points",
Type: schema.TypeString,
},
{
Name: "unit",
Description: "The unit of the metric associated with the alarm",
Type: schema.TypeString,
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchLightsailAlarms(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
var input lightsail.GetAlarmsInput
c := meta.(*client.Client)
svc := c.Services().Lightsail
for {
response, err := svc.GetAlarms(ctx, &input)
if err != nil {
return diag.WrapError(err)
}
res <- response.Alarms
if aws.ToString(response.NextPageToken) == "" {
break
}
input.PageToken = response.NextPageToken
}
return nil
}