I have an ASP.NET Core 2.2 app that is using health checks and health checks UI. I have that portion working, but when I try to add a webhook for Teams it is not showing up.
I followed the example in the 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"
}
],
I tried calling the webhook directly with cURL and this works as expected:
curl -H "Content-Type: application/json" -d "{\"text\": \"Hello World\"}" <YOUR WEBHOOK URL>
I also tried simplifying the Payload
:
"Webhooks": [
{
"Name": "Teams",
"Uri": "https://outlook.office.com/webhook/...",
"Payload": "{\"text\":\"[[LIVENESS]] has failed! Failure: [[FAILURE]]\" }",
"RestoredPayload": "{\"text\": \"The HealthCheck [[LIVENESS]] has recovered. \" }"
}
]
Still no joy. When I start up the page I see no webhooks displayed, but I do see this error in the console:
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)
Which is referring to this:
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
}
}
Looking at the network tab I see a call to “healthchecks-webhooks”
. The response from this looks like html, but when I go directly to the page it is a json response with the Teams webhook.
Here’s how I’m setting up healthchecks:
.UseHealthChecks("/health", new Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = HealthChecks.UI.Client.UIResponseWriter.WriteHealthCheckUIResponse
})
.UseHealthChecksUI()
Is there some other configuration I’m missing? How can I get the Teams webhook to work?