diff --git a/src/Umbraco.Web/HealthCheck/HealthCheckNotificationMethodResolver.cs b/src/Umbraco.Web/HealthCheck/HealthCheckNotificationMethodResolver.cs index 3e676a0621..e7c6326a89 100644 --- a/src/Umbraco.Web/HealthCheck/HealthCheckNotificationMethodResolver.cs +++ b/src/Umbraco.Web/HealthCheck/HealthCheckNotificationMethodResolver.cs @@ -59,20 +59,37 @@ namespace Umbraco.Web.HealthCheck var healthCheckConfig = UmbracoConfig.For.HealthCheck(); var notificationMethods = healthCheckConfig.NotificationSettings.NotificationMethods; var notificationMethod = notificationMethods[attribute.Alias]; - if (notificationMethod == null) - { - return null; - } + // Create array for constructor paramenters. Will consists of common ones that all notification methods have as well // as those specific to this particular notification method. var baseType = typeof(NotificationMethodBase); var baseTypeCtor = baseType.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).First(); var baseTypeCtorParamNames = baseTypeCtor.GetParameters().Select(x => x.Name); - var ctorParams = new List { notificationMethod.Enabled, notificationMethod.FailureOnly, notificationMethod.Verbosity }; - ctorParams.AddRange(ctor.GetParameters() - .Where(x => baseTypeCtorParamNames.Contains(x.Name) == false) - .Select(x => notificationMethod.Settings[x.Name].Value)); + + List ctorParams; + + if (notificationMethod != null) + { + // configuration found so set ctorParams to config values + ctorParams = new List + { + notificationMethod.Enabled, + notificationMethod.FailureOnly, + notificationMethod.Verbosity + }; + ctorParams.AddRange(ctor.GetParameters() + .Where(x => baseTypeCtorParamNames.Contains(x.Name) == false) + .Select(x => notificationMethod.Settings[x.Name].Value)); + } + else + { + // no configuration found so set to default values, enabled = false + ctorParams = new List { false, false, HealthCheckNotificationVerbosity.Detailed }; + ctorParams.AddRange(ctor.GetParameters() + .Where(x => baseTypeCtorParamNames.Contains(x.Name) == false) + .Select(x => string.Empty)); + } // Instantiate the type with the constructor parameters return Activator.CreateInstance(serviceType, ctorParams.ToArray()); diff --git a/src/Umbraco.Web/HealthCheck/NotificationMethods/EmailNotificationMethod.cs b/src/Umbraco.Web/HealthCheck/NotificationMethods/EmailNotificationMethod.cs index bfce87fde0..9703fb775b 100644 --- a/src/Umbraco.Web/HealthCheck/NotificationMethods/EmailNotificationMethod.cs +++ b/src/Umbraco.Web/HealthCheck/NotificationMethods/EmailNotificationMethod.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods public EmailNotificationMethod(bool enabled, bool failureOnly, HealthCheckNotificationVerbosity verbosity, string recipientEmail) : this(enabled, failureOnly, verbosity, recipientEmail, ApplicationContext.Current.Services.TextService) - { + { } /// @@ -39,13 +39,13 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods : base(enabled, failureOnly, verbosity) { if (textService == null) throw new ArgumentNullException("textService"); - if (string.IsNullOrWhiteSpace(recipientEmail)) throw new ArgumentException("Value cannot be null or whitespace.", "recipientEmail"); + if (enabled && string.IsNullOrWhiteSpace(recipientEmail)) throw new ArgumentException("Value cannot be null or whitespace.", "recipientEmail"); _textService = textService; RecipientEmail = recipientEmail; Verbosity = verbosity; } - public string RecipientEmail { get; private set; } + public string RecipientEmail { get; private set; } public async Task SendAsync(HealthCheckResults results) { diff --git a/src/Umbraco.Web/HealthCheck/NotificationMethods/IHealthCheckNotificatationMethod.cs b/src/Umbraco.Web/HealthCheck/NotificationMethods/IHealthCheckNotificatationMethod.cs index 1b7952c111..3202adc8e0 100644 --- a/src/Umbraco.Web/HealthCheck/NotificationMethods/IHealthCheckNotificatationMethod.cs +++ b/src/Umbraco.Web/HealthCheck/NotificationMethods/IHealthCheckNotificatationMethod.cs @@ -4,6 +4,7 @@ namespace Umbraco.Web.HealthCheck.NotificationMethods { public interface IHealthCheckNotificatationMethod { + bool Enabled { get; } Task SendAsync(HealthCheckResults results); } } diff --git a/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs b/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs index 61296a37bd..c10c1c5315 100644 --- a/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs +++ b/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs @@ -64,8 +64,8 @@ namespace Umbraco.Web.Scheduling var results = new HealthCheckResults(checks); results.LogResults(); - // Send using registered notification methods - var registeredNotificationMethods = HealthCheckNotificationMethodResolver.Current.NotificationMethods; + // Send using registered notification methods that are enabled + var registeredNotificationMethods = HealthCheckNotificationMethodResolver.Current.NotificationMethods.Where(x => x.Enabled); foreach (var notificationMethod in registeredNotificationMethods) { await notificationMethod.SendAsync(results);