健康检查UI(BeatPulse)无法让团队webhook工作

问题描述 投票:0回答:1

我有一个使用运行状况检查和运行状况检查UI的ASP.NET Core 2.2应用程序。我有这个部分工作,但当我尝试为团队添加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. \" }"
    }
]

仍然没有快乐。当我启动页面时,我看不到显示的webhook,但我确实在控制台中看到了这个错误:

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,但是当我直接进入页面时,它是与团队webhook的json响应。

以下是我设置健康检查的方法:

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

我还缺少其他一些配置吗?如何让团队webhook工作?

asp.net-core webhooks health-monitoring
1个回答
1
投票

WebHooks.RestoredPayload json没有关闭引号和大括号导致解析错误。

试试这个json:

"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\" }"
      }
    ],
© www.soinside.com 2019 - 2024. All rights reserved.