/
droplet_detail.sp
601 lines (515 loc) · 11.7 KB
/
droplet_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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
dashboard "droplet_detail" {
title = "DigitalOcean Droplet Detail"
documentation = file("./dashboards/droplet/docs/droplet_detail.md")
tags = merge(local.droplet_common_tags, {
type = "Detail"
})
input "droplet_urn" {
title = "Select a droplet:"
query = query.droplet_input
width = 4
}
container {
card {
width = 2
query = query.droplet_status
args = [self.input.droplet_urn.value]
}
card {
width = 2
query = query.droplet_vcpus
args = [self.input.droplet_urn.value]
}
card {
width = 2
query = query.droplet_storage
args = [self.input.droplet_urn.value]
}
card {
width = 2
query = query.droplet_public_access
args = [self.input.droplet_urn.value]
}
card {
width = 2
query = query.droplet_backup_status
args = [self.input.droplet_urn.value]
}
card {
width = 2
query = query.droplet_monitoring_status
args = [self.input.droplet_urn.value]
}
}
with "blockstorage_volumes_for_droplet" {
query = query.blockstorage_volumes_for_droplet
args = [self.input.droplet_urn.value]
}
with "image_images_for_droplet" {
query = query.image_images_for_droplet
args = [self.input.droplet_urn.value]
}
with "network_firewalls_for_droplet" {
query = query.network_firewalls_for_droplet
args = [self.input.droplet_urn.value]
}
with "network_floating_ips_for_droplet" {
query = query.network_floating_ips_for_droplet
args = [self.input.droplet_urn.value]
}
with "network_load_balancers_for_droplet" {
query = query.network_load_balancers_for_droplet
args = [self.input.droplet_urn.value]
}
with "network_vpcs_for_droplet" {
query = query.network_vpcs_for_droplet
args = [self.input.droplet_urn.value]
}
with "snapshot_snapshots_for_droplet" {
query = query.snapshot_snapshots_for_droplet
args = [self.input.droplet_urn.value]
}
container {
graph {
title = "Relationships"
type = "graph"
direction = "TD"
node {
base = node.blockstorage_volume
args = {
blockstorage_volume_urns = with.blockstorage_volumes_for_droplet.rows[*].volume_urn
}
}
node {
base = node.droplet_droplet
args = {
droplet_droplet_urns = [self.input.droplet_urn.value]
}
}
node {
base = node.image_image
args = {
image_image_urns = with.image_images_for_droplet.rows[*].image_urn
}
}
node {
base = node.network_firewall
args = {
network_firewall_urns = with.network_firewalls_for_droplet.rows[*].firewall_urn
}
}
node {
base = node.network_floating_ip
args = {
network_floating_ip_urns = with.network_floating_ips_for_droplet.rows[*].floating_ip_urn
}
}
node {
base = node.network_load_balancer
args = {
network_load_balancer_urns = with.network_load_balancers_for_droplet.rows[*].lb_urn
}
}
node {
base = node.network_vpc
args = {
network_vpc_urns = with.network_vpcs_for_droplet.rows[*].vpc_urn
}
}
node {
base = node.snapshot_snapshot
args = {
snapshot_snapshot_urns = with.snapshot_snapshots_for_droplet.rows[*].snapshot_urn
}
}
edge {
base = edge.droplet_droplet_to_blockstorage_volume
args = {
droplet_droplet_urns = [self.input.droplet_urn.value]
}
}
edge {
base = edge.droplet_droplet_to_network_firewall
args = {
droplet_droplet_urns = [self.input.droplet_urn.value]
}
}
edge {
base = edge.droplet_droplet_to_network_floating_ip
args = {
droplet_droplet_urns = [self.input.droplet_urn.value]
}
}
edge {
base = edge.droplet_droplet_to_network_load_balancer
args = {
droplet_droplet_urns = [self.input.droplet_urn.value]
}
}
edge {
base = edge.droplet_droplet_to_network_vpc
args = {
droplet_droplet_urns = [self.input.droplet_urn.value]
}
}
edge {
base = edge.network_firewall_to_network_vpc
args = {
droplet_droplet_urns = [self.input.droplet_urn.value]
}
}
edge {
base = edge.droplet_droplet_to_snapshot_snapshot
args = {
droplet_droplet_urns = [self.input.droplet_urn.value]
}
}
edge {
base = edge.image_image_to_droplet_droplet
args = {
image_image_urns = with.image_images_for_droplet.rows[*].image_urn
}
}
}
}
container {
container {
width = 6
table {
title = "Overview"
type = "line"
width = 6
query = query.droplet_overview
args = [self.input.droplet_urn.value]
}
table {
title = "Tags"
width = 6
query = query.droplet_tags
args = [self.input.droplet_urn.value]
}
}
container {
width = 6
table {
title = "Attached Volumes"
query = query.droplet_attached_volumes
args = [self.input.droplet_urn.value]
column "Volume URN" {
display = "none"
}
column "Volume Name" {
href = "/digitalocean_insights.dashboard.blockstorage_volume_detail?input.volume_urn={{.'Volume URN' | @uri}}"
}
}
}
}
container {
container {
width = 6
table {
title = "Firewall Details"
query = query.droplet_firewall_configuration
args = [self.input.droplet_urn.value]
column "URN" {
display = "none"
}
column "Name" {
href = "/digitalocean_insights.dashboard.network_firewall_detail?input.firewall_urn={{.'URN' | @uri}}"
}
}
}
container {
width = 6
table {
title = "VPC Details"
query = query.droplet_network_vpc_details
args = [self.input.droplet_urn.value]
column "URN" {
display = "none"
}
column "Name" {
href = "/digitalocean_insights.dashboard.network_vpc_detail?input.vpc_urn={{.'URN' | @uri}}"
}
}
}
}
}
# Input queries
query "droplet_input" {
sql = <<-EOQ
select
title as label,
urn as value,
json_build_object(
'region', region_slug,
'id', id
) as tags
from
digitalocean_droplet
order by
title;
EOQ
}
# With queries
query "blockstorage_volumes_for_droplet" {
sql = <<-EOQ
select
v.urn as volume_urn
from
digitalocean_droplet as d,
digitalocean_volume as v,
jsonb_array_elements(droplet_ids) as did
where
d.id::int = did::int
and d.urn = $1;
EOQ
}
query "image_images_for_droplet" {
sql = <<-EOQ
select
i.urn as image_urn
from
digitalocean_image as i,
digitalocean_droplet as d
where
i.id::text = image->>'id'
and d.urn = $1;
EOQ
}
query "network_firewalls_for_droplet" {
sql = <<-EOQ
select
f.urn as firewall_urn
from
digitalocean_droplet as d,
digitalocean_firewall as f,
jsonb_array_elements(droplet_ids) as did
where
d.id::text = did::text
and d.urn = $1;
EOQ
}
query "network_floating_ips_for_droplet" {
sql = <<-EOQ
select
f.urn as floating_ip_urn
from
digitalocean_floating_ip as f,
digitalocean_droplet as d
where
d.id = f.droplet_id
and d.urn = $1;
EOQ
}
query "network_load_balancers_for_droplet" {
sql = <<-EOQ
select
l.urn as lb_urn
from
digitalocean_droplet as d,
digitalocean_load_balancer as l,
jsonb_array_elements(droplet_ids) as did
where
d.id::text = did::text
and d.urn = $1;
EOQ
}
query "network_vpcs_for_droplet" {
sql = <<-EOQ
select
v.urn as vpc_urn
from
digitalocean_vpc as v,
digitalocean_droplet as d
where
d.vpc_uuid = v.id
and d.urn = $1;
EOQ
}
query "snapshot_snapshots_for_droplet" {
sql = <<-EOQ
select
s.id as snapshot_urn
from
digitalocean_droplet as d,
jsonb_array_elements(snapshot_ids) as sid,
digitalocean_snapshot as s
where
s.id = sid::text
and d.urn = $1;
EOQ
}
# Card queries
query "droplet_status" {
sql = <<-EOQ
select
'Status' as label,
initcap(status) as value
from
digitalocean_droplet
where
urn = $1;
EOQ
}
query "droplet_storage" {
sql = <<-EOQ
select
disk as "Disk Storage (GB)"
from
digitalocean_droplet
where
urn = $1;
EOQ
}
query "droplet_vcpus" {
sql = <<-EOQ
select
'vCPUs' as label,
vcpus as value
from
digitalocean_droplet
where
urn = $1;
EOQ
}
query "droplet_public_access" {
sql = <<-EOQ
select
'Public Access' as label,
case
when image ->> 'public' = 'true' then 'Enabled'
else 'Disabled'
end as value,
case
when image ->> 'public' = 'true' then 'alert'
else 'ok'
end as "type"
from
digitalocean_droplet
where
urn = $1;
EOQ
}
query "droplet_backup_status" {
sql = <<-EOQ
select
'Backups' as label,
case
when features ? 'backups' then 'Enabled'
else 'Disabled'
end as value,
case
when features ? 'backups' then 'ok'
else 'alert'
end as "type"
from
digitalocean_droplet
where
urn = $1;
EOQ
}
query "droplet_monitoring_status" {
sql = <<-EOQ
select
'Monitoring' as label,
case
when features ? 'monitoring' then 'Enabled'
else 'Disabled'
end as value,
case
when features ? 'monitoring' then 'ok'
else 'alert'
end as "type"
from
digitalocean_droplet
where
urn = $1;
EOQ
}
# Other detail page queries
query "droplet_overview" {
sql = <<-EOQ
select
name as "Name",
id as "ID",
created_at as "Create Time",
image ->> 'distribution' as "Distribution Type",
title as "Title",
region ->> 'name' as "Region",
urn as "URN"
from
digitalocean_droplet
where
urn = $1
EOQ
}
query "droplet_tags" {
sql = <<-EOQ
select
tag.key as "Key",
tag.value as "Value"
from
digitalocean_droplet
join jsonb_each_text(tags) tag on true
where
urn = $1
order by
tag.key;
EOQ
}
query "droplet_attached_volumes" {
sql = <<-EOQ
select
v.name as "Name",
v.id as "ID",
v.created_at as "Create Time",
v.urn as "URN"
from
digitalocean_droplet as d,
jsonb_array_elements_text(d.volume_ids) as volume_id,
digitalocean_volume as v
where
v.id = volume_id
and d.urn = $1
order by
v.name;
EOQ
}
query "droplet_network_vpc_details" {
sql = <<-EOQ
select
vpc.name as "Name",
vpc.urn as "URN",
vpc.id as "ID",
vpc.ip_range as "IP Range",
vpc.created_at as "Create Time"
from
digitalocean_droplet dr
join
digitalocean_vpc vpc
on vpc.id = vpc_uuid
where
dr.urn = $1
order by
vpc.name;
EOQ
}
query "droplet_firewall_configuration" {
sql = <<-EOQ
select
f.name as "Name",
f.id as "ID",
f.created_at as "Create Time",
f.urn as "URN"
from
digitalocean_droplet dr,
digitalocean_firewall f,
jsonb_array_elements(droplet_ids) dr_id
where
dr.id = dr_id::bigint
and dr.urn = $1
order by
f.name;
EOQ
}