-
Notifications
You must be signed in to change notification settings - Fork 18
/
eventbridge_rule_detail.sp
316 lines (275 loc) · 6.97 KB
/
eventbridge_rule_detail.sp
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
dashboard "eventbridge_rule_detail" {
title = "AWS EventBridge Rule Detail"
documentation = file("./dashboards/eventbridge/docs/eventbridge_rule_detail.md")
tags = merge(local.eventbridge_common_tags, {
type = "Detail"
})
input "eventbridge_rule_arn" {
title = "Select a rule:"
query = query.eventbridge_rule_input
width = 4
}
container {
card {
query = query.eventbridge_rule_state
width = 3
args = [self.input.eventbridge_rule_arn.value]
}
card {
width = 3
query = query.eventbridge_rule_target_count
args = [self.input.eventbridge_rule_arn.value]
}
}
with "cloudwatch_log_groups_for_eventbridge_rule" {
query = query.cloudwatch_log_groups_for_eventbridge_rule
args = [self.input.eventbridge_rule_arn.value]
}
with "eventbridge_buses_for_eventbridge_rule" {
query = query.eventbridge_buses_for_eventbridge_rule
args = [self.input.eventbridge_rule_arn.value]
}
with "lambda_functions_for_eventbridge_rule" {
query = query.lambda_functions_for_eventbridge_rule
args = [self.input.eventbridge_rule_arn.value]
}
with "sns_topics_for_eventbridge_rule" {
query = query.sns_topics_for_eventbridge_rule
args = [self.input.eventbridge_rule_arn.value]
}
container {
graph {
title = "Relationships"
type = "graph"
direction = "TD"
node {
base = node.cloudwatch_log_group
args = {
cloudwatch_log_group_arns = with.cloudwatch_log_groups_for_eventbridge_rule.rows[*].cloudwatch_log_group_arn
}
}
node {
base = node.eventbridge_bus
args = {
eventbridge_bus_arns = with.eventbridge_buses_for_eventbridge_rule.rows[*].eventbridge_bus_arn
}
}
node {
base = node.eventbridge_rule
args = {
eventbridge_rule_arns = [self.input.eventbridge_rule_arn.value]
}
}
node {
base = node.lambda_function
args = {
lambda_function_arns = with.lambda_functions_for_eventbridge_rule.rows[*].function_arn
}
}
node {
base = node.sns_topic
args = {
sns_topic_arns = with.sns_topics_for_eventbridge_rule.rows[*].topic_arn
}
}
edge {
base = edge.eventbridge_rule_to_cloudwatch_log_group
args = {
eventbridge_rule_arns = [self.input.eventbridge_rule_arn.value]
}
}
edge {
base = edge.eventbridge_rule_to_eventbridge_bus
args = {
eventbridge_rule_arns = [self.input.eventbridge_rule_arn.value]
}
}
edge {
base = edge.eventbridge_rule_to_lambda_function
args = {
eventbridge_rule_arns = [self.input.eventbridge_rule_arn.value]
}
}
edge {
base = edge.eventbridge_rule_to_sns_topic
args = {
eventbridge_rule_arns = [self.input.eventbridge_rule_arn.value]
}
}
}
}
container {
container {
width = 6
table {
title = "Overview"
type = "line"
width = 6
query = query.eventbridge_rule_overview
args = [self.input.eventbridge_rule_arn.value]
}
table {
title = "Tags"
width = 6
query = query.eventbridge_rule_tags
args = [self.input.eventbridge_rule_arn.value]
}
}
container {
width = 6
table {
title = "Targets"
query = query.eventbridge_rule_targets
args = [self.input.eventbridge_rule_arn.value]
}
}
}
}
# Input queries
query "eventbridge_rule_input" {
sql = <<-EOQ
select
title as label,
arn as value,
json_build_object(
'account_id', account_id,
'region', region
) as tags
from
aws_eventbridge_rule
order by
arn;
EOQ
}
# With queries
query "cloudwatch_log_groups_for_eventbridge_rule" {
sql = <<-EOQ
select
(t ->> 'Arn')::text || ':*' as cloudwatch_log_group_arn
from
aws_eventbridge_rule r,
jsonb_array_elements(targets) t
where
r.arn = $1
and r.account_id = split_part($1, ':', 5)
and r.region = split_part($1, ':', 4)
and t ->> 'Arn' like '%logs%';
EOQ
}
query "eventbridge_buses_for_eventbridge_rule" {
sql = <<-EOQ
select
b.arn as eventbridge_bus_arn
from
aws_eventbridge_rule r
join aws_eventbridge_bus b on b.name = r.event_bus_name
where
r.arn = $1
and b.region = split_part($1, ':', 4)
and b.account_id = split_part($1, ':', 5)
EOQ
}
query "lambda_functions_for_eventbridge_rule" {
sql = <<-EOQ
select
(t ->> 'Arn')::text as function_arn
from
aws_eventbridge_rule r,
jsonb_array_elements(targets) t
where
r.arn = $1
and r.account_id = split_part($1, ':', 5)
and r.region = split_part($1, ':', 4)
and t ->> 'Arn' like '%lambda%';
EOQ
}
query "sns_topics_for_eventbridge_rule" {
sql = <<-EOQ
select
(t ->> 'Arn')::text as topic_arn
from
aws_eventbridge_rule r,
jsonb_array_elements(targets) t
where
arn = $1
and r.account_id = split_part($1, ':', 5)
and r.region = split_part($1, ':', 4)
and t ->> 'Arn' like '%sns%';
EOQ
}
# Card queries
query "eventbridge_rule_state" {
sql = <<-EOQ
select
'State' as label,
initcap(state) as value
from
aws_eventbridge_rule
where
arn = $1
and account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4);
EOQ
}
query "eventbridge_rule_target_count" {
sql = <<-EOQ
select
coalesce(jsonb_array_length(targets), 0) as value,
'Targets' as label
from
aws_eventbridge_rule
where
arn = $1
and account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4);
EOQ
}
# Other detail page queries
query "eventbridge_rule_overview" {
sql = <<-EOQ
select
name as "Name",
event_bus_name as "Event Bus Name",
managed_by as "Managed by",
region as "Region",
account_id as "Account ID",
arn as "ARN"
from
aws_eventbridge_rule
where
arn = $1
and account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4);
EOQ
}
query "eventbridge_rule_tags" {
sql = <<-EOQ
select
tag ->> 'Key' as "Key",
tag ->> 'Value' as "Value"
from
aws_eventbridge_rule,
jsonb_array_elements(tags_src) as tag
where
arn = $1
and account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
order by
tag ->> 'Key';
EOQ
}
query "eventbridge_rule_targets" {
sql = <<-EOQ
select
target ->> 'Id' as "ID",
target ->> 'Arn' as "ARN",
target ->> 'Input' as "Input"
from
aws_eventbridge_rule as c,
jsonb_array_elements(c.targets) as target
where
c.arn = $1
and c.account_id = split_part($1, ':', 5)
and c.region = split_part($1, ':', 4);
EOQ
}