From 9b6cad7d8277451090c6b06c9e895138b19a83ca Mon Sep 17 00:00:00 2001 From: AndyButland Date: Mon, 5 Jun 2017 10:08:57 +0200 Subject: [PATCH 1/3] Fixed health check configuration following namespace refactor --- src/Umbraco.Web.UI/web.Template.Debug.config | 2 +- src/Umbraco.Web.UI/web.Template.config | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.UI/web.Template.Debug.config b/src/Umbraco.Web.UI/web.Template.Debug.config index 5f07e506ec..7e0cf722c8 100644 --- a/src/Umbraco.Web.UI/web.Template.Debug.config +++ b/src/Umbraco.Web.UI/web.Template.Debug.config @@ -33,7 +33,7 @@
-
+
diff --git a/src/Umbraco.Web.UI/web.Template.config b/src/Umbraco.Web.UI/web.Template.config index c271c006c5..75c244ada3 100644 --- a/src/Umbraco.Web.UI/web.Template.config +++ b/src/Umbraco.Web.UI/web.Template.config @@ -12,7 +12,7 @@
-
+
From 0366fa73c33d12b3884b013ee3128bd29aec7572 Mon Sep 17 00:00:00 2001 From: AndyButland Date: Mon, 5 Jun 2017 10:14:17 +0200 Subject: [PATCH 2/3] Remove requirement for configuring start time for scheduled health checks; if not provided, start with short delay after application start --- .../HealthCheckNotificationSettingsElement.cs | 2 +- src/Umbraco.Web/Scheduling/Scheduler.cs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs b/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs index 8c533d9bac..0cb89be12f 100644 --- a/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs +++ b/src/Umbraco.Core/Configuration/HealthChecks/HealthCheckNotificationSettingsElement.cs @@ -24,7 +24,7 @@ namespace Umbraco.Core.Configuration.HealthChecks } } - [ConfigurationProperty(FIRST_RUN_TIME_KEY, IsRequired = true)] + [ConfigurationProperty(FIRST_RUN_TIME_KEY, IsRequired = false)] public string FirstRunTime { get diff --git a/src/Umbraco.Web/Scheduling/Scheduler.cs b/src/Umbraco.Web/Scheduling/Scheduler.cs index 85a5843486..6e470ad145 100644 --- a/src/Umbraco.Web/Scheduling/Scheduler.cs +++ b/src/Umbraco.Web/Scheduling/Scheduler.cs @@ -78,11 +78,21 @@ namespace Umbraco.Web.Scheduling if (healthCheckConfig.NotificationSettings.Enabled) { - var delayInMilliseconds = DateTime.Now.PeriodicMinutesFrom(healthCheckConfig.NotificationSettings.FirstRunTime) * 60 * 1000; - if (delayInMilliseconds < DelayMilliseconds) + // If first run time not set, start with just small delay after application start + int delayInMilliseconds; + if (string.IsNullOrEmpty(healthCheckConfig.NotificationSettings.FirstRunTime)) { delayInMilliseconds = DelayMilliseconds; } + else + { + // Otherwise start at scheduled time + delayInMilliseconds = DateTime.Now.PeriodicMinutesFrom(healthCheckConfig.NotificationSettings.FirstRunTime) * 60 * 1000; + if (delayInMilliseconds < DelayMilliseconds) + { + delayInMilliseconds = DelayMilliseconds; + } + } var periodInMilliseconds = healthCheckConfig.NotificationSettings.PeriodInHours * 60 * 60 * 1000; tasks.Add(new HealthCheckNotifier(_healthCheckRunner, delayInMilliseconds, periodInMilliseconds, e.UmbracoContext.Application)); From 474dcf0779020354825cd4ee0d649b361c8232e3 Mon Sep 17 00:00:00 2001 From: AndyButland Date: Mon, 5 Jun 2017 10:14:47 +0200 Subject: [PATCH 3/3] Improved layout of scheduled healthcheck result logging --- .../HealthCheck/HealthCheckResults.cs | 40 +++++++++++++++++++ .../Scheduling/HealthCheckNotifier.cs | 15 ++----- src/Umbraco.Web/Umbraco.Web.csproj | 1 + 3 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 src/Umbraco.Web/HealthCheck/HealthCheckResults.cs diff --git a/src/Umbraco.Web/HealthCheck/HealthCheckResults.cs b/src/Umbraco.Web/HealthCheck/HealthCheckResults.cs new file mode 100644 index 0000000000..a6a2bca1bd --- /dev/null +++ b/src/Umbraco.Web/HealthCheck/HealthCheckResults.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; +using Umbraco.Core.Logging; + +namespace Umbraco.Web.HealthCheck +{ + public class HealthCheckResults + { + private readonly Dictionary> _results; + + public HealthCheckResults(IEnumerable checks) + { + _results = checks.ToDictionary(t => t.Name, t => t.GetStatus()); + } + + public void LogResults() + { + LogHelper.Info("Scheduled health check results:"); + foreach (var result in _results) + { + var checkName = result.Key; + var checkResults = result.Value; + var checkIsSuccess = result.Value.All(x => x.ResultType == StatusResultType.Success); + if (checkIsSuccess) + { + LogHelper.Info(string.Format(" Checks for '{0}' all completed succesfully.", checkName)); + } + else + { + LogHelper.Warn(string.Format(" Checks for '{0}' completed with errors.", checkName)); + } + + foreach (var checkResult in checkResults) + { + LogHelper.Info(string.Format(" Result: {0}, Message: '{1}'", checkResult.ResultType, checkResult.Message)); + } + } + } + } +} diff --git a/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs b/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs index 794941c6b4..614b2caca7 100644 --- a/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs +++ b/src/Umbraco.Web/Scheduling/HealthCheckNotifier.cs @@ -1,3 +1,5 @@ +using System; +using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; @@ -50,14 +52,8 @@ namespace Umbraco.Web.Scheduling var checks = _healthCheckResolver.HealthChecks .Where(x => disabledCheckIds.Contains(x.Id) == false); - var sb = new StringBuilder(); - foreach (var check in checks) - { - // TODO: get all sub-checks, not just first - var status = check.GetStatus().First(); - sb.AppendFormat(" - Check {0} returned {1} with message {2}.", check.Name, status.ResultType, status.Message); - sb.AppendLine(); - } + var results = new HealthCheckResults(checks); + results.LogResults(); // TODO: get email address and send if (!string.IsNullOrEmpty(healthCheckConfig.NotificationSettings.RecipientEmail)) @@ -70,9 +66,6 @@ namespace Umbraco.Web.Scheduling { } - - LogHelper.Info("Health check results:"); - LogHelper.Info(sb.ToString()); } return true; // repeat diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 34a9274065..033c4538d3 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -336,6 +336,7 @@ +