0
点赞
收藏
分享

微信扫一扫

Automation 结合Logic Apps触发告警 - 配置

创建好Logic Apps之后,我们来看看如何实现automation以及logic apps的联动

首先先配置logic apps,先设置好触发器,我们这里用HTTP的触发器

Automation 结合Logic Apps触发告警 - 配置_Azure

然后设计好body的结构,主要就需要邮件的body, subject, to等

{
"properties": {
"email": {
"properties": {
"body": {
"type": "string"
},
"subject": {
"type": "string"
},
"to": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}

设置好trigger之后,会看到这里会生成一个URL,这个就是可以让我们用HTTP来调用的一个endpoint了

Automation 结合Logic Apps触发告警 - 配置_HTTP_02


接下来就可以设置具体执行的操作了,添加一个新的步骤就是发送邮件,logic apps这点做的很好就是操作起来非常简单,添加一个Office 365 Outlook的action组件,然后直接登录下自己的邮箱账号,后来会常见一个connection出来,之后就可以设置自己想要的操作了,我们这里直接设置发送邮件即可

Automation 结合Logic Apps触发告警 - 配置_logic apps_03


然后邮件的各种内容,都是从之前的HTTP Post请求里读出来的

Automation 结合Logic Apps触发告警 - 配置_HTTP_04

这样logic apps的部分就设置好了,相对来说还是挺简单的,不需要任何框架,也不需要有coding,鼠标点点就可以了

之后在automation里创建用来监控session host的runbook

Automation 结合Logic Apps触发告警 - 配置_发送邮件_05


相关代码如下,本质上和之前直接用Send-MailMessage发邮件区别不大,只是把发邮件的内容替换成了用HTTP请求来trigger logic apps

$AzureContext = (Connect-AzAccount -Identity).context
# set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext
Select-AzSubscription -SubscriptionId "xxx";

[string[]]$unhealthlist = @()
$IsUnhealthy = $false

$VDIPools = [ordered]@{
'avdtest' = 'avd'
}

foreach ($VDIPool in $VDIPools.GetEnumerator()) {

$sessionhosts = Get-AzWvdSessionHost -ResourceGroupName $VDIPool.value -HostPoolName $VDIPool.key
foreach ($sessionhost in $sessionhosts) {
if ($sessionhost.Status -ne "Available") {

$unhealthlist += "$($sessionhost.Name) status is $($sessionhost.Status) <br>"
$IsUnhealthy = $true

}

}

}

if ($IsUnhealthy) {

$Body = @"
{
"email" : {
"to" : "xxxx",
"subject" : "Azure VDI Health Alert",
"body": "$unhealthlist"
}

}
"@

Invoke-WebRequest -Uri "https://prod-02.eastasia.logic.azure.com:443/workflows/6c0xxb4/triggers/manual/paths/invoke?api-version=2016-xxxx" -Method Post -Body $Body -ContentType "application/json"


}
else {

write-output "All session hosts are healthy"

}

然后我们设置runbook每隔多久运行一次,或者手动trigger下试试

可以看到logic apps被正常触发了

Automation 结合Logic Apps触发告警 - 配置_发邮件_06

对应的也收到了邮件

Automation 结合Logic Apps触发告警 - 配置_发邮件_07


举报

相关推荐

0 条评论