Skip to content

Commit

Permalink
EventLogErrorSummary Kentico#217, fix OnlineMarketingTableAnalysis bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-ericd committed Jun 7, 2024
1 parent d372e3d commit 518ef96
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/KInspector.Blazor/Components/Modules/ResultTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}
else
{
<span>@value</span>
<span>@Truncate(value, 300)</span>
}
</td>
}
Expand Down Expand Up @@ -142,4 +142,20 @@

return properties.Select(prop => prop.GetValue(row));
}

private object Truncate(object? value, int maxLength)
{
if (value is not string)
{
return value;
}

var strVal = value.ToString();
if (!string.IsNullOrEmpty(strVal) && strVal.Length > maxLength)
{
return strVal.Substring(0, maxLength) + "...";
}

return strVal;
}
}
8 changes: 8 additions & 0 deletions src/KInspector.Blazor/wwwroot/css/app.min.css
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,10 @@ input:checked + .toggle-bg {
overflow-x: hidden;
}

.text-ellipsis {
text-overflow: ellipsis;
}

.whitespace-nowrap {
white-space: nowrap;
}
Expand Down Expand Up @@ -2264,6 +2268,10 @@ input:checked + .toggle-bg {
content: var(--tw-content);
}

.hover\:text-clip:hover {
text-overflow: clip;
}

.hover\:border-gray-300:hover {
--tw-border-opacity: 1;
border-color: rgb(209 213 219 / var(--tw-border-opacity));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
details:
name: Event log error summary
shortDescription: Shows all errors from the Event log.
longDescription: |
Displays all errors, their count, and first/last occurrences from the __Event log__.
terms:
good: No errors found.
information: <totalErrors> total <totalErrors|error|errors>.
eventLogTableName: Event log errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace KInspector.Reports.EventLogErrorSummary.Models
{
public class CmsErrorEvent
{
public int Count { get; set; }

public string? EventCode { get; set; }

public string? EventDescription { get; set; }

public string? Source { get; set; }

public DateTime? EventFirstDate { get; set; }

public DateTime? EventLastDate { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/KInspector.Reports/EventLogErrorSummary/Models/Terms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using KInspector.Core.Models;

namespace KInspector.Reports.EventLogErrorSummary.Models
{
public class Terms
{
public Term? Good { get; set; }

public Term? Information { get; set; }

public Term? EventLogTableName { get; set; }
}
}
54 changes: 54 additions & 0 deletions src/KInspector.Reports/EventLogErrorSummary/Report.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using KInspector.Core;
using KInspector.Core.Constants;
using KInspector.Core.Helpers;
using KInspector.Core.Models;
using KInspector.Core.Services.Interfaces;
using KInspector.Reports.EventLogErrorSummary.Models;

namespace KInspector.Reports.EventLogErrorSummary
{
public class Report : AbstractReport<Terms>
{
private readonly IDatabaseService databaseService;

public Report(IDatabaseService databaseService, IModuleMetadataService moduleMetadataService) : base(moduleMetadataService)
{
this.databaseService = databaseService;
}

public override IList<Version> CompatibleVersions => VersionHelper.GetVersionList("12", "13");

public override IList<string> Tags => new List<string> {
ModuleTags.Health,
ModuleTags.Information
};

public async override Task<ModuleResults> GetResults()
{
var errors = await databaseService.ExecuteSqlFromFile<CmsErrorEvent>(Scripts.GetEventLogErrors);
if (!errors.Any()) {
return new ModuleResults
{
Status = ResultsStatus.Good,
Summary = Metadata.Terms.Good,
Type = ResultsType.NoResults
};
}

var totalErrors = errors.Sum(e => e.Count);
var results = new ModuleResults
{
Status = ResultsStatus.Warning,
Summary = Metadata.Terms.Information?.With(new { totalErrors }),
Type = ResultsType.TableList
};
results.TableResults.Add(new TableResult
{
Name = Metadata.Terms.EventLogTableName,
Rows = errors
});

return results;
}
}
}
9 changes: 9 additions & 0 deletions src/KInspector.Reports/EventLogErrorSummary/Scripts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace KInspector.Reports.EventLogErrorSummary
{
public static class Scripts
{
public static string BaseDirectory => $"{nameof(EventLogErrorSummary)}/Scripts";

public static string GetEventLogErrors => $"{BaseDirectory}/{nameof(GetEventLogErrors)}.sql";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT Count(EventDescription) AS Count,
EventCode,
Source,
EventDescription,
MIN(EventTime) AS 'EventFirstDate',
MAX(EventTime) AS 'EventLastDate'
FROM CMS_EventLog
WHERE EventType = 'E'
GROUP BY Source, EventCode, EventDescription
ORDER BY Count DESC
7 changes: 7 additions & 0 deletions src/KInspector.Reports/KInspector.Reports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<None Update="ContentTreeChildrenAnalysis\Scripts\GetNodesWithManyChildren.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="EventLogErrorSummary\Metadata\en-US.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="EventLogErrorSummary\Scripts\GetEventLogErrors.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="InactiveContactSettingsSummary\Metadata\en-US.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -249,6 +255,7 @@

<ItemGroup>
<Folder Include="ContentTreeChildrenAnalysis\Scripts\" />
<Folder Include="EventLogErrorSummary\Scripts\" />
<Folder Include="InactiveContactSettingsSummary\Scripts\" />
<Folder Include="PageNotFoundSummary\Scripts\" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async override Task<ModuleResults> GetResults()
totalIssues++;
}

var totalScoringRules = await databaseService.ExecuteSqlFromFileScalar<int>(Scripts.GetScoringRulesCount);
var totalScoringRules = await databaseService.ExecuteSqlFromFileScalar<int>(Scripts.GetScoringRuleCount);
results.StringResults.Add(Metadata.Terms.ScoringRuleIssues?.With(new
{
totalScoringRules,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public static class Scripts

public static string GetContactGroupCount => $"{BaseDirectory}/{nameof(GetContactGroupCount)}.sql";

public static string GetScoringRulesCount => $"{BaseDirectory}/{nameof(GetScoringRulesCount)}.sql";
public static string GetScoringRuleCount => $"{BaseDirectory}/{nameof(GetScoringRuleCount)}.sql";
}
}

0 comments on commit 518ef96

Please sign in to comment.