https://dev.azure.com/umbraco/D-Team%20Tracker/_workitems/edit/6587 - Moved controllers: HealthCheckController + All localization files + fixed issues with MapPath from wwwroot to content root
This commit is contained in:
@@ -282,10 +282,10 @@ namespace Umbraco.Web.Editors
|
||||
// "examineMgmtBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl<ExamineManagementController>(
|
||||
// controller => controller.GetIndexerDetails())
|
||||
// },
|
||||
{
|
||||
"healthCheckBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl<HealthCheckController>(
|
||||
controller => controller.GetAllHealthChecks())
|
||||
},
|
||||
// {
|
||||
// "healthCheckBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl<HealthCheckController>(
|
||||
// controller => controller.GetAllHealthChecks())
|
||||
// },
|
||||
{
|
||||
"templateQueryApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl<TemplateQueryController>(
|
||||
controller => controller.PostTemplateQuery(null))
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.HealthCheck.Checks.Data
|
||||
{
|
||||
[HealthCheck(
|
||||
"73DD0C1C-E0CA-4C31-9564-1DCA509788AF",
|
||||
"Database data integrity check",
|
||||
Description = "Checks for various data integrity issues in the Umbraco database.",
|
||||
Group = "Data Integrity")]
|
||||
public class DatabaseIntegrityCheck : HealthCheck
|
||||
{
|
||||
private readonly IContentService _contentService;
|
||||
private readonly IMediaService _mediaService;
|
||||
private const string _fixMediaPaths = "fixMediaPaths";
|
||||
private const string _fixContentPaths = "fixContentPaths";
|
||||
private const string _fixMediaPathsTitle = "Fix media paths";
|
||||
private const string _fixContentPathsTitle = "Fix content paths";
|
||||
|
||||
public DatabaseIntegrityCheck(IContentService contentService, IMediaService mediaService)
|
||||
{
|
||||
_contentService = contentService;
|
||||
_mediaService = mediaService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the status for this health check
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override IEnumerable<HealthCheckStatus> GetStatus()
|
||||
{
|
||||
//return the statuses
|
||||
return new[]
|
||||
{
|
||||
CheckDocuments(false),
|
||||
CheckMedia(false)
|
||||
};
|
||||
}
|
||||
|
||||
private HealthCheckStatus CheckMedia(bool fix)
|
||||
{
|
||||
return CheckPaths(_fixMediaPaths, _fixMediaPathsTitle, Core.Constants.UdiEntityType.Media, fix,
|
||||
() => _mediaService.CheckDataIntegrity(new ContentDataIntegrityReportOptions {FixIssues = fix}));
|
||||
}
|
||||
|
||||
private HealthCheckStatus CheckDocuments(bool fix)
|
||||
{
|
||||
return CheckPaths(_fixContentPaths, _fixContentPathsTitle, Core.Constants.UdiEntityType.Document, fix,
|
||||
() => _contentService.CheckDataIntegrity(new ContentDataIntegrityReportOptions {FixIssues = fix}));
|
||||
}
|
||||
|
||||
private HealthCheckStatus CheckPaths(string actionAlias, string actionName, string entityType, bool detailedReport, Func<ContentDataIntegrityReport> doCheck)
|
||||
{
|
||||
var report = doCheck();
|
||||
|
||||
var actions = new List<HealthCheckAction>();
|
||||
if (!report.Ok)
|
||||
{
|
||||
actions.Add(new HealthCheckAction(actionAlias, Id)
|
||||
{
|
||||
Name = actionName
|
||||
});
|
||||
}
|
||||
|
||||
return new HealthCheckStatus(GetReport(report, entityType, detailedReport))
|
||||
{
|
||||
ResultType = report.Ok ? StatusResultType.Success : StatusResultType.Error,
|
||||
Actions = actions
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetReport(ContentDataIntegrityReport report, string entityType, bool detailed)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
if (report.Ok)
|
||||
{
|
||||
sb.AppendLine($"<p>All {entityType} paths are valid</p>");
|
||||
|
||||
if (!detailed)
|
||||
return sb.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine($"<p>{report.DetectedIssues.Count} invalid {entityType} paths detected.</p>");
|
||||
}
|
||||
|
||||
if (detailed && report.DetectedIssues.Count > 0)
|
||||
{
|
||||
sb.AppendLine("<ul>");
|
||||
foreach (var issueGroup in report.DetectedIssues.GroupBy(x => x.Value.IssueType))
|
||||
{
|
||||
var countByGroup = issueGroup.Count();
|
||||
var fixedByGroup = issueGroup.Count(x => x.Value.Fixed);
|
||||
sb.AppendLine("<li>");
|
||||
sb.AppendLine($"{countByGroup} issues of type <code>{issueGroup.Key}</code> ... {fixedByGroup} fixed");
|
||||
sb.AppendLine("</li>");
|
||||
}
|
||||
sb.AppendLine("</ul>");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public override HealthCheckStatus ExecuteAction(HealthCheckAction action)
|
||||
{
|
||||
switch (action.Alias)
|
||||
{
|
||||
case _fixContentPaths:
|
||||
return CheckDocuments(true);
|
||||
case _fixMediaPaths:
|
||||
return CheckMedia(true);
|
||||
default:
|
||||
throw new InvalidOperationException("Action not supported");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Http;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.Editors;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using Umbraco.Core.Configuration.HealthChecks;
|
||||
|
||||
namespace Umbraco.Web.HealthCheck
|
||||
{
|
||||
/// <summary>
|
||||
/// The API controller used to display the health check info and execute any actions
|
||||
/// </summary>
|
||||
[UmbracoApplicationAuthorize(Core.Constants.Applications.Settings)]
|
||||
public class HealthCheckController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
private readonly HealthCheckCollection _checks;
|
||||
private readonly IList<Guid> _disabledCheckIds;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public HealthCheckController(HealthCheckCollection checks, ILogger logger, IHealthChecksSettings healthChecksSettings)
|
||||
{
|
||||
_checks = checks ?? throw new ArgumentNullException(nameof(checks));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
var healthCheckConfig = healthChecksSettings ?? throw new ArgumentNullException(nameof(healthChecksSettings));
|
||||
_disabledCheckIds = healthCheckConfig.DisabledChecks
|
||||
.Select(x => x.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a grouped list of health checks, but doesn't actively check the status of each health check.
|
||||
/// </summary>
|
||||
/// <returns>Returns a collection of anonymous objects representing each group.</returns>
|
||||
public object GetAllHealthChecks()
|
||||
{
|
||||
var groups = _checks
|
||||
.Where(x => _disabledCheckIds.Contains(x.Id) == false)
|
||||
.GroupBy(x => x.Group)
|
||||
.OrderBy(x => x.Key);
|
||||
var healthCheckGroups = new List<HealthCheckGroup>();
|
||||
foreach (var healthCheckGroup in groups)
|
||||
{
|
||||
var hcGroup = new HealthCheckGroup
|
||||
{
|
||||
Name = healthCheckGroup.Key,
|
||||
Checks = healthCheckGroup
|
||||
.OrderBy(x => x.Name)
|
||||
.ToList()
|
||||
};
|
||||
healthCheckGroups.Add(hcGroup);
|
||||
}
|
||||
|
||||
return healthCheckGroups;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public object GetStatus(Guid id)
|
||||
{
|
||||
var check = GetCheckById(id);
|
||||
|
||||
try
|
||||
{
|
||||
//Core.Logging.LogHelper.Debug<HealthCheckController>("Running health check: " + check.Name);
|
||||
return check.GetStatus();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error<HealthCheckController>(ex, "Exception in health check: {HealthCheckName}", check.Name);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HealthCheckStatus ExecuteAction(HealthCheckAction action)
|
||||
{
|
||||
var check = GetCheckById(action.HealthCheckId);
|
||||
return check.ExecuteAction(action);
|
||||
}
|
||||
|
||||
private HealthCheck GetCheckById(Guid id)
|
||||
{
|
||||
var check = _checks
|
||||
.Where(x => _disabledCheckIds.Contains(x.Id) == false)
|
||||
.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
if (check == null) throw new InvalidOperationException($"No health check found with id {id}");
|
||||
|
||||
return check;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,6 @@
|
||||
<Compile Include="Editors\TinyMceController.cs" />
|
||||
<Compile Include="HttpContextAccessorExtensions.cs" />
|
||||
<Compile Include="HttpContextExtensions.cs" />
|
||||
<Compile Include="HealthCheck\Checks\Data\DatabaseIntegrityCheck.cs" />
|
||||
<Compile Include="ImageCropperTemplateCoreExtensions.cs" />
|
||||
<Compile Include="Install\ChangesMonitor.cs" />
|
||||
<Compile Include="Logging\OwinLogger.cs" />
|
||||
@@ -268,7 +267,6 @@
|
||||
<Compile Include="Editors\BackOfficeNotificationsController.cs" />
|
||||
<Compile Include="Editors\MemberGroupController.cs" />
|
||||
<Compile Include="Composing\CompositionExtensions\Controllers.cs" />
|
||||
<Compile Include="HealthCheck\HealthCheckController.cs" />
|
||||
<Compile Include="HtmlHelperBackOfficeExtensions.cs" />
|
||||
<Compile Include="Composing\ModuleInjector.cs" />
|
||||
<Compile Include="Mvc\FilteredControllerFactoryCollection.cs" />
|
||||
|
||||
Reference in New Issue
Block a user