Skip to content

Commit

Permalink
Adding response writing to provide useful output to the health check …
Browse files Browse the repository at this point in the history
…caller
  • Loading branch information
Chris committed Jun 29, 2019
1 parent bfdad66 commit 0972955
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions HealthChecks.SomeModelService/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using Autofac;
using HealthChecks.Configuration;
Expand Down Expand Up @@ -103,7 +103,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplica

app.UseHealthChecks("/health", new HealthCheckOptions()
{
Predicate = _ => true
ResponseWriter = WriteHealthCheckResponse
});

//Use Identity and Access Control
Expand All @@ -113,6 +113,23 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplica
app.UseMvc();
}

private static Task WriteHealthCheckResponse(HttpContext httpContext,
HealthReport result)
{
httpContext.Response.ContentType = "application/json";

var json = new JObject(
new JProperty("status", result.Status.ToString()),
new JProperty("results", new JObject(result.Entries.Select(pair =>
new JProperty(pair.Key, new JObject(
new JProperty("status", pair.Value.Status.ToString()),
new JProperty("description", pair.Value.Description),
new JProperty("data", new JObject(pair.Value.Data.Select(
p => new JProperty(p.Key, p.Value))))))))));
return httpContext.Response.WriteAsync(
json.ToString(Formatting.Indented));
}

/// <summary>
/// Used to configure your container as needed.
/// </summary>
Expand Down

0 comments on commit 0972955

Please sign in to comment.