From 8334a519ec4339814664096ee51cc7c6da9c2ddb Mon Sep 17 00:00:00 2001 From: Cory Fowler Date: Wed, 22 Feb 2017 10:30:56 -0800 Subject: [PATCH] added scripts for Connect, Monitor and Scale --- app-service/connect-to-sql/connect-to-sql.ps1 | 35 +++++++++++++++++++ .../connect-to-storage/connect-to-storage.ps1 | 27 ++++++++++++++ .../monitor-with-logs/monitor-with-logs.ps1 | 26 ++++++++++++++ .../scale-geographic/scale-geographic.ps1 | 28 +++++++++++++++ app-service/scale-manual/scale-manual.ps1 | 20 +++++++++++ 5 files changed, 136 insertions(+) create mode 100644 app-service/connect-to-sql/connect-to-sql.ps1 create mode 100644 app-service/connect-to-storage/connect-to-storage.ps1 create mode 100644 app-service/monitor-with-logs/monitor-with-logs.ps1 create mode 100644 app-service/scale-geographic/scale-geographic.ps1 create mode 100644 app-service/scale-manual/scale-manual.ps1 diff --git a/app-service/connect-to-sql/connect-to-sql.ps1 b/app-service/connect-to-sql/connect-to-sql.ps1 new file mode 100644 index 00000000..0a7fb490 --- /dev/null +++ b/app-service/connect-to-sql/connect-to-sql.ps1 @@ -0,0 +1,35 @@ + +# Generates a Random Value +$Random=(New-Guid).ToString().Substring(0,8) + +# Variables +$ResourceGroup="MyResourceGroup$Random" +$AppName="webappwithSQL$Random" +$Location="West US" +$ServerName="webappwithsql$Random" +$StartIP="0.0.0.0" +$EndIP="0.0.0.0" +$Username="ServerAdmin" +$Password="" +$SqlServerPassword=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,(ConvertTo-SecureString -String $Password -AsPlainText -Force) + +# Create a Resource Group +New-AzureRMResourceGroup -Name $ResourceGroup -Location $Location + +# Create an App Service Plan +New-AzureRMAppservicePlan -Name WebAppwithSQLPlan -ResourceGroupName $ResourceGroup -Location $Location -Tier Basic + +# Create a Web App in the App Service Plan +New-AzureRMWebApp -Name $AppName -ResourceGroupName $ResourceGroup -Location $Location -AppServicePlan WebAppwithSQLPlan + +# Create a SQL Database Server +New-AzureRMSQLServer -ServerName $ServerName -Location $Location -SqlAdministratorCredentials $SqlServerPassword -ResourceGroupName $ResourceGroup + +# Create Firewall Rule for SQL Database Server +New-AzureRmSqlServerFirewallRule -FirewallRuleName "AllowYourIp" -StartIpAddress $StartIP -EndIPAddress $EndIP -ServerName $ServerName -ResourceGroupName $ResourceGroup + +# Create SQL Database in SQL Database Server +New-AzureRMSQLDatabase -ServerName $ServerName -DatabaseName MySampleDatabase -ResourceGroupName $ResourceGroup + +# Assign Connection String to Connection String +Set-AzureRMWebApp -ConnectionStrings @{ MyConnectionString = @{ Type="SQLAzure"; Value ="Server=tcp:$ServerName.database.windows.net;Database=MySampleDatabase;User ID=$Username@$ServerName;Password=$password;Trusted_Connection=False;Encrypt=True;" } } -Name $AppName -ResourceGroupName $ResourceGroup \ No newline at end of file diff --git a/app-service/connect-to-storage/connect-to-storage.ps1 b/app-service/connect-to-storage/connect-to-storage.ps1 new file mode 100644 index 00000000..0f8056db --- /dev/null +++ b/app-service/connect-to-storage/connect-to-storage.ps1 @@ -0,0 +1,27 @@ + +# Generates a Random Value +$Random=(New-Guid).ToString().Substring(0,8) + +# Variables +$ResourceGroup="MyResourceGroup$Random" +$AppName="webappwithStorage$Random" +$StorageName="webappstorage$Random" +$Location="West US" + +# Create a Resource Group +New-AzureRMResourceGroup -Name $ResourceGroup -Location $Location + +# Create an App Service Plan +New-AzureRMAppservicePlan -Name WebAppwithStoragePlan -ResourceGroupName $ResourceGroup -Location $Location -Tier Basic + +# Create a Web App in the App Service Plan +New-AzureRMWebApp -Name $AppName -ResourceGroupName $ResourceGroup -Location $Location -AppServicePlan WebAppwithStoragePlan + +# Create Storage Account +New-AzureRMStorageAccount -Name $StorageName -ResourceGroupName $ResourceGroup -Location $Location -SkuName Standard_LRS + +# Get Connection String for Storage Account +$StorageKey=(Get-AzureRMStorageAccountKey -ResourceGroupName $ResourceGroup -Name $StorageName).Value[0] + +# Assign Connection String to App Setting +Set-AzureRMWebApp -ConnectionStrings @{ MyStorageConnStr = @{ Type="Custom"; Value="DefaultEndpointsProtocol=https;AccountName=$StorageName;AccountKey=$StorageKey;" } } -Name $AppName -ResourceGroupName $ResourceGroup \ No newline at end of file diff --git a/app-service/monitor-with-logs/monitor-with-logs.ps1 b/app-service/monitor-with-logs/monitor-with-logs.ps1 new file mode 100644 index 00000000..e8c39572 --- /dev/null +++ b/app-service/monitor-with-logs/monitor-with-logs.ps1 @@ -0,0 +1,26 @@ + +# Generates a Random Value +$Random=(New-Guid).ToString().Substring(0,8) + +# Variables +$ResourceGroupName="myResourceGroup$Random" +$AppName="AppServiceMonitor$Random" +$Location="WestUS" + +# Create a Resource Group +New-AzureRMResourceGroup -Name $ResourceGroupName -Location $Location + +# Create an App Service Plan +New-AzureRMAppservicePlan -Name AppServiceMonitorPlan -ResourceGroupName $ResourceGroupName -Location $Location -Tier Basic + +# Create a Web App in the App Service Plan +New-AzureRMWebApp -Name $AppName -ResourceGroupName $ResourceGroupName -Location $Location -AppServicePlan AppServiceMonitorPlan + +# Enable Logs +Set-AzureRMWebApp -RequestTracingEnabled $True -HttpLoggingEnabled $True -DetailedErrorLoggingEnabled $True -ResourceGroupName $ResourceGroupName -Name $AppName + +# Make a Request +Invoke-WebRequest -Method "Get" -Uri https://$AppName.azurewebsites.net/404 -ErrorAction SilentlyContinue + +# Download the Web App Logs +#Get-AzureRMWebAppMetrics -ResourceGroupName $ResourceGroupName -Name $AppName -Metrics \ No newline at end of file diff --git a/app-service/scale-geographic/scale-geographic.ps1 b/app-service/scale-geographic/scale-geographic.ps1 new file mode 100644 index 00000000..73512a9e --- /dev/null +++ b/app-service/scale-geographic/scale-geographic.ps1 @@ -0,0 +1,28 @@ + +# Generates a Random Value +$Random=(New-Guid).ToString().Substring(0,8) + +# Variables +$ResourceGroupName="myResourceGroup$Random" +$App1Name="AppServiceTM1$Random" +$App2Name="AppServiceTM2$Random" +$Location1="WestUS" +$Location2="EastUS" + +# Create a Resource Group +New-AzureRMResourceGroup -Name $ResourceGroupName -Location $Location1 + +# Create Traffic Manager Profile +New-AzureRMTrafficManagerProfile -Name "$ResourceGroupName-tmp" -ResourceGroupName $ResourceGroupName -TrafficRoutingMethod Performance -MonitorPath '/' -MonitorProtocol "HTTP" -RelativeDnsName $ResourceGroupName -Ttl 30 -MonitorPort 80 + +# Create an App Service Plan +New-AzureRMAppservicePlan -Name "$App1Name-Plan" -ResourceGroupName $ResourceGroupName -Location $Location1 -Tier Standard +New-AzureRMAppservicePlan -Name "$App2Name-Plan" -ResourceGroupName $ResourceGroupName -Location $Location2 -Tier Standard + +# Create a Web App in the App Service Plan +$App1ResourceId=(New-AzureRMWebApp -Name $App1Name -ResourceGroupName $ResourceGroupName -Location $Location1 -AppServicePlan "$App1Name-Plan").Id +$App2ResourceId=(New-AzureRMWebApp -Name $App2Name -ResourceGroupName $ResourceGroupName -Location $Location2 -AppServicePlan "$App2Name-Plan").Id + +# Create Traffic Manager Endpoints for Web Apps +New-AzureRMTrafficManagerEndpoint -Name "$App1Name-$Location1" -ResourceGroupName $ResourceGroupName -ProfileName "$ResourceGroupName-tmp" -Type AzureEndpoints -TargetResourceId $App1ResourceId -EndpointStatus "Enabled" +New-AzureRMTrafficManagerEndpoint -Name "$App2Name-$Location2" -ResourceGroupName $ResourceGroupName -ProfileName "$ResourceGroupName-tmp" -Type AzureEndpoints -TargetResourceId $App2ResourceId -EndpointStatus "Enabled" \ No newline at end of file diff --git a/app-service/scale-manual/scale-manual.ps1 b/app-service/scale-manual/scale-manual.ps1 new file mode 100644 index 00000000..37ec52d0 --- /dev/null +++ b/app-service/scale-manual/scale-manual.ps1 @@ -0,0 +1,20 @@ + +# Generates a Random Value +$Random=(New-Guid).ToString().Substring(0,8) + +# Variables +$ResourceGroupName="myResourceGroup$random" +$AppName="AppServiceManualScale$random" +$Location="WestUS" + +# Create a Resource Group +New-AzureRMResourceGroup -Name $ResourceGroupName -Location $Location + +# Create an App Service Plan +New-AzureRMAppservicePlan -Name AppServiceManualScalePlan -ResourceGroupName $ResourceGroupName -Location $Location -Tier Basic + +# Create a Web App in the App Service Plan +New-AzureRMWebApp -Name $AppName -ResourceGroupName $ResourceGroup -Location $Location -AppServicePlan AppServiceManualScalePlan + +# Scale Web App to 2 Workers +Set-AzureRMAppServicePlan -NumberofWorkers 2 -Name AppServiceManualScalePlan -ResourceGroupName $ResourceGroupName \ No newline at end of file