使用webhook到Microsoft Teams的Azure Monitor Alerts-没有消息发送给Teams [英] Azure Monitor Alerts using webhook to Microsoft Teams - No messages to Teams

查看:327
本文介绍了使用webhook到Microsoft Teams的Azure Monitor Alerts-没有消息发送给Teams的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Azure Monitor/Log Analytics成功触发警报.我试图使警报进入Microsoft Teams频道(以及用于调试的松弛频道),但没有成功.

I'm using Azure Monitor/Log Analytics to trigger alerts successfully. I'm trying to get the alerts into a Microsoft Teams channel (as well as a slack channel for debugging) with no success.

我有一条警报已成功触发.我有一个配置了电子邮件,短信和天蓝色应用程序推送的操作组.每当警报触发时,我都会收到这些消息.

I've an alert that's successfully being triggered. I have an action group with my email, sms and azure app push configured. I've been receiving these messages each time the alert triggers.

我还有另一个行动小组,其中有几个针对Microsoft Teams和Slack频道的网络鸣叫.这些频道上我什么也没收到.

I've got another action group with a couple of webhooks in for a Microsoft Teams and Slack channels. I'm not receiving anything on these channels.

我启用了自定义为webhook包含自定义Json有效负载",并粘贴了建议的json和以下内容 { "AlertName":"#alertrulename", "AlertDescription":"#description", "LinkToSearchResults":"#linktosearchresults"}

I've enabled the custom 'Include custom Json payload for webhook' and pasted both the suggested json and the following { "AlertName":"#alertrulename", "AlertDescription":"#description", "LinkToSearchResults":"#linktosearchresults"}

我收到电子邮件/短信/推送通知,但未收到发送到Web挂钩的消息.我尝试在操作组(默认设置)中将通用警报架构设置为否(也尝试在是"上尝试失败).

I get the emails/sms/push notifications but not the messages to the web hooks. I've tried leaving the common alert schema set to no in the action group, the default (as well trying unsuccessfully on yes as well).

怀疑与自定义有效负载json有关,如此处

Suspecting it's something to do with the custom payload json as mention here https://azure.microsoft.com/en-gb/blog/webhooks-for-azure-alerts/

关于如何将警报发送到团队的任何想法?

Any ideas on how I can get my alerts into teams?

谢谢

推荐答案

设法破解它并使它在所有人中都能使用!

Managed to crack it and get it working everyone!

使用Azure自动化,一个运行本/webhook.

Using Azure Automation, a runbook/webhook.

将以下内容添加为运行手册(更新您的uri):

Added the following as a runbook (update your 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'
}

然后为Runbook生成一个webhook,并将其添加到Azure警报中.

Then generate a webhook for the runbook and add this into the Azure Alert.

在天蓝色警报中,我已将自定义有效负载设置为此:

In the azure alert i've set the custom payload to this:

{ "AlertName":"#alertrulename", "AlertDescription":"#description", "LinkToSearchResults":"#linktosearchresults"}

宾果游戏,触发的警报和警报通过

Bingo, triggered alert and alert came through

这篇关于使用webhook到Microsoft Teams的Azure Monitor Alerts-没有消息发送给Teams的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆