Joh*_*Fox 8 json webhooks azure-monitoring microsoft-teams
我正在使用 Azure Monitor/Log Analytics 成功触发警报。我正在尝试将警报发送到 Microsoft Teams 频道(以及用于调试的松弛频道),但没有成功。
我有一个成功触发的警报。我有一个操作组,配置了我的电子邮件、短信和 azure 应用程序推送。每次警报触发时,我都会收到这些消息。
我有另一个行动小组,其中有几个 webhooks 用于 Microsoft Teams 和 Slack 频道。我在这些频道上没有收到任何消息。
我已启用自定义“为 webhook 包含自定义 Json 负载”并粘贴了建议的 json 和以下内容
{ "AlertName":"#alertrulename", "AlertDescription":"#description", "LinkToSearchResults":"#linktosearchresults"}
我收到电子邮件/短信/推送通知,但没有收到网络挂钩的消息。我已经尝试将操作组中的通用警报模式设置为 no,这是默认设置(以及在 yes 上尝试也没有成功)。
怀疑这与此处提到的自定义有效负载 json 有关https://azure.microsoft.com/en-gb/blog/webhooks-for-azure-alerts/
关于如何将我的警报发送到团队的任何想法?
谢谢
设法破解它并让每个人都能正常工作!
使用 Azure 自动化,一个 Runbook/webhook。
添加以下内容作为操作手册(更新您的 uri):
param
(
[Parameter (Mandatory=$false)]
[object] $WebhookData
)
if ($WebhookData)
{
# Get the data object from WebhookData.
$WebhookBody = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)
$alertName = $WebhookBody.alertname
$alertDescription = $WebhookBody.alertDescription
$linkToSearch = $WebhookBody.linktosearchresults
$query = $WebhookBody.searchquery
$results = $WebhookBody.resultcount
$AlertThreshold = $WebhookBody.AlertThreshold
$AlertThresholdValue = $WebhookBody.AlertThresholdValue
$StartTime = $WebhookBody.SearchStartTime
$EndTime = $WebhookBody.SearchEndTime
$formatLink = "[Link]($linkToSearch)"
$formatMessage = "$alertName has exceeded the threshold $AlertThreshold $AlertThresholdValue. Results returned: $results"
$uri = 'https://teams-connector-uri'
$body = ConvertTo-Json -Depth 4 @{
summary = $alertName
sections = @(
@{
activityTitle = $alertName
activitySubtitle = $alertDescription
activityText = $formatMessage
},
@{
title = 'Details'
facts = @(
@{
name = 'Query time range. (UTC)'
value = "$StartTime $EndTime"
},
@{
name = 'Link to search results'
value = $formatLink
},
@{
name = 'Query Executed'
value = $query
}
)
}
)
}
Invoke-RestMethod -uri $uri -Method Post -body $body -ContentType 'application/json'
}
Run Code Online (Sandbox Code Playgroud)
然后为 Runbook 生成一个 webhook 并将其添加到 Azure 警报中。
在 azure 警报中,我将自定义负载设置为:
{ "AlertName":"#alertrulename", "AlertDescription":"#description", "LinkToSearchResults":"#linktosearchresults"}
Run Code Online (Sandbox Code Playgroud)
宾果游戏,触发警报和警报通过
小智 6
在 Teams 中,对于每个频道,我们都有一个关联的电子邮件地址。频道的“获取电子邮件地址”选项提供电子邮件 ID。使用带有电子邮件 ID 的操作组中的电子邮件通知。Webhook URL 似乎不起作用
我没有使用过 Azure 警报,所以我不确定您到底有哪些可用选项,但从您的有效负载的结构来看,您似乎希望将其格式化为某种一致的机制。
使用连接器实现此目的的常见方法是使用“可操作消息卡”之类的东西。本质上,您就像将一个迷你格式的弹出窗口发送到团队频道中一样。要查看一些示例,请转到此处并单击左上角菜单上的“选择示例”。
为此,卡片不需要非常复杂,但您确实需要稍微考虑一下您想要它的外观,以及可能想要提供的操作。例如,您可能希望名称和描述采用某种表格格式,并且 LinkToSearchResults 是底部加载浏览器窗口的按钮。可操作消息设计器也可以帮助您将其组合在一起。完成最终设计后,您将得到一个 JSON 文本负载,只需将其与 Azure 中的令牌组合在一起即可。
就像我说的,我没有使用过 Azure 警报,但我认为这应该有所帮助。
| 归档时间: |
|
| 查看次数: |
5995 次 |
| 最近记录: |