Amended registration of health check scheduled notifiers (email and Slack) to use a resolver method and allow others to be added without modifying core
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.HealthChecks
|
||||
{
|
||||
public abstract class BaseNotificationMethodElement : ConfigurationElement
|
||||
{
|
||||
private const string VERBOSITY_KEY = "verbosity";
|
||||
private const string FAILUREONLY_KEY = "failureOnly";
|
||||
|
||||
[ConfigurationProperty(VERBOSITY_KEY, IsRequired = true)]
|
||||
public HealthCheckNotificationVerbosity Verbosity
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((HealthCheckNotificationVerbosity)(base[VERBOSITY_KEY]));
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(FAILUREONLY_KEY, IsRequired = true)]
|
||||
public bool FailureOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((bool)(base[FAILUREONLY_KEY]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.HealthChecks
|
||||
{
|
||||
public class EmailSettingsElement : BaseNotificationMethodElement
|
||||
{
|
||||
private const string RECIPIENT_EMAIL_KEY = "recipientEmail";
|
||||
private const string SUBJECT_KEY = "subject";
|
||||
|
||||
[ConfigurationProperty(RECIPIENT_EMAIL_KEY, IsRequired = true)]
|
||||
public string RecipientEmail
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((string)(base[RECIPIENT_EMAIL_KEY]));
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(SUBJECT_KEY, IsRequired = true)]
|
||||
public string Subject
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((string)(base[SUBJECT_KEY]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,15 @@ namespace Umbraco.Core.Configuration.HealthChecks
|
||||
private const string ENABLED_KEY = "enabled";
|
||||
private const string FIRST_RUN_TIME_KEY = "firstRunTime";
|
||||
private const string PERIOD_KEY = "periodInHours";
|
||||
private const string NOTIFICATION_METHODS_KEY = "notificationMethods";
|
||||
private const string DISABLED_CHECKS_KEY = "disabledChecks";
|
||||
private const string EMAIL_SETTINGS_KEY = "emailSettings";
|
||||
private const string SLACK_SETTINGS_KEY = "slackSettings";
|
||||
|
||||
[ConfigurationProperty(ENABLED_KEY, IsRequired = true)]
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((bool)(base[ENABLED_KEY]));
|
||||
return (bool)base[ENABLED_KEY];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +28,7 @@ namespace Umbraco.Core.Configuration.HealthChecks
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((string)(base[FIRST_RUN_TIME_KEY]));
|
||||
return (string)base[FIRST_RUN_TIME_KEY];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,34 +37,25 @@ namespace Umbraco.Core.Configuration.HealthChecks
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((int)(base[PERIOD_KEY]));
|
||||
return (int)base[PERIOD_KEY];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(DISABLED_CHECKS_KEY, IsDefaultCollection = true, IsRequired = false)]
|
||||
[ConfigurationProperty(NOTIFICATION_METHODS_KEY, IsDefaultCollection = true, IsRequired = false)]
|
||||
public NotificationMethodsElementCollection NotificationMethods
|
||||
{
|
||||
get
|
||||
{
|
||||
return (NotificationMethodsElementCollection)base[NOTIFICATION_METHODS_KEY];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(DISABLED_CHECKS_KEY, IsDefaultCollection = false, IsRequired = false)]
|
||||
public DisabledHealthChecksElementCollection DisabledChecks
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((DisabledHealthChecksElementCollection)(base[DISABLED_CHECKS_KEY]));
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(EMAIL_SETTINGS_KEY, IsDefaultCollection = true, IsRequired = false)]
|
||||
public EmailSettingsElement EmailSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((EmailSettingsElement)(base[EMAIL_SETTINGS_KEY]));
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(SLACK_SETTINGS_KEY, IsDefaultCollection = true, IsRequired = false)]
|
||||
public SlackSettingsElement SlackSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((SlackSettingsElement)(base[SLACK_SETTINGS_KEY]));
|
||||
return (DisabledHealthChecksElementCollection)base[DISABLED_CHECKS_KEY];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Umbraco.Core.Configuration.HealthChecks
|
||||
{
|
||||
public class NotificationMethodElement : ConfigurationElement
|
||||
{
|
||||
private const string ALIAS_KEY = "alias";
|
||||
private const string ENABLED_KEY = "enabled";
|
||||
private const string VERBOSITY_KEY = "verbosity";
|
||||
private const string FAILUREONLY_KEY = "failureOnly";
|
||||
private const string SETTINGS_KEY = "settings";
|
||||
|
||||
[ConfigurationProperty(ALIAS_KEY, IsKey = true, IsRequired = true)]
|
||||
public string Alias
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)base[ALIAS_KEY];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(ENABLED_KEY, IsKey = true, IsRequired = true)]
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return (bool)base[ENABLED_KEY];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(VERBOSITY_KEY, IsRequired = true)]
|
||||
public HealthCheckNotificationVerbosity Verbosity
|
||||
{
|
||||
get
|
||||
{
|
||||
return (HealthCheckNotificationVerbosity)base[VERBOSITY_KEY];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(FAILUREONLY_KEY, IsRequired = false)]
|
||||
public bool FailureOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return (bool)base[FAILUREONLY_KEY];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(SETTINGS_KEY, IsDefaultCollection = true, IsRequired = false)]
|
||||
public NotificationMethodSettingsElementCollection Settings
|
||||
{
|
||||
get
|
||||
{
|
||||
return (NotificationMethodSettingsElementCollection)base[SETTINGS_KEY];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.HealthChecks
|
||||
{
|
||||
public class NotificationMethodSettingsElement : ConfigurationElement
|
||||
{
|
||||
private const string KEY_KEY = "key";
|
||||
private const string VALUE_KEY = "value";
|
||||
|
||||
[ConfigurationProperty(KEY_KEY, IsKey = true, IsRequired = true)]
|
||||
public string Key
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)base[KEY_KEY];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(VALUE_KEY, IsRequired = true)]
|
||||
public string Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)base[VALUE_KEY];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.HealthChecks
|
||||
{
|
||||
[ConfigurationCollection(typeof(NotificationMethodSettingsElement), AddItemName = "add")]
|
||||
public class NotificationMethodSettingsElementCollection : ConfigurationElementCollection, IEnumerable<NotificationMethodSettingsElement>
|
||||
{
|
||||
protected override ConfigurationElement CreateNewElement()
|
||||
{
|
||||
return new NotificationMethodSettingsElement();
|
||||
}
|
||||
|
||||
protected override object GetElementKey(ConfigurationElement element)
|
||||
{
|
||||
return ((NotificationMethodSettingsElement)(element)).Key;
|
||||
}
|
||||
|
||||
new public NotificationMethodSettingsElement this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
return (NotificationMethodSettingsElement)BaseGet(key);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator<NotificationMethodSettingsElement> IEnumerable<NotificationMethodSettingsElement>.GetEnumerator()
|
||||
{
|
||||
for (var i = 0; i < Count; i++)
|
||||
{
|
||||
yield return BaseGet(i) as NotificationMethodSettingsElement;
|
||||
}
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.HealthChecks
|
||||
{
|
||||
[ConfigurationCollection(typeof(NotificationMethodElement), AddItemName = "notificationMethod")]
|
||||
public class NotificationMethodsElementCollection : ConfigurationElementCollection, IEnumerable<NotificationMethodElement>
|
||||
{
|
||||
protected override ConfigurationElement CreateNewElement()
|
||||
{
|
||||
return new NotificationMethodElement();
|
||||
}
|
||||
|
||||
protected override object GetElementKey(ConfigurationElement element)
|
||||
{
|
||||
return ((NotificationMethodElement)(element)).Alias;
|
||||
}
|
||||
|
||||
new public NotificationMethodElement this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
return (NotificationMethodElement)BaseGet(key);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator<NotificationMethodElement> IEnumerable<NotificationMethodElement>.GetEnumerator()
|
||||
{
|
||||
for (var i = 0; i < Count; i++)
|
||||
{
|
||||
yield return BaseGet(i) as NotificationMethodElement;
|
||||
}
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using System.Configuration;
|
||||
|
||||
namespace Umbraco.Core.Configuration.HealthChecks
|
||||
{
|
||||
public class SlackSettingsElement : BaseNotificationMethodElement
|
||||
{
|
||||
private const string WEBHOOKURL_KEY = "webHookUrl";
|
||||
private const string CHANNEL_KEY = "channel";
|
||||
private const string USERNAME_KEY = "username";
|
||||
|
||||
[ConfigurationProperty(WEBHOOKURL_KEY, IsRequired = true)]
|
||||
public string WebHookUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((string)(base[WEBHOOKURL_KEY]));
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(CHANNEL_KEY, IsRequired = true)]
|
||||
public string Channel
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((string)(base[CHANNEL_KEY]));
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(USERNAME_KEY, IsRequired = true)]
|
||||
public string UserName
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((string)(base[USERNAME_KEY]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user