forked from lacework-dev/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lw_azure_inventory.sh
executable file
·61 lines (49 loc) · 1.41 KB
/
lw_azure_inventory.sh
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
#!/bin/bash
# Script to fetch Azure inventory for Lacework sizing.
# Requirements: az cli, jq
# This script can be run from Azure Cloud Shell.
# Set the initial counts to zero.
AZURE_VMS=0
SQL_SERVERS=0
LOAD_BALANCERS=0
GATEWAYS=0
function getResourceGroups {
az group list | jq -r '.[] | .name'
}
function getVMs {
az vm list -d --query "[?powerState=='VM running']" | jq length
}
function getSQLServers {
az sql server list | jq length
}
function getLoadBalancers {
az network lb list | jq length
}
function getGateways {
RG=$1
az network vnet-gateway list --resource-group $RG | jq length
}
echo "Starting inventory check."
echo "Fetching VMs..."
vms=$(getVMs)
AZURE_VMS=$(($AZURE_VMS + $vms))
echo "Fetching SQL Databases..."
sql=$(getSQLServers)
SQL_SERVERS=$(($SQL_SERVERS + $sql))
echo "Fetching Load Balancers..."
lbs=$(getLoadBalancers)
LOAD_BALANCERS=$(($LOAD_BALANCERS + $lbs))
echo "Fetching Gateways..."
for group in $(getResourceGroups); do
gw=$(getGateways $group)
GATEWAYS=$(($GATEWAYS + $gw))
done
echo "######################################################################"
echo "Lacework inventory collection complete."
echo ""
echo "Azure VMs: $AZURE_VMS"
echo "SQL Servers: $SQL_SERVERS"
echo "Load Balancers: $LOAD_BALANCERS"
echo "Vnet Gateways: $GATEWAYS"
echo "===================="
echo "Total Resources: $(($AZURE_VMS + $SQL_SERVERS + $LOAD_BALANCERS + $GATEWAYS))"