2022-10-10 08:21:17 -04:00
|
|
|
#!/usr/bin/env bash
|
2022-09-05 12:12:46 -04:00
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
set -euo pipefail
|
|
|
|
shopt -s inherit_errexit
|
|
|
|
|
|
|
|
printf "Fetching logs of instances in resource group %s\n" "${1}"
|
2022-09-05 12:12:46 -04:00
|
|
|
|
|
|
|
# get list of all scale sets
|
2022-11-10 04:28:35 -05:00
|
|
|
scalesetsjson=$(az vmss list --resource-group "${1}" -o json)
|
2023-07-13 10:28:33 -04:00
|
|
|
scalesetslist=$(echo "${scalesetsjson}" | yq eval '.[] | .name' -)
|
|
|
|
subscription=$(az account show | yq eval .id -)
|
2022-09-05 12:12:46 -04:00
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
printf "Checking scalesets %s\n" "${scalesetslist}"
|
2022-09-05 12:12:46 -04:00
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
for scaleset in ${scalesetslist}; do
|
2022-11-10 08:17:04 -05:00
|
|
|
instanceids=$(
|
|
|
|
az vmss list-instances \
|
|
|
|
--resource-group "${1}" \
|
|
|
|
--name "${scaleset}" \
|
|
|
|
-o json |
|
2023-07-13 10:28:33 -04:00
|
|
|
yq eval '.[] | .instanceId' -
|
2022-11-10 08:17:04 -05:00
|
|
|
)
|
|
|
|
printf "Checking instance IDs %s\n" "${instanceids}"
|
|
|
|
for instanceid in ${instanceids}; do
|
|
|
|
bloburi=$(
|
|
|
|
az rest \
|
|
|
|
--method post \
|
|
|
|
--url https://management.azure.com/subscriptions/"${subscription}"/resourceGroups/"${1}"/providers/Microsoft.Compute/virtualMachineScaleSets/"${scaleset}"/virtualmachines/"${instanceid}"/retrieveBootDiagnosticsData?api-version=2022-03-01 |
|
2023-07-13 10:28:33 -04:00
|
|
|
yq eval '.serialConsoleLogBlobUri' -
|
2022-11-10 08:17:04 -05:00
|
|
|
)
|
|
|
|
sleep 4
|
2023-01-19 05:22:31 -05:00
|
|
|
curl -fsSL -o "./${scaleset}-${instanceid}.log" "${bloburi}"
|
2022-11-10 08:17:04 -05:00
|
|
|
realpath "./${scaleset}-${instanceid}.log"
|
|
|
|
done
|
2022-09-05 12:12:46 -04:00
|
|
|
done
|