Updated healthchecks to show a link to documentation instead of trying to fix something that can often not be fixed automatically.
This commit is contained in:
@@ -13,7 +13,7 @@ using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.Media;
|
||||
using Umbraco.Core.WebAssets;
|
||||
using Umbraco.Extensions;
|
||||
using Umbraco.Web.BackOffice.HealthCheck;
|
||||
using Umbraco.Web.BackOffice.HealthChecks;
|
||||
using Umbraco.Web.BackOffice.Profiling;
|
||||
using Umbraco.Web.BackOffice.PropertyEditors;
|
||||
using Umbraco.Web.BackOffice.Routing;
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
using System;
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.HealthCheck;
|
||||
using Umbraco.Core.HealthChecks;
|
||||
using Umbraco.Web.BackOffice.Controllers;
|
||||
using Umbraco.Web.BackOffice.Filters;
|
||||
using Umbraco.Web.Common.Attributes;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Umbraco.Web.Common.Authorization;
|
||||
|
||||
namespace Umbraco.Web.BackOffice.HealthCheck
|
||||
namespace Umbraco.Web.BackOffice.HealthChecks
|
||||
{
|
||||
/// <summary>
|
||||
/// The API controller used to display the health check info and execute any actions
|
||||
@@ -26,12 +29,15 @@ namespace Umbraco.Web.BackOffice.HealthCheck
|
||||
private readonly IList<Guid> _disabledCheckIds;
|
||||
private readonly ILogger<HealthCheckController> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HealthCheckController"/> class.
|
||||
/// </summary>
|
||||
public HealthCheckController(HealthCheckCollection checks, ILogger<HealthCheckController> logger, IOptions<HealthChecksSettings> healthChecksSettings)
|
||||
{
|
||||
_checks = checks ?? throw new ArgumentNullException(nameof(checks));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
|
||||
var healthCheckConfig = healthChecksSettings.Value ?? throw new ArgumentNullException(nameof(healthChecksSettings));
|
||||
HealthChecksSettings healthCheckConfig = healthChecksSettings.Value ?? throw new ArgumentNullException(nameof(healthChecksSettings));
|
||||
_disabledCheckIds = healthCheckConfig.DisabledChecks
|
||||
.Select(x => x.Id)
|
||||
.ToList();
|
||||
@@ -43,12 +49,12 @@ namespace Umbraco.Web.BackOffice.HealthCheck
|
||||
/// <returns>Returns a collection of anonymous objects representing each group.</returns>
|
||||
public object GetAllHealthChecks()
|
||||
{
|
||||
var groups = _checks
|
||||
IOrderedEnumerable<IGrouping<string, HealthCheck>> 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)
|
||||
foreach (IGrouping<string, HealthCheck> healthCheckGroup in groups)
|
||||
{
|
||||
var hcGroup = new HealthCheckGroup
|
||||
{
|
||||
@@ -63,15 +69,18 @@ namespace Umbraco.Web.BackOffice.HealthCheck
|
||||
return healthCheckGroups;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status of the HealthCheck with the specified id.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public object GetStatus(Guid id)
|
||||
public async Task<object> GetStatus(Guid id)
|
||||
{
|
||||
var check = GetCheckById(id);
|
||||
HealthCheck check = GetCheckById(id);
|
||||
|
||||
try
|
||||
{
|
||||
//Core.Logging.LogHelper.Debug<HealthCheckController>("Running health check: " + check.Name);
|
||||
return check.GetStatus();
|
||||
_logger.LogDebug("Running health check: " + check.Name);
|
||||
return await check.GetStatus();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -80,20 +89,26 @@ namespace Umbraco.Web.BackOffice.HealthCheck
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a given action from a HealthCheck.
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public HealthCheckStatus ExecuteAction(HealthCheckAction action)
|
||||
{
|
||||
var check = GetCheckById(action.HealthCheckId);
|
||||
HealthCheck check = GetCheckById(action.HealthCheckId);
|
||||
return check.ExecuteAction(action);
|
||||
}
|
||||
|
||||
private Core.HealthCheck.HealthCheck GetCheckById(Guid id)
|
||||
private HealthCheck GetCheckById(Guid id)
|
||||
{
|
||||
var check = _checks
|
||||
HealthCheck 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}");
|
||||
if (check == null)
|
||||
{
|
||||
throw new InvalidOperationException($"No health check found with id {id}");
|
||||
}
|
||||
|
||||
return check;
|
||||
}
|
||||
Reference in New Issue
Block a user