再来继续谈谈Azure China中AVD session host的监控问题,之前说了WVDAgentHealthStatus这个query目前在21v Azure中还不可用,既然这样的话,想用Log Analytics来监控看来是实现不了了
这种情况下不妨换个思路,PowerShell或者CLI应该是可以获取到session host的状态的,唯一有问题的可能是配置告警,PowerShell本身是不提供这种alert的功能的,只能靠自己想办法了,发邮件PowerShell本身就可以做,只是需要两个问题
- 这个监控脚本需要定期执行,需要考虑下在哪里执行这个脚本
- 发邮件的话,账号密码是明文的,需要考虑下保密性问题
而这两个问题用Azure Automation其实恰好都能解决,automation account本来就是用于定期执行脚本的,而账号密码的话可以通过automation account里的Credentials解决
具体的执行也不是很复杂,首先在automation account里添加一个credential
credential里可以指定好用户名和密码,对应的就是我们邮箱账号的账户名密码,保存在credential里之后,就不需要在代码中明文指定这些账号信息了,起码从代码里不至于造成密码泄露
之后就是具体的代码了,runbook和schedule的创建之类的就比较基础了,不准备一步步都写上,创建一个runbook还有link好schedule之后,把用户监控session host状态的脚本附上
$AzureContext = (Connect-AzAccount -Identity -Environment AzureChinaCloud).context
# set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext
Select-AzSubscription -SubscriptionId "xxxxxxxxx";
$MyCred = Get-AutomationPSCredential -Name 'o3ma'
[string[]]$unhealthlist = @()
$unhealthlist += "<html>"
$IsUnhealthy = $false
#这里用于定义hostpool的名字和对应的resource group
$VDIPools = [ordered]@{
'xxxxx-xxxxx-01' = 'xxxxx-xxxxx-xxxx-rg-01'
'xxxxx-xxxxx-xxx-01' = 'xxxxx-xxxxx-xx-xxxxx-rg-01'
'xxxxx-xxxxx-xxx-01' = 'xxxxx-xxxxx-xxx-xxxxx-rg-01'
'xxxxx-xxxxx-xxx-01' = 'xxxxx-xxxxx-xxx-xxxxx-rg-01'
'xxxxx-xxxx-01' = 'xxxxx-xxxx-xxx-rg-01'
'xxxxx-xxxx-01' = 'xxxxx-xxx-rg-01'
'xxxxx-xxxx-01' = 'xxxxx-xxxx-xxxx-rg-01'
'xxxxx-xxxxx-01' = 'xxxxx-xxxx-xxxx-rg-01'
}
foreach ($VDIPool in $VDIPools.GetEnumerator()) {
$sessionhosts = Get-AzWvdSessionHost -ResourceGroupName $VDIPool.value -HostPoolName $VDIPool.key
foreach ($sessionhost in $sessionhosts) {
if ($sessionhost.Status -eq "Available") {
$unhealthlist += "$($sessionhost.Name) status is $($sessionhost.Status) <br>"
$IsUnhealthy = $true
}
}
}
if ($IsUnhealthy) {
$unhealthlist += "</html>"
$unhealthliststring = $unhealthlist | out-string # convert array to string as Send-MailMessage does not support array as body
Send-MailMessage -SmtpServer 'smtp.office365.com' -Port 587 -UseSsl -Credential $MyCred -From '[email protected]' -To '[email protected]' -Subject "SMTP Client Submission - $(Get-Date -Format g)" -Body $unhealthliststring -BodyAsHtml
}
else {
write-output "All session hosts are healthy"
}
之后把runbook跑起来
有不可用的session host就可以收到邮件了
标签:01,xxxx,xxx,host,session,rg,VDI,xxxxx From: https://blog.51cto.com/mxyit/6101374