Azure NSG Dump: mudanças entre as edições

De Wiki Clusterlab.com.br
Ir para navegação Ir para pesquisar
(Criou página com 'First log in using azure-cli. <br> The script will dump all nsgs in all subscriptions the users is subscribed to json files. One per subscription <br> You may run it from Azur...')
 
Sem resumo de edição
 
Linha 2: Linha 2:
The script will dump all nsgs in all subscriptions the users is subscribed to json files. One per subscription <br>
The script will dump all nsgs in all subscriptions the users is subscribed to json files. One per subscription <br>
You may run it from Azure cloud shell. <br>
You may run it from Azure cloud shell. <br>
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash line=1 highlight=31>
#!/bin/bash
#!/bin/bash
export DATETIME=$(date +"%Y-%m-%d_%H-%M_%S")
export DATETIME=$(date +"%Y-%m-%d_%H-%M_%S")

Edição atual tal como às 11h28min de 27 de abril de 2020

First log in using azure-cli.
The script will dump all nsgs in all subscriptions the users is subscribed to json files. One per subscription
You may run it from Azure cloud shell.

#!/bin/bash
export DATETIME=$(date +"%Y-%m-%d_%H-%M_%S")
function ARQTEMP() {
case $1 in
        criar)
                mktemp -t tempfile.XXXXXX
                ;;
        apagar)
                rm -fr $2
                ;;
esac
}
function GETTOKEN() {
  echo get TOKEN
  # curl -X POST -d 'grant_type=client_credentials&client_id=[APP_ID]&client_secret=[PASSWORD]&resource=https%3A%2F%2Fmanagement.azure.com%2F' https://login.microsoftonline.com/[TENANT_ID]/oauth2/token
}
# https://management.azure.com/subscriptions/<xxxxxxxxxxxxxxxx>/providers/Microsoft.Network/networkSecurityGroups?api-version=2018-07-01
function GETDATA() {
  curl -X GET \
  -H "Authorization: Bearer $2" \
  -H "Content-Type: application/json" https://management.azure.com/subscriptions/$1/providers/Microsoft.Network/networkSecurityGroups?api-version=2018-07-01
}
export ACCOUNTDATA=$(ARQTEMP criar)
az account get-access-token  -o tsv > $ACCOUNTDATA
export ACCESSTOKEN=$(cat $ACCOUNTDATA | awk '{print $1}')
export ACCESSTENANT=$(cat $ACCOUNTDATA | awk '{print $3}')
export ACCESSSUBSCRIPTION=$(cat $ACCOUNTDATA | awk '{print $2}')
ARQTEMP apagar $ACCOUNTDATA
az account list --query "[].[id]" -o tsv | while read SUBSCRIPTION
do
  GETDATA $SUBSCRIPTION $ACCESSTOKEN > $DATETIME-$SUBSCRIPTION.json
done