-
Notifications
You must be signed in to change notification settings - Fork 7
/
03_02_Enable_Insights.azurecli
99 lines (84 loc) · 3.91 KB
/
03_02_Enable_Insights.azurecli
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
#Define Deployment Variables
appNamePrefix='tws'
locations=(
"westeurope"
"northeurope"
)
#Enable App Service Logs
for i in "${locations[@]}"; do
#Define Deployment Variables
resourceGroupName="${appNamePrefix}-paas-${i}"
resourceGroup=$(az group show --name ${resourceGroupName} --output json)
resourceGroupLocation=$(echo $resourceGroup | jq .location -r)
resourceGroupId=$(echo $resourceGroup | jq .id -r | shasum)
nameSuffix="${resourceGroupId:0:4}"
webAppName="${appNamePrefix}-web-${resourceGroupLocation}-${nameSuffix}"
#Configure App Service Logs
az webapp log config \
--resource-group ${resourceGroupName} \
--name ${webAppName} \
--web-server-logging filesystem
done
#Configure Diagnostic Settings
for i in "${locations[@]}"; do
#Define Deployment Variables
resourceGroupName="${appNamePrefix}-paas-${i}"
resourceGroup=$(az group show --name ${resourceGroupName} --output json)
resourceGroupLocation=$(echo $resourceGroup | jq .location -r)
resourceGroupId=$(echo $resourceGroup | jq .id -r | shasum)
nameSuffix="${resourceGroupId:0:4}"
webAppName="${appNamePrefix}-web-${resourceGroupLocation}-${nameSuffix}"
webAppId=$(az webapp show --resource-group ${resourceGroupName} --name ${webAppName} --query id --output tsv)
storageAccountName="${appNamePrefix}logs${resourceGroupLocation}${nameSuffix}"
#Deploy Storage Account for Logs
storageAccount=$(az storage account create \
--resource-group ${resourceGroupName} \
--location ${resourceGroupLocation} \
--name ${storageAccountName} \
--kind StorageV2 \
--sku Standard_LRS \
--output json)
#Configure Diagnostic Settings on Web App
az monitor diagnostic-settings create \
--name WebAppDiagnostics \
--resource ${webAppId} \
--logs '[{"category": "AppServiceHTTPLogs","enabled": true},{"category": "AppServiceAppLogs","enabled": true},{"category": "AppServicePlatformLogs","enabled": true}]' \
--metrics '[{"category": "AllMetrics","enabled": true}]' \
--storage-account $(echo $storageAccount | jq .id -r)
done
#Enable Application Insights
for i in "${locations[@]}"; do
#Define Deployment Variables
resourceGroupName="${appNamePrefix}-paas-${i}"
resourceGroup=$(az group show --name ${resourceGroupName} --output json)
resourceGroupLocation=$(echo $resourceGroup | jq .location -r)
resourceGroupId=$(echo $resourceGroup | jq .id -r | shasum)
nameSuffix="${resourceGroupId:0:4}"
webAppName="${appNamePrefix}-web-${resourceGroupLocation}-${nameSuffix}"
webAppId=$(az webapp show --resource-group ${resourceGroupName} --name ${webAppName} --query id --output tsv)
appInsightsName="$appNamePrefix-ai-$resourceGroupLocation-$nameSuffix"
#Create Application Insights Component
az monitor app-insights component create \
--resource-group $resourceGroupName \
--location $resourceGroupLocation \
--app $appInsightsName
#Get Instrumentation Key
instrumentationKey=$(az monitor app-insights component show \
--resource-group $resourceGroupName \
--app $appInsightsName \
--query "instrumentationKey" \
--output tsv)
#Enable Application Insights in Web App
az webapp config appsettings set \
--resource-group $resourceGroupName \
--name $webAppName \
--settings "APPINSIGHTS_INSTRUMENTATIONKEY=$instrumentationKey"
az webapp config appsettings set \
--resource-group $resourceGroupName \
--name $webAppName \
--settings "ApplicationInsightsAgent_EXTENSION_VERSION=~2"
az webapp config appsettings set \
--resource-group $resourceGroupName \
--name $webAppName \
--settings "XDT_MicrosoftApplicationInsights_Mode=recommended"
done