Adding a Results method to the HealthCheckResults so that Notification Methods can construct specific messages with different result sets

This commit is contained in:
Jeavon
2017-06-19 12:18:47 +01:00
parent 0638786075
commit 824eee80b3
2 changed files with 36 additions and 0 deletions

View File

@@ -157,5 +157,34 @@ namespace Umbraco.Web.HealthCheck
.Replace("<em>", "*")
.Replace("</em>", "*");
}
public Dictionary<string, IEnumerable<HealthCheckStatus>> 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;
}
}
}

View File

@@ -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,