51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Umbraco.Core.Configuration.HealthChecks;
|
|
|
|
namespace Umbraco.Web.HealthCheck.NotificationMethods
|
|
{
|
|
public abstract class NotificationMethodBase : IHealthCheckNotificationMethod
|
|
{
|
|
protected NotificationMethodBase(IHealthChecksSettings healthCheckSettingsConfig)
|
|
{
|
|
var type = GetType();
|
|
var attribute = type.GetCustomAttribute<HealthCheckNotificationMethodAttribute>();
|
|
if (attribute == null)
|
|
{
|
|
Enabled = false;
|
|
return;
|
|
}
|
|
|
|
var notificationMethods = healthCheckSettingsConfig.NotificationSettings.NotificationMethods;
|
|
var notificationMethod = notificationMethods[attribute.Alias];
|
|
if (notificationMethod == null)
|
|
{
|
|
Enabled = false;
|
|
return;
|
|
}
|
|
|
|
Enabled = notificationMethod.Enabled;
|
|
FailureOnly = notificationMethod.FailureOnly;
|
|
Verbosity = notificationMethod.Verbosity;
|
|
Settings = notificationMethod.Settings;
|
|
}
|
|
|
|
public bool Enabled { get; protected set; }
|
|
|
|
public bool FailureOnly { get; protected set; }
|
|
|
|
public HealthCheckNotificationVerbosity Verbosity { get; protected set; }
|
|
|
|
public IReadOnlyDictionary<string, INotificationMethodSettings> Settings { get; }
|
|
|
|
protected bool ShouldSend(HealthCheckResults results)
|
|
{
|
|
return Enabled && (!FailureOnly || !results.AllChecksSuccessful);
|
|
}
|
|
|
|
public abstract Task SendAsync(HealthCheckResults results, CancellationToken token);
|
|
}
|
|
}
|