-
Notifications
You must be signed in to change notification settings - Fork 2
/
compute_virtual_machine_scale_set_dashboard.sp
352 lines (315 loc) · 8.64 KB
/
compute_virtual_machine_scale_set_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
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
dashboard "compute_virtual_machine_scale_set_dashboard" {
title = "Azure Compute Virtual Machine Scale Set Dashboard"
documentation = file("./dashboards/compute/docs/compute_virtual_machine_scale_set_dashboard.md")
tags = merge(local.compute_common_tags, {
type = "Dashboard"
})
container {
# Analysis
card {
query = query.compute_virtual_machine_scale_set_count
width = 3
}
card {
query = query.compute_virtual_machine_scale_set_host_encryption_count
width = 3
}
# Assessments
card {
query = query.compute_virtual_machine_scale_set_logging_disabled
width = 3
}
card {
query = query.compute_virtual_machine_scale_set_log_analytics_agent_installed_count
width = 3
}
}
container {
title = "Assessments"
chart {
title = "Host Encryption Status"
query = query.compute_virtual_machine_scale_set_by_host_encryption_status
type = "donut"
width = 2
series "count" {
point "encrypted" {
color = "ok"
}
point "unencrypted" {
color = "alert"
}
}
}
chart {
title = "Logging Status"
query = query.compute_virtual_machine_scale_set_by_logging_status
type = "donut"
width = 2
series "count" {
point "enabled" {
color = "ok"
}
point "disabled" {
color = "alert"
}
}
}
chart {
title = "Log Analytic Agent Status"
query = query.compute_virtual_machine_scale_set_by_log_analytics_agent_installed_status
type = "donut"
width = 2
series "count" {
point "installed" {
color = "ok"
}
point "not installed" {
color = "alert"
}
}
}
}
container {
title = "Analysis"
chart {
title = "Scale Sets by Subscription"
query = query.compute_virtual_machine_scale_set_by_subscription
type = "column"
width = 3
}
chart {
title = "Scale Sets by Resource Group"
query = query.compute_virtual_machine_scale_set_by_resource_group
type = "column"
width = 3
}
chart {
title = "Scale Sets by Region"
query = query.compute_virtual_machine_scale_set_by_region
type = "column"
width = 3
}
chart {
title = "Scale Sets by Tier"
query = query.compute_virtual_machine_scale_set_by_tier
type = "column"
width = 3
}
}
}
# Card Queries
query "compute_virtual_machine_scale_set_count" {
sql = <<-EOQ
select count(*) as "Virtual Machine Scale Sets" from azure_compute_virtual_machine_scale_set;
EOQ
}
query "compute_virtual_machine_scale_set_host_encryption_count" {
sql = <<-EOQ
select
count(*) as value,
'Unencrypted Host' as label,
case count(*) when 0 then 'ok' else 'alert' end as type
from
azure_compute_virtual_machine_scale_set
where
virtual_machine_security_profile -> 'encryptionAtHost' <> 'true'
or virtual_machine_security_profile -> 'encryptionAtHost' is null;
EOQ
}
query "compute_virtual_machine_scale_set_logging_disabled" {
sql = <<-EOQ
with logging_details as (
select
distinct a.id as vm_scale_set_id
from
azure_compute_virtual_machine_scale_set as a,
jsonb_array_elements(extensions) as b
where
(b ->> 'Publisher' = 'Microsoft.Azure.Diagnostics'
and b ->> 'ExtensionType' = 'IaaSDiagnostics'
or
(b ->> 'Publisher' = any(ARRAY ['Microsoft.OSTCExtensions', 'Microsoft.Azure.Diagnostics']))
and b ->> 'ExtensionType' = 'LinuxDiagnostic')
)
select
count(*) as value,
'Logging Disabled' as label,
case when count(*) = 0 then 'ok' else 'alert' end as type
from
azure_compute_virtual_machine_scale_set as a
left join logging_details as b on a.id = b.vm_scale_set_id
where
b.vm_scale_set_id is null;
EOQ
}
query "compute_virtual_machine_scale_set_log_analytics_agent_installed_count" {
sql = <<-EOQ
with agent_installed_vm_scale_set as (
select
distinct a.id as vm_id
from
azure_compute_virtual_machine_scale_set as a,
jsonb_array_elements(extensions) as b
where
b ->> 'Publisher' = 'Microsoft.EnterpriseCloud.Monitoring'
and b ->> 'ExtensionType' = any(ARRAY ['MicrosoftMonitoringAgent', 'OmsAgentForLinux'])
and b ->> 'ProvisioningState' = 'Succeeded'
and b -> 'Settings' ->> 'workspaceId' is not null
)
select
count(*) as value,
'Log Analytics Agent Installed' as label,
case count(*) when 0 then 'alert' else 'ok' end as type
from
azure_compute_virtual_machine_scale_set as a
left join agent_installed_vm_scale_set as b on a.id = b.vm_id
where
b.vm_id is not null;
EOQ
}
# Assessment Queries
query "compute_virtual_machine_scale_set_by_host_encryption_status" {
sql = <<-EOQ
select
encryption,
count(*)
from (
select virtual_machine_security_profile -> 'encryptionAtHost',
case when virtual_machine_security_profile -> 'encryptionAtHost' <> 'true' or virtual_machine_security_profile -> 'encryptionAtHost' is null then 'unencrypted'
else 'encrypted'
end encryption
from
azure_compute_virtual_machine_scale_set) as vmss
group by
encryption
order by
encryption;
EOQ
}
query "compute_virtual_machine_scale_set_by_logging_status" {
sql = <<-EOQ
with logging_details as (
select
distinct a.id as vm_scale_set_id
from
azure_compute_virtual_machine_scale_set as a,
jsonb_array_elements(extensions) as b
where
(b ->> 'Publisher' = 'Microsoft.Azure.Diagnostics'
and b ->> 'ExtensionType' = 'IaaSDiagnostics'
or
(b ->> 'Publisher' = any(ARRAY ['Microsoft.OSTCExtensions', 'Microsoft.Azure.Diagnostics']))
and b ->> 'ExtensionType' = 'LinuxDiagnostic')
)
select
set_id,
count(*)
from (
select b.vm_scale_set_id,
case when b.vm_scale_set_id is not null then
'enabled'
else
'disabled'
end set_id
from
azure_compute_virtual_machine_scale_set as a
left join logging_details as b on a.id = b.vm_scale_set_id) as vmss
group by
set_id
order by
set_id;
EOQ
}
query "compute_virtual_machine_scale_set_by_log_analytics_agent_installed_status" {
sql = <<-EOQ
with agent_installed_vm_scale_set as (
select
distinct a.id as vm_id
from
azure_compute_virtual_machine_scale_set as a,
jsonb_array_elements(extensions) as b
where
b ->> 'Publisher' = 'Microsoft.EnterpriseCloud.Monitoring'
and b ->> 'ExtensionType' = any(ARRAY ['MicrosoftMonitoringAgent', 'OmsAgentForLinux'])
and b ->> 'ProvisioningState' = 'Succeeded'
and b -> 'Settings' ->> 'workspaceId' is not null
)
select
status,
count(*)
from (
select
b.vm_id,
case when b.vm_id is not null then
'installed'
else
'not installed'
end status
from
azure_compute_virtual_machine_scale_set as a
left join agent_installed_vm_scale_set as b on a.id = b.vm_id) as vmss
group by
status
order by
status;
EOQ
}
# Analysis Queries
query "compute_virtual_machine_scale_set_by_subscription" {
sql = <<-EOQ
select
a.title as "Subscription",
count(vmss.*) as "Scale Sets"
from
azure_compute_virtual_machine_scale_set as vmss,
azure_subscription as a
where
a.subscription_id = vmss.subscription_id
group by
a.title
order by
a.title;
EOQ
}
query "compute_virtual_machine_scale_set_by_resource_group" {
sql = <<-EOQ
select
resource_group || ' [' || sub.title || ']' as "Resource Group",
count(s.*) as "Scale Sets"
from
azure_compute_virtual_machine_scale_set as s,
azure_subscription as sub
where
s.subscription_id = sub.subscription_id
group by
resource_group, sub.title
order by
resource_group;
EOQ
}
query "compute_virtual_machine_scale_set_by_region" {
sql = <<-EOQ
select
region as "Region",
count(*) as "Scale sets"
from
azure_compute_virtual_machine_scale_set
group by
region
order by
region;
EOQ
}
query "compute_virtual_machine_scale_set_by_tier" {
sql = <<-EOQ
select
sku_tier as "Tier",
count(sku_tier) as "Scale sets"
from
azure_compute_virtual_machine_scale_set
group by
sku_tier
order by
sku_tier;
EOQ
}