Netcore: Health check notifier hosted service (#9295)

* Implemented health check notifier as a hosted service.
Added validation to health check settings.

* Registered health check notifier as a hosted service.
Modified health check nested settings to use concrete classes to align with other configuration models.

* Resolved issues with email sending using development server.

* PR review comments and fixed failing unit test.

* Changed period and delay millisecond and hourly values to TimeSpans.
Changed configuration of first run time for health check notifications to use H:mm format.

* Set up SecureSocketOptions as a locally defined enum.

* Tightened up time format validation to verify input is an actual time (with hours and minutes only) and not a timespan.

* Aligned naming and namespace of health check configuration related classes with other configuration classes.

* Created constants for hex colors used in formatting health check results as HTML.

* Revert "Tightened up time format validation to verify input is an actual time (with hours and minutes only) and not a timespan."

This reverts commit f9bb8a7a825bcb58146879f18b47922e09453e2d.

* Renamed method to be clear validation is of a TimeSpan and not a time.

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
Andy Butland
2020-10-30 13:56:13 +01:00
committed by GitHub
parent 4ae329589a
commit bdb8f34da3
31 changed files with 636 additions and 248 deletions

View File

@@ -128,11 +128,17 @@ namespace Umbraco.Infrastructure.HealthCheck
return html;
}
internal Dictionary<string, IEnumerable<HealthCheckStatus>> ResultsAsDictionary => _results;
private string ApplyHtmlHighlighting(string html)
{
html = ApplyHtmlHighlightingForStatus(html, StatusResultType.Success, "5cb85c");
html = ApplyHtmlHighlightingForStatus(html, StatusResultType.Warning, "f0ad4e");
return ApplyHtmlHighlightingForStatus(html, StatusResultType.Error, "d9534f");
const string SuccessHexColor = "5cb85c";
const string WarningHexColor = "f0ad4e";
const string ErrorHexColor = "d9534f";
html = ApplyHtmlHighlightingForStatus(html, StatusResultType.Success, SuccessHexColor);
html = ApplyHtmlHighlightingForStatus(html, StatusResultType.Warning, WarningHexColor);
return ApplyHtmlHighlightingForStatus(html, StatusResultType.Error, ErrorHexColor);
}
private string ApplyHtmlHighlightingForStatus(string html, StatusResultType status, string color)

View File

@@ -28,7 +28,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods
IOptions<ContentSettings> contentSettings)
: base(healthChecksSettings)
{
var recipientEmail = Settings?["recipientEmail"]?.Value;
var recipientEmail = Settings?["RecipientEmail"];
if (string.IsNullOrWhiteSpace(recipientEmail))
{
Enabled = false;
@@ -45,7 +45,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods
public string RecipientEmail { get; }
public override async Task SendAsync(HealthCheckResults results, CancellationToken token)
public override async Task SendAsync(HealthCheckResults results)
{
if (ShouldSend(results) == false)
{

View File

@@ -8,6 +8,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods
public interface IHealthCheckNotificationMethod : IDiscoverable
{
bool Enabled { get; }
Task SendAsync(HealthCheckResults results, CancellationToken token);
Task SendAsync(HealthCheckResults results);
}
}

View File

@@ -1,11 +1,9 @@
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.HealthCheck;
using Umbraco.Core.HealthCheck.Checks;
using Umbraco.Infrastructure.HealthCheck;
namespace Umbraco.Web.HealthCheck.NotificationMethods
@@ -22,8 +20,8 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods
return;
}
var notificationMethods = healthCheckSettings.Value.NotificationSettings.NotificationMethods;
if(!notificationMethods.TryGetValue(attribute.Alias, out var notificationMethod))
var notificationMethods = healthCheckSettings.Value.Notification.NotificationMethods;
if (!notificationMethods.TryGetValue(attribute.Alias, out var notificationMethod))
{
Enabled = false;
return;
@@ -41,13 +39,13 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods
public HealthCheckNotificationVerbosity Verbosity { get; protected set; }
public IReadOnlyDictionary<string, INotificationMethodSettings> Settings { get; }
public IDictionary<string, string> Settings { get; }
protected bool ShouldSend(HealthCheckResults results)
{
return Enabled && (!FailureOnly || !results.AllChecksSuccessful);
}
public abstract Task SendAsync(HealthCheckResults results, CancellationToken token);
public abstract Task SendAsync(HealthCheckResults results);
}
}