-
Notifications
You must be signed in to change notification settings - Fork 1
/
mddashboards.ps1
247 lines (241 loc) · 10.3 KB
/
mddashboards.ps1
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<#
.SYNOPSIS
Adds a Web App Dashboard to your Azure "Ibiza" Portal.
.DESCRIPTION
The Add-AzureRMDashboardStarterWebAppMD creates a new resource group per subscription and generates a dashboard resources which will be visible as a shared source.
On this dashboard following parts will be created:
* A clock (still in the default setting)
* A Markdown part with an overview of all the available Web Apps per that subscription. This overview is in table form and contains:
- the hostname
- the website url(s)
- the Kudu Link
- the Monaco / App Service Editor Link
This generation will be ARM based and the json files can be adapted afterwards or redeployed if needed. Also a rerun will regenerate the files and update the dashboard.
.PARAMETER yourlocation
The location where you an tto desploy the resource group.
.PARAMETER yourmdtitle
The text you want as a header or title for the Markdown part
.PARAMETER yourmdsubtitle
The text you want as a subtitle for the Markdown part
.EXAMPLE
PS C:\> Add-AzureRMDashboardStarterWebAppMD "West Europe"
Generates a default dashboard with all the parts mentioned and with the generic title and substitle for the MD part.
#>
function Add-AzureRMDashboardStarterWebAppMD {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$yourlocation,
[Parameter(Mandatory = $false)]
[string]$yourmdtitle,
[Parameter(Mandatory = $false)]
[string]$yourmdsubtitle
)
Add-AzureRmAccount
new-item .\mddashsub -ItemType Directory -Force
$azuresubs = (Get-AzureRmSubscription|Out-GridView -PassThru)
foreach ($sub in $azuresubs) {
Select-AzureRmSubscription -SubscriptionName $sub.Name
$mdfile = ".\mddashsub\$($sub.Name)webapp.md"
$yourtitle = $sub.Name + " Site Overview for subscription"
$yourname = "mddashboardstarter"+ $sub.Id
$locpartid = 2
$partsjson = ''
$partY = 8
$webappsenvs = Get-AzureRmAppServicePlan
if ($webappsenvs.Count -gt 0) {
Set-Content -Path $mdfile -Value "|hostname|default url|kudu console|monaco/app service editor|\r\n"
add-Content -Path $mdfile -Value "|---|---|---|---|\r\n"
foreach ($webappenv in $webappsenvs) {
$webapps = Get-AzureRmWebApp -AppServicePlan $webappenv
$webappshostnames = $webapps|select name, DefaultHostName,ID #($webapps | select Name, EnabledHostNames)
$partX = 0
for ($pt = 1; $pt -lt 4; $pt++) {
$partsjson += ',' + ( New-AzureRMDashboardStarterWebAppPart -partID $locpartid -posX $partX -posY $partY -resID $webappenv.Id -partType $pt)
$partX += 4
$locpartid++
}
foreach ($wh in $webappshostnames) {
$mdstring = "|$($wh.name) |[$($wh.DefaultHostName)](http://$($wh.DefaultHostName)) |[go](https://$($wh.name).scm.azurewebsites.net)| [go](https://$($wh.name).scm.azurewebsites.net/dev)|\r\n"
add-content -path $mdfile -Value $mdstring
$partsjson += ',' + ( New-AzureRMDashboardStarterWebAppPart -partID $locpartid -posX $partX -posY $partY -resID $wh.Id -partType 4)
$partX+=4
$locpartid++
}
$partY += 2
}
}
$yourmdfile = Get-Content $mdfile
$jsonout = ".\mddashsub\$($sub.Name)_deploymddashboard.json"
$jsonoutparam = ".\mddashsub\$($sub.Name)_deploymddashboard.parameters.json"
#Copy-Item .\mddashboards.json $jsonout
$rsdepjson = Get-Content .\mddashboards.parameters.json
Write-Verbose 'Following parameters will be written to the .parameters.json file'
#$exportparams = @{$yourtitle,$yourname,$yourmdfile, $yourmdtitle,$yourmdsubtitle }
#Write-Verbose $exportparams
$armjson = get-content .\mddashboards.json
$armjson | foreach {$PSItem -replace '<"XXX":{}>',$partsjson} | out-file $jsonout
$rsdepjson | foreach { $PSItem -replace '<YOURTITLE>' , $yourtitle } |
foreach { $PSItem -replace '<YOURNAME>' , $yourname } |
foreach { $PSItem -replace '<YOURMDFILE>', $yourmdfile } |
foreach { $PSItem -replace '<YOURMDTITLE>', $yourmdtitle } |
foreach { $PSItem -replace '<YOURMDSUBTITLE>', $yourmdsubtitle } |
out-file $jsonoutparam
New-AzureRmResourceGroup -Name $yourname -Location $yourlocation
New-AzureRmResourceGroupDeployment -Name $yourname -ResourceGroupName $yourname -TemplateFile $jsonout -TemplateParameterFile $jsonoutparam
}
}
function Add-AzureRMDashboardStarterVMMD {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]$yourlocation,
[Parameter(Mandatory = $false)]
[string]$yourmdtitle,
[Parameter(Mandatory = $false)]
[string]$yourmdsubtitle
)
Add-AzureRmAccount
new-item .\mddashsub -ItemType Directory -Force
$azuresubs = (Get-AzureRmSubscription|Out-GridView -PassThru)
foreach ($sub in $azuresubs) {
Select-AzureRmSubscription -SubscriptionName $sub.Name
$subID = $sub.Id
$mdfile = ".\mddashsub\$($sub.Name)vm.md"
$yourtitle = "$($sub.name) Site Overview for subscription"
$yourname = "mddashboardstarter$($sub.name)"
$rgs = Get-AzureRmResourceGroup
foreach ($rg in $rgs) {
$rgID = $rg.ResourceId
$vms = Get-AzureRmVM -ResourceGroupName $rg.ResourceGroupName
$i = ($vms | measure).Count
if ($i -ne 0) {
foreach ($vm in $vms) {
$tag = "$($vm.Id)"
}
}
}
}
}
function New-AzureRMDashboardStarterWebAppPart {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[int]$partID,
[Parameter(Mandatory = $true)]
[int]$posX,
[Parameter(Mandatory = $true)]
[int]$posY,
[Parameter(Mandatory = $true)]
[string]$resID,
[Parameter(Mandatory = $true)]
[int]$partType
)
switch ($partType) {
#microsoft.web/serverfarms - CPU/MEM
1 {
$partmetrics = "{
""resourceId"": ""$resID"",
""name"": ""CpuPercentage""
},
{
""resourceId"": ""$resID"",
""name"": ""MemoryPercentage""
}"
}
#microsoft.web/serverfarms - IO
2 {
$partmetrics = "{
""resourceId"": ""$resID"",
""name"": ""DiskQueueLength""
},
{
""resourceId"": ""$resID"",
""name"": ""HttpQueueLength""
}"
}
#microsoft.web/serverfarms - bandwidth
3 {
$partmetrics = "{
""resourceId"": ""$resID"",
""name"": ""BytesReceived""
},
{
""resourceId"": ""$resID"",
""name"": ""BytesSent""
}"
}
#microsoft.web/sites - http codes
4 {
$partmetrics = "{
""resourceId"": ""$resID"",
""name"": ""Http2xx""
},
{
""resourceId"": ""$resID"",
""name"": ""Http3xx""
},
{
""resourceId"": ""$resID"",
""name"": ""Http401""
},
{
""resourceId"": ""$resID"",
""name"": ""Http403""
},
{
""resourceId"": ""$resID"",
""name"": ""Http404""
},
{
""resourceId"": ""$resID"",
""name"": ""Http406""
},
{
""resourceId"": ""$resID"",
""name"": ""Http4xx""
},
{
""resourceId"": ""$resID"",
""name"": ""Http5xx""
},
{
""resourceId"": ""$resID"",
""name"": ""Requests""
}"
}
}
$partoutput = """$partID"": {
""position"": {
""x"": $posX,
""y"": $posY,
""rowSpan"": 2,
""colSpan"": 4
},
""metadata"": {
""inputs"": [
{
""name"": ""queryInputs"",
""value"": {
""metrics"": [
$partmetrics
],
""timespan"": {
""duration"": ""PT1H"",
""start"": null,
""end"": null
},
""chartType"": 0
}
}
],
""type"": ""Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart"",
""settings"": {}
}
}"
return $partoutput
}