Merge branch 'feature/health-check-scheduler' of https://github.com/AndyButland/Umbraco-CMS into temp-U4-9984

This commit is contained in:
Jeavon Leopold
2017-06-05 10:18:26 +02:00
7 changed files with 60 additions and 16 deletions

View File

@@ -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

View File

@@ -33,7 +33,7 @@
<section name="BaseRestExtensions" type="Umbraco.Core.Configuration.BaseRest.BaseRestSection, Umbraco.Core" requirePermission="false" />
<section name="FileSystemProviders" type="Umbraco.Core.Configuration.FileSystemProvidersSection, Umbraco.Core" requirePermission="false" />
<section name="dashBoard" type="Umbraco.Core.Configuration.Dashboard.DashboardSection, Umbraco.Core" requirePermission="false" />
<section name="HealthChecks" type="Umbraco.Core.Configuration.HealthChecksSection, Umbraco.Core" requirePermission="false" />
<section name="HealthChecks" type="Umbraco.Core.Configuration.HealthChecks.HealthChecksSection, Umbraco.Core" requirePermission="false" />
</sectionGroup>
</configSections>

View File

@@ -12,7 +12,7 @@
<section name="BaseRestExtensions" type="Umbraco.Core.Configuration.BaseRest.BaseRestSection, Umbraco.Core" requirePermission="false" />
<section name="FileSystemProviders" type="Umbraco.Core.Configuration.FileSystemProvidersSection, Umbraco.Core" requirePermission="false" />
<section name="dashBoard" type="Umbraco.Core.Configuration.Dashboard.DashboardSection, Umbraco.Core" requirePermission="false" />
<section name="HealthChecks" type="Umbraco.Core.Configuration.HealthChecksSection, Umbraco.Core" requirePermission="false"/>
<section name="HealthChecks" type="Umbraco.Core.Configuration.HealthChecks.HealthChecksSection, Umbraco.Core" requirePermission="false"/>
</sectionGroup>
<sectionGroup name="imageProcessor">

View File

@@ -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<string, IEnumerable<HealthCheckStatus>> _results;
public HealthCheckResults(IEnumerable<HealthCheck> checks)
{
_results = checks.ToDictionary(t => t.Name, t => t.GetStatus());
}
public void LogResults()
{
LogHelper.Info<HealthCheckResults>("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<HealthCheckResults>(string.Format(" Checks for '{0}' all completed succesfully.", checkName));
}
else
{
LogHelper.Warn<HealthCheckResults>(string.Format(" Checks for '{0}' completed with errors.", checkName));
}
foreach (var checkResult in checkResults)
{
LogHelper.Info<HealthCheckResults>(string.Format(" Result: {0}, Message: '{1}'", checkResult.ResultType, checkResult.Message));
}
}
}
}
}

View File

@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
@@ -51,14 +53,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))
@@ -79,9 +75,6 @@ namespace Umbraco.Web.Scheduling
};
slackClient.Post(slackMessage);
}
LogHelper.Info<HealthCheckNotifier>("Health check results:");
LogHelper.Info<HealthCheckNotifier>(sb.ToString());
}
return true; // repeat

View File

@@ -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));

View File

@@ -345,6 +345,7 @@
<Compile Include="HealthCheck\HealthCheckGroup.cs" />
<Compile Include="HealthCheck\HealthCheckResolver.cs" />
<Compile Include="HealthCheck\HealthCheck.cs" />
<Compile Include="HealthCheck\HealthCheckResults.cs" />
<Compile Include="HealthCheck\HealthCheckStatus.cs" />
<Compile Include="HealthCheck\Checks\Security\HttpsCheck.cs" />
<Compile Include="HealthCheck\IHealthCheckResolver.cs" />