Files
Umbraco-CMS/src/Umbraco.Web/HealthCheck/NotificationMethods/NotificationMethodBase.cs
T

55 lines
1.8 KiB
C#
Raw Normal View History

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;
2019-01-07 10:43:28 +01:00
using Umbraco.Core;
2018-12-12 17:49:24 +01:00
using Umbraco.Core.Composing;
2017-09-08 19:39:13 +02:00
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.HealthChecks;
namespace Umbraco.Web.HealthCheck.NotificationMethods
{
public abstract class NotificationMethodBase : IHealthCheckNotificationMethod
{
protected NotificationMethodBase()
{
var type = GetType();
var attribute = type.GetCustomAttribute<HealthCheckNotificationMethodAttribute>();
if (attribute == null)
{
Enabled = false;
return;
}
2019-01-07 10:43:28 +01:00
var healthCheckConfig = Current.Configs.HealthChecks();
2017-09-08 19:39:13 +02:00
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);
}
}