Skip to content

Commit a6e0764

Browse files
author
Michael Droessler
committed
rewrote azure script to ps1, resource graph for vnet gateways
1 parent 9d3154b commit a6e0764

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

pwsh/lw_azure_inventory.ps1

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
# Script to fetch Azure inventory for Lacework sizing.
3+
# Requirements: az cli
4+
5+
# This script can be run from Azure Cloud Shell.
6+
7+
# Set the initial counts to zero.
8+
$AZURE_VMS=0
9+
$SQL_SERVERS=0
10+
$LOAD_BALANCERS=0
11+
$GATEWAYS=0
12+
13+
function getVMs {
14+
$(az vm list -d --query "[?powerState=='VM running']" | ConvertFrom-Json).Count
15+
}
16+
17+
function getSQLServers {
18+
$(az sql server list | ConvertFrom-Json).Count
19+
}
20+
21+
function getLoadBalancers {
22+
$(az network lb list | ConvertFrom-Json).Count
23+
}
24+
25+
write-host "Starting inventory check."
26+
write-host "Fetching VMs..."
27+
$vms=$(getVMs)
28+
$AZURE_VMS=$(($AZURE_VMS + $vms))
29+
30+
write-host "Fetching SQL Databases..."
31+
$sql=$(getSQLServers)
32+
$SQL_SERVERS=$(($SQL_SERVERS + $sql))
33+
34+
write-host "Fetching Load Balancers..."
35+
$lbs=$(getLoadBalancers)
36+
$LOAD_BALANCERS=$(($LOAD_BALANCERS + $lbs))
37+
38+
write-host "Fetching Gateways..."
39+
#TODO -- replace this with a resource graph query...
40+
# Microsoft.Network/virtualNetworkGateways
41+
# need to run this to avoid an interactive prompt to use the resource graph extension
42+
az config set extension.use_dynamic_install=yes_without_prompt
43+
$GATEWAYS= $(az graph query -q "Resources | where type =~ 'Microsoft.Network/virtualNetworkGateways' | summarize count=count()" | ConvertFrom-Json).data.count
44+
45+
46+
write-host "######################################################################"
47+
write-host "Lacework inventory collection complete."
48+
write-host ""
49+
write-host "Azure VMs: $AZURE_VMS"
50+
write-host "SQL Servers: $SQL_SERVERS"
51+
write-host "Load Balancers: $LOAD_BALANCERS"
52+
write-host "Vnet Gateways: $GATEWAYS"
53+
write-host "===================="
54+
write-host "Total Resources: $(($AZURE_VMS + $SQL_SERVERS + $LOAD_BALANCERS + $GATEWAYS))"

pwsh/lw_gcp_inventory.ps1

Whitespace-only changes.

0 commit comments

Comments
 (0)