2017-09-08 19:39:13 +02:00
|
|
|
using System.Collections.Generic;
|
2018-03-07 09:36:04 +01:00
|
|
|
using System.Reflection;
|
2017-09-08 19:39:13 +02:00
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Umbraco.Core.Configuration.HealthChecks;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.HealthCheck.NotificationMethods
|
|
|
|
|
{
|
|
|
|
|
public abstract class NotificationMethodBase : IHealthCheckNotificationMethod
|
|
|
|
|
{
|
2020-01-07 13:08:21 +01:00
|
|
|
protected NotificationMethodBase(IHealthChecks healthCheckConfig)
|
2017-09-08 19:39:13 +02:00
|
|
|
{
|
|
|
|
|
var type = GetType();
|
|
|
|
|
var attribute = type.GetCustomAttribute<HealthCheckNotificationMethodAttribute>();
|
|
|
|
|
if (attribute == null)
|
|
|
|
|
{
|
|
|
|
|
Enabled = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var notificationMethods = healthCheckConfig.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);
|
|
|
|
|
}
|
|
|
|
|
}
|