-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecs_disk_detail.sp
485 lines (422 loc) · 10.2 KB
/
ecs_disk_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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
dashboard "ecs_disk_detail" {
title = "AliCloud ECS Disk Detail"
documentation = file("./dashboards/ecs/docs/ecs_disk_detail.md")
tags = merge(local.ecs_common_tags, {
type = "Detail"
})
input "disk_arn" {
title = "Select a disk:"
query = query.ecs_disk_input
width = 4
}
container {
card {
width = 2
query = query.ecs_disk_storage
args = [self.input.disk_arn.value]
}
card {
width = 2
query = query.ecs_disk_iops
args = [self.input.disk_arn.value]
}
card {
width = 2
query = query.ecs_disk_category
args = [self.input.disk_arn.value]
}
card {
width = 2
query = query.ecs_disk_attached_instances_count
args = [self.input.disk_arn.value]
}
card {
width = 2
query = query.ecs_disk_encryption
args = [self.input.disk_arn.value]
}
card {
width = 2
query = query.ecs_disk_auto_snapshot
args = [self.input.disk_arn.value]
}
}
with "ecs_images_for_ecs_disk" {
query = query.ecs_images_for_ecs_disk
args = [self.input.disk_arn.value]
}
with "ecs_instances_for_ecs_disk" {
query = query.ecs_instances_for_ecs_disk
args = [self.input.disk_arn.value]
}
with "source_ecs_snapshots_for_ecs_disk" {
query = query.source_ecs_snapshots_for_ecs_disk
args = [self.input.disk_arn.value]
}
with "kms_keys_for_ecs_disk" {
query = query.kms_keys_for_ecs_disk
args = [self.input.disk_arn.value]
}
with "target_ecs_snapshots_for_ecs_disk" {
query = query.target_ecs_snapshots_for_ecs_disk
args = [self.input.disk_arn.value]
}
container {
graph {
title = "Relationships"
type = "graph"
node {
base = node.ecs_disk
args = {
ecs_disk_arns = [self.input.disk_arn.value]
}
}
node {
base = node.ecs_image
args = {
ecs_image_arns = with.ecs_images_for_ecs_disk.rows[*].image_arn
}
}
node {
base = node.ecs_instance
args = {
ecs_instance_arns = with.ecs_instances_for_ecs_disk.rows[*].instance_arn
}
}
node {
base = node.ecs_snapshot
args = {
ecs_snapshot_arns = with.source_ecs_snapshots_for_ecs_disk.rows[*].snapshot_arn
}
}
node {
base = node.ecs_snapshot
args = {
ecs_snapshot_arns = with.target_ecs_snapshots_for_ecs_disk.rows[*].snapshot_arn
}
}
node {
base = node.kms_key
args = {
kms_key_arns = with.kms_keys_for_ecs_disk.rows[*].key_arn
}
}
edge {
base = edge.ecs_disk_to_ecs_image
args = {
ecs_disk_arns = [self.input.disk_arn.value]
}
}
edge {
base = edge.ecs_disk_to_ecs_snapshot
args = {
ecs_snapshot_arns = with.target_ecs_snapshots_for_ecs_disk.rows[*].snapshot_arn
}
}
edge {
base = edge.ecs_disk_to_kms_key
args = {
ecs_disk_arns = [self.input.disk_arn.value]
}
}
edge {
base = edge.ecs_instance_to_ecs_disk
args = {
ecs_instance_arns = with.ecs_instances_for_ecs_disk.rows[*].instance_arn
}
}
edge {
base = edge.ecs_snapshot_to_ecs_disk
args = {
ecs_snapshot_arns = with.source_ecs_snapshots_for_ecs_disk.rows[*].snapshot_arn
}
}
}
}
container {
container {
width = 6
table {
title = "Overview"
type = "line"
width = 6
query = query.ecs_disk_overview
args = [self.input.disk_arn.value]
}
table {
title = "Tags"
width = 6
query = query.ecs_disk_tags
args = [self.input.disk_arn.value]
}
}
container {
width = 6
table {
title = "Attached To"
query = query.ecs_disk_attached_instances
args = [self.input.disk_arn.value]
column "Instance ARN" {
display = "none"
}
column "Instance ID" {
href = "${dashboard.ecs_instance_detail.url_path}?input.instance_arn={{.'Instance ARN' | @uri}}"
}
}
table {
title = "Encryption Details"
column "KMS Key ID" {
href = "${dashboard.kms_key_detail.url_path}?input.key_arn={{.'KMS Key ID' | @uri}}"
}
query = query.ecs_disk_encryption_status
args = [self.input.disk_arn.value]
}
}
}
}
# Input queries
query "ecs_disk_input" {
sql = <<-EOQ
select
title as label,
arn as value,
json_build_object(
'account_id', account_id,
'region', region,
'disk_id', disk_id
) as tags
from
alicloud_ecs_disk
order by
title;
EOQ
}
# with queries
query "source_ecs_snapshots_for_ecs_disk" {
sql = <<-EOQ
select
s.arn as snapshot_arn
from
alicloud_ecs_snapshot s
left join alicloud_ecs_disk as d on s.snapshot_id = d.source_snapshot_id
where
d.account_id = split_part($1, ':', 5)
and d.region = split_part($1, ':', 4)
and d.arn = $1
and s.arn is not null;
EOQ
}
query "target_ecs_snapshots_for_ecs_disk" {
sql = <<-EOQ
select
s.arn as snapshot_arn
from
alicloud_ecs_snapshot s
left join alicloud_ecs_disk as d on s.source_disk_id = d.disk_id
where
d.account_id = split_part($1, ':', 5)
and d.region = split_part($1, ':', 4)
and d.arn = $1
and s.arn is not null;
EOQ
}
query "ecs_images_for_ecs_disk" {
sql = <<-EOQ
select
i.arn as image_arn
from
alicloud_ecs_disk d,
alicloud_ecs_image i
where
d.image_id = i.image_id
and d.region = i.region
and d.account_id = i.account_id
and d.arn = $1
EOQ
}
query "ecs_instances_for_ecs_disk" {
sql = <<-EOQ
select
i.arn as instance_arn
from
alicloud_ecs_instance i
left join alicloud_ecs_disk as d on i.instance_id = d.instance_id
where
d.arn = $1
and d.account_id = split_part($1, ':', 5)
and d.region = split_part($1, ':', 4)
and i.arn is not null;
EOQ
}
query "kms_keys_for_ecs_disk" {
sql = <<-EOQ
select
k.arn as key_arn
from
alicloud_kms_key k
left join alicloud_ecs_disk as d on k.key_id = d.kms_key_id
where
d.arn = $1
and d.account_id = split_part($1, ':', 5)
and d.region = split_part($1, ':', 4)
and k.arn is not null;
EOQ
}
# card queries
query "ecs_disk_storage" {
sql = <<-EOQ
select
'Storage (GB)' as label,
sum(size) as value
from
alicloud_ecs_disk
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
and arn = $1;
EOQ
}
query "ecs_disk_iops" {
sql = <<-EOQ
select
'IOPS' as label,
iops as value
from
alicloud_ecs_disk
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
and arn = $1;
EOQ
}
query "ecs_disk_category" {
sql = <<-EOQ
select
'Category' as label,
category as value
from
alicloud_ecs_disk
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
and arn = $1;
EOQ
}
query "ecs_disk_attached_instances_count" {
sql = <<-EOQ
select
'Attached Instances' as label,
case
when attachments is null then 0
else jsonb_array_length(attachments)
end as value,
case
when jsonb_array_length(attachments) > 0 then 'ok'
else 'alert'
end as "type"
from
alicloud_ecs_disk
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
and arn = $1;
EOQ
}
query "ecs_disk_encryption" {
sql = <<-EOQ
select
'Encryption' as label,
case when encrypted then 'Enabled' else 'Disabled' end as value,
case when encrypted then 'ok' else 'alert' end as type
from
alicloud_ecs_disk
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
and arn = $1;
EOQ
}
query "ecs_disk_auto_snapshot" {
sql = <<-EOQ
select
'Auto Snapshot' as label,
case when enable_auto_snapshot then 'Enabled' else 'Disabled' end as value,
case when enable_auto_snapshot then 'ok' else 'alert' end as type
from
alicloud_ecs_disk
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
and arn = $1;
EOQ
}
# Other detail page queries
query "ecs_disk_attached_instances" {
sql = <<-EOQ
select
i.instance_id as "Instance ID",
i.name as "Name",
i.arn as "Instance ARN",
i.status as "Instance State",
attachment ->> 'AttachedTime' as "Attachment Time"
from
alicloud_ecs_disk as v,
jsonb_array_elements(attachments) as attachment,
alicloud_ecs_instance as i
where
i.instance_id = attachment ->> 'InstanceId'
and v.arn = $1
and v.account_id = split_part($1, ':', 5)
and v.region = split_part($1, ':', 4)
order by
i.instance_id;
EOQ
}
query "ecs_disk_encryption_status" {
sql = <<-EOQ
select
case when encrypted then 'Enabled' else 'Disabled' end as "Encryption",
kms_key_id as "KMS Key ID"
from
alicloud_ecs_disk
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
and arn = $1;
EOQ
}
query "ecs_disk_overview" {
sql = <<-EOQ
select
disk_id as "Disk ID",
enable_auto_snapshot as "Auto Enabled Snapshot",
source_snapshot_id as "Snapshot ID",
zone as "Zone",
title as "Title",
region as "Region",
account_id as "Account ID",
arn as "ARN"
from
alicloud_ecs_disk
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
and arn = $1;
EOQ
}
query "ecs_disk_tags" {
sql = <<-EOQ
select
tag ->> 'Key' as "Key",
tag ->> 'Value' as "Value"
from
alicloud_ecs_disk,
jsonb_array_elements(tags_src) as tag
where
account_id = split_part($1, ':', 5)
and region = split_part($1, ':', 4)
and arn = $1
order by
tag ->> 'Key';
EOQ
}