运行状况检查 UI (BeatPulse) 无法使 Teams webhook 正常工作
Health Checks UI (BeatPulse) not able to get Teams webhook working
我有一个 ASP.NET Core 2.2 应用程序正在使用健康检查和健康检查 UI。我有那部分工作,但当我尝试为 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. \" }"
}
]
仍然没有快乐。当我启动页面时,我没有看到显示任何 webhooks,但我确实在控制台中看到了这个错误:
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 webhook 工作?
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\" }"
}
],
我有一个 ASP.NET Core 2.2 应用程序正在使用健康检查和健康检查 UI。我有那部分工作,但当我尝试为 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. \" }"
}
]
仍然没有快乐。当我启动页面时,我没有看到显示任何 webhooks,但我确实在控制台中看到了这个错误:
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 webhook 工作?
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\" }"
}
],