diff --git a/src/BuslyCLI.Console/Commands/ServiceControl/CustomCheck/ListCustomChecksCommand.cs b/src/BuslyCLI.Console/Commands/ServiceControl/CustomCheck/ListCustomChecksCommand.cs new file mode 100644 index 00000000..9bf6f25e --- /dev/null +++ b/src/BuslyCLI.Console/Commands/ServiceControl/CustomCheck/ListCustomChecksCommand.cs @@ -0,0 +1,43 @@ +using BuslyCLI.Config; +using BuslyCLI.Infrastructure; +using Spectre.Console; +using Spectre.Console.Cli; + +namespace BuslyCLI.Commands.ServiceControl.CustomCheck; + +public class ListCustomChecksCommand(IAnsiConsole console, INServiceBusConfiguration nservicebusConfiguration, ServiceControlClient serviceControlClient) + : AsyncCommand +{ + protected override async Task ExecuteAsync(CommandContext context, ListCustomChecksSettings settings, CancellationToken cancellationToken) + { + var config = await nservicebusConfiguration.GetServiceControlValidatedConfigurationAsync(settings.Config.Path); + + var customChecks = await serviceControlClient.GetCustomChecksAsync(config.CurrentServiceControlInstanceConfig.Url, + status: "fail", + page: settings.Page, + pageSize: settings.PageSize, + cancellationToken); + + var table = new Table(); + table.AddColumn("Reported At"); + table.AddColumn("Status"); + table.AddColumn("Category"); + table.AddColumn("Reason"); + table.AddColumn("Endpoint"); + + foreach (var customCheck in customChecks.OrderByDescending(x => x.ReportedAt)) + { + table.AddRow( + customCheck.ReportedAt.ToString("u"), + // TODO: Currently it's hardcoded to only show failures in ServiceControlClient + customCheck.Status == "fail" ? "[red]Fail[/]" : "[green]Pass[/]", + customCheck.Category, + customCheck.FailureReason, + $"{customCheck.OriginatingEndpoint.Name} ({customCheck.OriginatingEndpoint.Host})"); + } + + console.Write(table); + + return 0; + } +} \ No newline at end of file diff --git a/src/BuslyCLI.Console/Commands/ServiceControl/CustomCheck/ListCustomChecksSettings.cs b/src/BuslyCLI.Console/Commands/ServiceControl/CustomCheck/ListCustomChecksSettings.cs new file mode 100644 index 00000000..77a1e48a --- /dev/null +++ b/src/BuslyCLI.Console/Commands/ServiceControl/CustomCheck/ListCustomChecksSettings.cs @@ -0,0 +1,18 @@ + + +using System.ComponentModel; +using BuslyCLI.Commands; +using Spectre.Console.Cli; + +public class ListCustomChecksSettings : GlobalCommandSettings +{ + [CommandOption("--page-size ")] + [DefaultValue(50)] + [Description("The page size to use when searching events")] + public int PageSize { get; set; } + + [CommandOption("--page-number ")] + [DefaultValue(1)] + [Description("The page number to use when searching events")] + public int Page { get; set; } +} \ No newline at end of file diff --git a/src/BuslyCLI.Console/Commands/ServiceControl/Message/SearchMessagesSettings.cs b/src/BuslyCLI.Console/Commands/ServiceControl/Message/SearchMessagesSettings.cs index 3d5fa275..72d73069 100644 --- a/src/BuslyCLI.Console/Commands/ServiceControl/Message/SearchMessagesSettings.cs +++ b/src/BuslyCLI.Console/Commands/ServiceControl/Message/SearchMessagesSettings.cs @@ -10,7 +10,7 @@ public class SearchMessagesSettings : GlobalCommandSettings public string Keyword { get; set; } = ""; [CommandOption("--endpoint ")] - [Description("The endpoint to search messages for")] + [Description("Filter to one endpoint")] public string Endpoint { get; set; } [CommandOption("--page-size ")] diff --git a/src/BuslyCLI.Console/Infrastructure/AppConfiguration.cs b/src/BuslyCLI.Console/Infrastructure/AppConfiguration.cs index f8bf3c38..28de3c80 100644 --- a/src/BuslyCLI.Console/Infrastructure/AppConfiguration.cs +++ b/src/BuslyCLI.Console/Infrastructure/AppConfiguration.cs @@ -3,6 +3,7 @@ using BuslyCLI.Commands.NsbCommand; using BuslyCLI.Commands.NsbEvent; using BuslyCLI.Commands.NsbTimeout; +using BuslyCLI.Commands.ServiceControl.CustomCheck; using BuslyCLI.Commands.ServiceControl.Endpoint; using BuslyCLI.Commands.ServiceControl.Event; using BuslyCLI.Commands.ServiceControl.Instance; @@ -90,7 +91,7 @@ public static Action GetSpectreCommandConfiguration() endpoints.SetDescription("Manage ServiceControl endpoints."); endpoints.AddCommand("list") .WithAlias("ls") - .WithDescription("List all endpoints for the current ServiceControl instance."); + .WithDescription("List all NServiceBus endpoints ServiceControl knows about."); endpoints.AddCommand("delete") .WithAlias("d") .WithDescription("Delete/Decommission an endpoint from the current ServiceControl instance."); @@ -116,6 +117,13 @@ public static Action GetSpectreCommandConfiguration() .WithAlias("ls") .WithDescription("Show events for the current ServiceControl instance."); }); + servicecontrol.AddBranch("custom-check", customChecks => + { + customChecks.SetDescription("Manage custom checks for the current ServiceControl instance."); + customChecks.AddCommand("list") + .WithAlias("ls") + .WithDescription("Show custom-checks for the current ServiceControl instance."); + }); }); config.SetExceptionHandler((ex, _) => diff --git a/src/BuslyCLI.Console/Infrastructure/ServiceControlClient.cs b/src/BuslyCLI.Console/Infrastructure/ServiceControlClient.cs index 6a4ee355..4734f71f 100644 --- a/src/BuslyCLI.Console/Infrastructure/ServiceControlClient.cs +++ b/src/BuslyCLI.Console/Infrastructure/ServiceControlClient.cs @@ -45,6 +45,17 @@ public async Task GetLicenseAsync(string baseUrl, Cancell return await httpClient.GetFromJsonAsync(url, JsonOptions, cancellationToken); } + public async Task> GetCustomChecksAsync(string baseUrl, string status = null, int page = 1, int pageSize = 50, CancellationToken cancellationToken = default) + { + var queryParams = new List { $"page={page}", $"pageSize={pageSize}" }; + + if (!string.IsNullOrEmpty(status)) + queryParams.Add($"status={Uri.EscapeDataString(status)}"); + + var url = $"{baseUrl.TrimEnd('/')}/customchecks?{string.Join("&", queryParams)}"; + return await httpClient.GetFromJsonAsync>(url, JsonOptions, cancellationToken) ?? []; + } + public async Task> SearchMessagesAsync( string baseUrl, string q = null, diff --git a/src/BuslyCLI.Console/Infrastructure/ServiceControlCustomCheck.cs b/src/BuslyCLI.Console/Infrastructure/ServiceControlCustomCheck.cs new file mode 100644 index 00000000..e1722976 --- /dev/null +++ b/src/BuslyCLI.Console/Infrastructure/ServiceControlCustomCheck.cs @@ -0,0 +1,19 @@ +namespace BuslyCLI.Infrastructure.ServiceControl; + +public class ServiceControlCustomCheck +{ + public string Id { get; set; } + public string CustomCheckId { get; set; } + public string Category { get; set; } + public string Status { get; set; } + public DateTimeOffset ReportedAt { get; set; } + public string FailureReason { get; set; } + public ServiceControlCustomCheckEndpoint OriginatingEndpoint { get; set; } +} + +public class ServiceControlCustomCheckEndpoint +{ + public string Name { get; set; } + public Guid HostId { get; set; } + public string Host { get; set; } +} \ No newline at end of file diff --git a/website/docs/cli-reference/cli-reference.md b/website/docs/cli-reference/cli-reference.md index d445f084..2898715d 100644 --- a/website/docs/cli-reference/cli-reference.md +++ b/website/docs/cli-reference/cli-reference.md @@ -20,6 +20,7 @@ This document contains information about all commands and settings available in - `busly servicecontrol endpoint delete` - `busly servicecontrol message search` - `busly servicecontrol license show` +- `busly servicecontrol custom-check list` ## Global Options diff --git a/website/docs/cli-reference/servicecontrol/.gitkeep b/website/docs/cli-reference/servicecontrol/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/website/docs/cli-reference/servicecontrol/custom-check/index.mdx b/website/docs/cli-reference/servicecontrol/custom-check/index.mdx new file mode 100644 index 00000000..d3af8dbb --- /dev/null +++ b/website/docs/cli-reference/servicecontrol/custom-check/index.mdx @@ -0,0 +1,7 @@ +import DocCardList from "@theme/DocCardList"; + +# busly servicecontrol custom-check + +Use `busly servicecontrol custom-check` to manage custom checks. + + diff --git a/website/docs/cli-reference/servicecontrol/custom-check/list.md b/website/docs/cli-reference/servicecontrol/custom-check/list.md new file mode 100644 index 00000000..17549b46 --- /dev/null +++ b/website/docs/cli-reference/servicecontrol/custom-check/list.md @@ -0,0 +1,23 @@ +# busly servicecontrol custom-check list + +List all failed custom-checks for the current ServiceControl instance. + +## Usage + +``` +busly servicecontrol custom-check list +``` + +## Aliases + +- `ls` + +## Options + +None + +## Examples + +``` +busly servicecontrol custom-check list +``` diff --git a/website/docs/cli-reference/servicecontrol/endpoint/.gitkeep b/website/docs/cli-reference/servicecontrol/endpoint/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/website/docs/cli-reference/servicecontrol/instance/.gitkeep b/website/docs/cli-reference/servicecontrol/instance/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/website/docs/cli-reference/servicecontrol/license/.gitkeep b/website/docs/cli-reference/servicecontrol/license/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/website/docs/cli-reference/servicecontrol/message/.gitkeep b/website/docs/cli-reference/servicecontrol/message/.gitkeep deleted file mode 100644 index e69de29b..00000000