diff --git a/HealthChecks.SomeModelService/Startup.cs b/HealthChecks.SomeModelService/Startup.cs index 17be3f3..99baf34 100644 --- a/HealthChecks.SomeModelService/Startup.cs +++ b/HealthChecks.SomeModelService/Startup.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Linq; using System.Threading.Tasks; using Autofac; using HealthChecks.Configuration; @@ -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 @@ -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)); + } + /// /// Used to configure your container as needed. ///