-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
srozemuller
committed
May 26, 2024
1 parent
60a7367
commit 0400b79
Showing
6 changed files
with
341 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
WVDCheckpoints | where (Name=="ProfileLoggedOff" or Name=="ODFCLoggedOff") and (Source=="RDAgent" or Source=="FSLogix") and TimeGenerated>ago(360d) | ||
| extend HostPool=tostring(split(_ResourceId,"/")[8]), ProfileType=iff(Name=="ProfileLoggedOff","Profile","ODFC") | ||
| summarize arg_max(TimeGenerated, *) by UserName, _ResourceId, ProfileType | ||
| extend ["VHD Size On Disk"]=todouble(replace_string(replace_string(tostring(Parameters.VHDSizeOnDisk),",",""),".","")),["VHD Free Space"]=todouble(replace_string(tostring(Parameters.VHDFreeSpace),",",".")),["VHD Max Size"]=todouble(replace_string(tostring(Parameters.MaxVHDSize),",",".")) | ||
| where ["VHD Size On Disk"]!="" | ||
| extend ["VHD Free Space"]=iff(["VHD Free Space"]>["VHD Max Size"],["VHD Free Space"]/1024.0,["VHD Free Space"]) | ||
| project HostPool, UserName, TimeStamp=TimeGenerated,ProfileType, ["VHD Size On Disk"], ["VHD Free Space"], ["VHD Max Size"], Usage=100*(["VHD Max Size"]-["VHD Free Space"])/["VHD Max Size"] | ||
| order by ["Usage"] desc |
215 changes: 215 additions & 0 deletions
215
LogicApps/AVD/FSLogix/StorageAccountFileShare/send-email-with-fileshare-usage.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
{ | ||
"definition": { | ||
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", | ||
"actions": { | ||
"Parse_file_share_body": { | ||
"inputs": { | ||
"content": "@body('Send_HTTP_GET_request_to_fileshare')", | ||
"schema": { | ||
"properties": { | ||
"etag": { | ||
"type": "string" | ||
}, | ||
"id": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"properties": { | ||
"properties": { | ||
"accessTier": { | ||
"type": "string" | ||
}, | ||
"accessTierChangeTime": { | ||
"type": "string" | ||
}, | ||
"lastModifiedTime": { | ||
"type": "string" | ||
}, | ||
"leaseState": { | ||
"type": "string" | ||
}, | ||
"leaseStatus": { | ||
"type": "string" | ||
}, | ||
"shareQuota": { | ||
"type": "integer" | ||
}, | ||
"shareUsageBytes": { | ||
"type": "integer" | ||
}, | ||
"signedIdentifiers": { | ||
"type": "array" | ||
} | ||
}, | ||
"type": "object" | ||
}, | ||
"type": { | ||
"type": "string" | ||
} | ||
}, | ||
"type": "object" | ||
} | ||
}, | ||
"runAfter": { | ||
"Send_HTTP_GET_request_to_fileshare": [ | ||
"SUCCEEDED" | ||
] | ||
}, | ||
"type": "ParseJson" | ||
}, | ||
"PercentUsage": { | ||
"inputs": { | ||
"name": "percentUsage", | ||
"value": "@mul(div(variables('shareUsage'),variables('fileShareSize')),100)" | ||
}, | ||
"runAfter": { | ||
"Set_Fileshare_size": [ | ||
"SUCCEEDED" | ||
], | ||
"ShareUsageInGB": [ | ||
"SUCCEEDED" | ||
] | ||
}, | ||
"type": "SetVariable" | ||
}, | ||
"Send_HTTP_GET_request_to_fileshare": { | ||
"inputs": { | ||
"authentication": { | ||
"audience": "https://management.azure.com", | ||
"type": "ManagedServiceIdentity" | ||
}, | ||
"method": "GET", | ||
"uri": "https://management.azure.com/subscriptions/5cdde9cd-9196-4483-94e9-e220a9ba8c7d/resourceGroups/infr-avddevfs-nonp-we-RG/providers/Microsoft.Storage/storageAccounts/infravddevnwest01/fileServices/default/shares/userprofile?$expand=stats&api-version=2023-01-01" | ||
}, | ||
"runAfter": { | ||
"fileShareSize_variable": [ | ||
"SUCCEEDED" | ||
] | ||
}, | ||
"runtimeConfiguration": { | ||
"contentTransfer": { | ||
"transferMode": "Chunked" | ||
} | ||
}, | ||
"type": "Http" | ||
}, | ||
"Send_an_email_(V2)": { | ||
"inputs": { | ||
"body": { | ||
"Body": "<p>Hi handsome,</p><br><p>I did a check on the file share <b>@{body('Parse_file_share_body')?['name']}<b> for its size and free space. </p><p>This is the result:</p><p>- File share size: @{variables('fileShareSize')} </p><p>- In use: @{variables('shareUsage')}</p><br><p>That is @{variables('percentUsage')}% of the total</p><br><p><a href=\"https://portal.azure.com/subscriptions/5cdde9cd-9196-4483-94e9-e220a9ba8c7d/resourceGroups/infr-avddevfs-nonp-we-RG/providers/Microsoft.Storage/storageAccounts/infravddevnwest01\">Go to storage account infravddevnwest01</a></p>", | ||
"Importance": "Normal", | ||
"Subject": "[Monitoring] File share disk size check on: @{body('Parse_file_share_body')?['name']}", | ||
"To": "[email protected]" | ||
}, | ||
"host": { | ||
"connection": { | ||
"referenceName": "office365" | ||
} | ||
}, | ||
"method": "post", | ||
"path": "/v2/Mail" | ||
}, | ||
"runAfter": { | ||
"Parse_file_share_body": [ | ||
"SUCCEEDED" | ||
], | ||
"PercentUsage": [ | ||
"SUCCEEDED" | ||
], | ||
"Set_Fileshare_size": [ | ||
"SUCCEEDED" | ||
] | ||
}, | ||
"type": "ApiConnection" | ||
}, | ||
"Set_Fileshare_size": { | ||
"inputs": { | ||
"name": "fileShareSize", | ||
"value": "@body('Parse_file_share_body')?['properties']?['shareQuota']" | ||
}, | ||
"runAfter": { | ||
"Parse_file_share_body": [ | ||
"SUCCEEDED" | ||
] | ||
}, | ||
"type": "SetVariable" | ||
}, | ||
"ShareUsageInGB": { | ||
"inputs": { | ||
"name": "shareUsage", | ||
"value": "@div(body('Parse_file_share_body')?['properties']?['shareUsageBytes'],1073741824)" | ||
}, | ||
"runAfter": { | ||
"Parse_file_share_body": [ | ||
"SUCCEEDED" | ||
] | ||
}, | ||
"type": "SetVariable" | ||
}, | ||
"fileShareSize_variable": { | ||
"inputs": { | ||
"variables": [ | ||
{ | ||
"name": "fileShareSize", | ||
"type": "integer" | ||
} | ||
] | ||
}, | ||
"runAfter": { | ||
"shareUsage_variable": [ | ||
"SUCCEEDED" | ||
] | ||
}, | ||
"type": "InitializeVariable" | ||
}, | ||
"percentUsage_variable": { | ||
"inputs": { | ||
"variables": [ | ||
{ | ||
"name": "percentUsage", | ||
"type": "integer" | ||
} | ||
] | ||
}, | ||
"runAfter": {}, | ||
"type": "InitializeVariable" | ||
}, | ||
"shareUsage_variable": { | ||
"inputs": { | ||
"variables": [ | ||
{ | ||
"name": "shareUsage", | ||
"type": "integer" | ||
} | ||
] | ||
}, | ||
"runAfter": { | ||
"percentUsage_variable": [ | ||
"SUCCEEDED" | ||
] | ||
}, | ||
"type": "InitializeVariable" | ||
} | ||
}, | ||
"contentVersion": "1.0.0.0", | ||
"outputs": {}, | ||
"triggers": { | ||
"Recurrence": { | ||
"recurrence": { | ||
"frequency": "Day", | ||
"interval": 1, | ||
"schedule": { | ||
"hours": [ | ||
"8" | ||
] | ||
}, | ||
"timeZone": "W. Europe Standard Time" | ||
}, | ||
"type": "Recurrence" | ||
} | ||
} | ||
}, | ||
"kind": "Stateful" | ||
} |
42 changes: 42 additions & 0 deletions
42
LogicApps/AVD/Session host health/findsessionhosthealthbytag.kql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// This log search finds session hosts in the provided host pool and looks for its health state. Only the session host with the host pool's deployment color will be searched for. | ||
let HostPoolName = "infra-avd-dev-vdpool"; | ||
let TagValueToSearch = toscalar( | ||
arg("").Resources | ||
| where type == "microsoft.desktopvirtualization/hostpools" | ||
| where name == HostPoolName | ||
| extend TagsParsed = parse_json(tags) | ||
| extend DeploymentColor = tostring(TagsParsed.deploymentcolor) | ||
| project DeploymentColor | ||
); | ||
arg("").desktopvirtualizationresources | ||
| extend HostPool = tostring(split(name, "/")[0]) | ||
| where type == "microsoft.desktopvirtualization/hostpools/sessionhosts" | ||
| where HostPool == HostPoolName | ||
| extend VmResourceId = tolower(properties.resourceId) | ||
| join kind=innerunique ( | ||
VMComputer | ||
| extend VmResourceId = tolower(_ResourceId) | ||
| lookup ( | ||
arg("").Resources | ||
| where type == 'microsoft.compute/virtualmachines' | ||
| where tostring(tags.deploymentcolor) == TagValueToSearch | ||
| project VmResourceId=tolower(id), vmTags=tags | ||
) | ||
on VmResourceId | ||
) | ||
on VmResourceId | ||
| mv-expand healthCheckData=properties.sessionHostHealthCheckResults | ||
| extend | ||
healthCheckResult = healthCheckData.healthCheckResult, | ||
healthCheckName = tostring(healthCheckData.healthCheckName), | ||
additionalHealthCheckStatus = tostring(healthCheckData.additionalFailureDetails.message), | ||
lastHealthCheckDateTime = todatetime(healthCheckData.additionalFailureDetails.lastHealthCheckDateTime) | ||
| where healthCheckResult !contains "Succeeded" | ||
| summarize arg_max(lastHealthCheckDateTime, *) by healthCheckName | ||
| project | ||
VmResourceId, | ||
HostPool, | ||
tostring(healthCheckName), | ||
tostring(healthCheckResult), | ||
tostring(lastHealthCheckDateTime), | ||
tostring(additionalHealthCheckStatus) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Virtual Machine available memory. | ||
InsightsMetrics | ||
| where TimeGenerated > ago(1h) | ||
| where Origin == "vm.azm.ms" | ||
| where Namespace == "Memory" | ||
| where Name == "AvailableMB" | ||
| join kind=inner( | ||
VMComputer | ||
) on _ResourceId | ||
| extend PercentAvailable = 100*(Val/PhysicalMemoryMB) | ||
| summarize AvailablePercent = avg(PercentAvailable) by bin(TimeGenerated, 5m), Computer | ||
| order by Computer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"bindings": [ | ||
{ | ||
"name": "Timer", | ||
"type": "timerTrigger", | ||
"direction": "in", | ||
"schedule": "0 30 * * * *" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Input bindings are passed in via param block. | ||
param($Timer) | ||
|
||
# Get the current West Europe time in the default string format. | ||
$currentTime = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId( (Get-Date), 'W. Europe Standard Time').ToString('yyyy-MM-dd HH:mm:ss') | ||
$informationPreference = 'Continue' | ||
# Write an information log with the current time. | ||
Write-Output "PowerShell timer trigger function ran! TIME: $currentTime" | ||
# Connect to Azure using the system assigned identity | ||
Connect-AzAccount -Identity | ||
|
||
$ProgressPreference = "SilentlyContinue" | ||
$azureApiUrl = "https://management.azure.com" | ||
$keyvaultToken = Get-AzAccessToken -ResourceUrl "https://vault.azure.net" | ||
$token = Get-AzAccessToken -ResourceUrl $azureApiUrl | ||
$azureHeaders = @{ | ||
'Content-Type' = 'application/json' | ||
Authorization = "Bearer $token" #-f $keyvaultToken.token | ||
} | ||
|
||
|
||
try { | ||
import-module .\Modules\mem-monitor-functions.psm1 | ||
} | ||
catch { | ||
Write-Error "Functions module not found!" | ||
exit; | ||
} | ||
try { | ||
$authHeader = Get-AuthApiToken -resource $env:graphApiUrl | ||
} | ||
catch { | ||
Throw "No token received, $_" | ||
} | ||
|
||
try { | ||
Write-Information "Searching for certificates in key vault" -InformationAction Continue | ||
$breakglassCertificateUrl = "{0}/certificates/{1}/versions?api-version=7.0&maxresults=25&_=1714746115235" -f $env:KEYVAULT_URL, $env:BREAKGLASS_CERTNAME | ||
$results = Invoke-RestMethod -Uri $breakglassCertificateUrl -Headers $azureHeaders -Method Get | ||
} | ||
catch { | ||
Throw "Unable to request certificates, $_" | ||
} | ||
|
||
try { | ||
#Renew the certificate | ||
$certificate = | ||
|
||
$renewUrl = "{0}/certificates/{1}/versions/{2}/create?action=Renew&api-version=7.0" -f $env:KEYVAULT_URL, $env:BREAKGLASS_CERTNAME, $certificate.properties.version | ||
|
||
} | ||
catch { | ||
|
||
} |