运行状况检查UI(BeatPulse)无法使Teams Webhook正常运行

时间:2019-01-28 20:22:03

标签: asp.net-core webhooks health-monitoring

我有一个使用运行状况检查和运行状况检查UI的ASP.NET Core 2.2应用程序。我的那部分工作正常,但是当我尝试为Teams添加Webhook时却没有显示。

我遵循了documentation中的示例:

"Webhooks": [
      {
        "Name": "Teams",
        "Uri": "https://outlook.office.com/webhook/...",
        "Payload": "{\r\n  \"@context\": \"http://schema.org/extensions\",\r\n  \"@type\": \"MessageCard\",\r\n \"themeColor\": \"0072C6\",\r\n  \"title\": \"[[LIVENESS]] has failed!\",\r\n  \"text\": \"[[FAILURE]] Click **Learn More** to go to BeatPulseUI Portal\",\r\n  \"potentialAction\": [\r\n    {\r\n      \"@type\": \"OpenUri\",\r\n      \"name\": \"Lear More\",\r\n      \"targets\": [\r\n        { \"os\": \"default\", \"uri\": \"http://localhost:52665/beatpulse-ui\" }\r\n      ]\r\n    }\r\n  ]\r\n}",
        "RestoredPayload": "{\"text\":\"The HealthCheck [[LIVENESS]] is recovered. All is up and running\",\"channel\":\"#general\",\"link_names\": 1,\"username\":\"monkey-bot\",\"icon_emoji\":\":monkey_face"
      }
    ],

我尝试了calling the webhook directly with cURL,它可以按预期工作:

curl -H "Content-Type: application/json" -d "{\"text\": \"Hello World\"}" <YOUR WEBHOOK URL>

我还尝试简化Payload

"Webhooks": [
    {
      "Name": "Teams",
      "Uri": "https://outlook.office.com/webhook/...",
      "Payload": "{\"text\":\"[[LIVENESS]] has failed! Failure: [[FAILURE]]\" }",
      "RestoredPayload": "{\"text\": \"The HealthCheck [[LIVENESS]] has recovered. \" }"
    }
]

仍然没有喜悦。当我启动页面时,没有看到任何显示的网络提示,但是在控制台中确实看到了此错误:

Uncaught SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at new e.HttpResponse (healthchecks-bundle.js:formatted:473)
    at XMLHttpRequest.l.onload (healthchecks-bundle.js:formatted:505)

这是指:

e.HttpResponse = class {
    constructor(A) {
        const {status: e, statusText: t, response: a, responseText: n} = A;
        this.status = e,
        this.statusText = t,
        this.response = a || n,
        this.data = JSON.parse(this.response) // line 473
    }
}

在“网络”标签上,我看到一个对“healthchecks-webhooks”的呼叫。响应看起来像html,但是当我直接转到页面时,它是Teams Webhook的json响应。

这是我进行健康检查的方式:

.UseHealthChecks("/health", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions()
 {
     Predicate = _ => true,
     ResponseWriter = HealthChecks.UI.Client.UIResponseWriter.WriteHealthCheckUIResponse
 })
 .UseHealthChecksUI()

我还有其他配置吗?我如何才能使用Teams网络挂钩?

1 个答案:

答案 0 :(得分:1)

WebHooks.RestoredPayload json没有右引号和大括号,这会导致解析错误。

尝试这个json insetad:

insouciant(nil) { User.profile.settings.card.options }