From 824eee80b3fbbbfca23ebb68985c7a6bb6918e48 Mon Sep 17 00:00:00 2001 From: Jeavon Date: Mon, 19 Jun 2017 12:18:47 +0100 Subject: [PATCH] Adding a Results method to the HealthCheckResults so that Notification Methods can construct specific messages with different result sets --- .../HealthCheck/HealthCheckResults.cs | 29 +++++++++++++++++++ .../SlackNotificationMethod.cs | 7 +++++ 2 files changed, 36 insertions(+) diff --git a/src/Umbraco.Web/HealthCheck/HealthCheckResults.cs b/src/Umbraco.Web/HealthCheck/HealthCheckResults.cs index 25de8f64bc..6241cdf60c 100644 --- a/src/Umbraco.Web/HealthCheck/HealthCheckResults.cs +++ b/src/Umbraco.Web/HealthCheck/HealthCheckResults.cs @@ -157,5 +157,34 @@ namespace Umbraco.Web.HealthCheck .Replace("", "*") .Replace("", "*"); } + + public Dictionary> Results(StatusResultType resultType) + { + // a check is considered a success status if all checks are successful or info + var successResults = _results.Where(x => x.Value.Any(y => y.ResultType == StatusResultType.Success) && x.Value.All(y => y.ResultType == StatusResultType.Success || y.ResultType == StatusResultType.Info)); + + // a check is considered warn status if one check is warn and all others are success or info + var warnResults = _results.Where(x => x.Value.Any(y => y.ResultType == StatusResultType.Warning) && x.Value.All(y => y.ResultType == StatusResultType.Warning || y.ResultType == StatusResultType.Success || y.ResultType == StatusResultType.Info)); + + // a check is considered error status if any check is error + var errorResults = _results.Where(x => x.Value.Any(y => y.ResultType == StatusResultType.Error)); + + // a check is considered info status if all checks are info + var infoResults = _results.Where(x => x.Value.All(y => y.ResultType == StatusResultType.Info)); + + switch (resultType) + { + case StatusResultType.Success: + return successResults.ToDictionary(x => x.Key, x => x.Value); + case StatusResultType.Warning: + return warnResults.ToDictionary(x => x.Key, x => x.Value); + case StatusResultType.Error: + return errorResults.ToDictionary(x => x.Key, x => x.Value); + case StatusResultType.Info: + return infoResults.ToDictionary(x => x.Key, x => x.Value); + } + + return null; + } } } diff --git a/src/Umbraco.Web/HealthCheck/NotificationMethods/SlackNotificationMethod.cs b/src/Umbraco.Web/HealthCheck/NotificationMethods/SlackNotificationMethod.cs index 7368a41ba0..e7afd0a16c 100644 --- a/src/Umbraco.Web/HealthCheck/NotificationMethods/SlackNotificationMethod.cs +++ b/src/Umbraco.Web/HealthCheck/NotificationMethods/SlackNotificationMethod.cs @@ -42,6 +42,13 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods icon = Emoji.WhiteCheckMark; } + var successResults = results.Results(StatusResultType.Success); + var warnResults = results.Results(StatusResultType.Warning); + var errorResults = results.Results(StatusResultType.Error); + var infoResults = results.Results(StatusResultType.Info); + + // todo construct Slack Message using Slack Attachments + var slackMessage = new SlackMessage { Channel = Channel,