-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute_network_dashboard.sp
216 lines (182 loc) · 4 KB
/
compute_network_dashboard.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
dashboard "compute_network_dashboard" {
title = "GCP Compute Network Dashboard"
documentation = file("./dashboards/compute/docs/compute_network_dashboard.md")
tags = merge(local.compute_common_tags, {
type = "Dashboard"
})
container {
card {
query = query.compute_network_count
width = 3
}
card {
query = query.compute_network_total_mtu
width = 3
}
card {
query = query.compute_network_default_count
width = 3
}
card {
query = query.compute_network_no_subnet_count
width = 3
}
}
container {
title = "Assessments"
chart {
title = "Default Networks"
type = "donut"
width = 4
query = query.compute_network_default_status
series "count" {
point "non-default" {
color = "ok"
}
point "default" {
color = "alert"
}
}
}
chart {
title = "Empty Networks (No Subnets)"
type = "donut"
width = 4
query = query.compute_network_subnet_status
series "count" {
point "non-empty" {
color = "ok"
}
point "empty" {
color = "alert"
}
}
}
}
container {
title = "Analysis"
chart {
title = "Networks by Project"
query = query.compute_network_by_project
type = "column"
width = 4
}
chart {
title = "Networks by Routing Mode"
query = query.compute_network_by_routing_mode
type = "column"
width = 4
}
chart {
title = "Networks by Creation Mode"
query = query.compute_network_by_creation_mode
type = "column"
width = 4
}
}
}
# Card Queries
query "compute_network_count" {
sql = <<-EOQ
select count(*) as "Networks" from gcp_compute_network;
EOQ
}
query "compute_network_total_mtu" {
sql = <<-EOQ
select sum(mtu) as "Total MTU (Bytes)" from gcp_compute_network;
EOQ
}
query "compute_network_default_count" {
sql = <<-EOQ
select
count(*) as value,
'Default Networks' as label,
case count(*) when 0 then 'ok' else 'alert' end as type
from
gcp_compute_network
where
name = 'default';
EOQ
}
query "compute_network_no_subnet_count" {
sql = <<-EOQ
select
count(*) as value,
'Networks Without Subnets' as label,
case when count(*) = 0 then 'ok' else 'alert' end as type
from
gcp_compute_network as n
left join gcp_compute_subnetwork as s on n.name = s.network_name
where
s.id is null;
EOQ
}
# Assessment Queries
query "compute_network_default_status" {
sql = <<-EOQ
select
case
when name = 'default' then 'default'
else 'non-default'
end as default_status,
count(*)
from
gcp_compute_network
group by
default_status;
EOQ
}
query "compute_network_subnet_status" {
sql = <<-EOQ
select
case when s.id is null then 'empty' else 'non-empty' end as status,
count(distinct n.id)
from
gcp_compute_network n
left join gcp_compute_subnetwork s on s.network_name = n.name
group by
status;
EOQ
}
# Analysis Queries
query "compute_network_by_project" {
sql = <<-EOQ
select
p.title as "Project",
count(n.*) as "total"
from
gcp_compute_network as n,
gcp_project as p
where
p.project_id = n.project
group by
p.title
order by count(n.*) desc;
EOQ
}
query "compute_network_by_routing_mode" {
sql = <<-EOQ
select
routing_mode as "Routing Mode",
count(*) as "networks"
from
gcp_compute_network
group by
routing_mode
order by
routing_mode;
EOQ
}
query "compute_network_by_creation_mode" {
sql = <<-EOQ
select
case when auto_create_subnetworks then 'auto' else 'custom' end as "Creation Mode",
count(*) as "networks"
from
gcp_compute_network
group by
auto_create_subnetworks
order by
auto_create_subnetworks;
EOQ
}