Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<ListCustomChecksSettings>
{
protected override async Task<int> 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


using System.ComponentModel;
using BuslyCLI.Commands;
using Spectre.Console.Cli;

public class ListCustomChecksSettings : GlobalCommandSettings
{
[CommandOption("--page-size <page-size>")]
[DefaultValue(50)]
[Description("The page size to use when searching events")]
public int PageSize { get; set; }

[CommandOption("--page-number <page-number>")]
[DefaultValue(1)]
[Description("The page number to use when searching events")]
public int Page { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class SearchMessagesSettings : GlobalCommandSettings
public string Keyword { get; set; } = "";

[CommandOption("--endpoint <endpoint>")]
[Description("The endpoint to search messages for")]
[Description("Filter to one endpoint")]
public string Endpoint { get; set; }

[CommandOption("--page-size <page-size>")]
Expand Down
10 changes: 9 additions & 1 deletion src/BuslyCLI.Console/Infrastructure/AppConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,7 +91,7 @@ public static Action<IConfigurator> GetSpectreCommandConfiguration()
endpoints.SetDescription("Manage ServiceControl endpoints.");
endpoints.AddCommand<ListEndpointsCommand>("list")
.WithAlias("ls")
.WithDescription("List all endpoints for the current ServiceControl instance.");
.WithDescription("List all NServiceBus endpoints ServiceControl knows about.");
endpoints.AddCommand<DeleteEndpointCommand>("delete")
.WithAlias("d")
.WithDescription("Delete/Decommission an endpoint from the current ServiceControl instance.");
Expand All @@ -116,6 +117,13 @@ public static Action<IConfigurator> 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<ListCustomChecksCommand>("list")
.WithAlias("ls")
.WithDescription("Show custom-checks for the current ServiceControl instance.");
});
});

config.SetExceptionHandler((ex, _) =>
Expand Down
11 changes: 11 additions & 0 deletions src/BuslyCLI.Console/Infrastructure/ServiceControlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ public async Task<ServiceControlLicense> GetLicenseAsync(string baseUrl, Cancell
return await httpClient.GetFromJsonAsync<ServiceControlLicense>(url, JsonOptions, cancellationToken);
}

public async Task<IReadOnlyList<ServiceControlCustomCheck>> GetCustomChecksAsync(string baseUrl, string status = null, int page = 1, int pageSize = 50, CancellationToken cancellationToken = default)
{
var queryParams = new List<string> { $"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<List<ServiceControlCustomCheck>>(url, JsonOptions, cancellationToken) ?? [];
}

public async Task<IReadOnlyList<ServiceControlMessage>> SearchMessagesAsync(
string baseUrl,
string q = null,
Expand Down
19 changes: 19 additions & 0 deletions src/BuslyCLI.Console/Infrastructure/ServiceControlCustomCheck.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
1 change: 1 addition & 0 deletions website/docs/cli-reference/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import DocCardList from "@theme/DocCardList";

# busly servicecontrol custom-check

Use `busly servicecontrol custom-check` to manage custom checks.

<DocCardList />
23 changes: 23 additions & 0 deletions website/docs/cli-reference/servicecontrol/custom-check/list.md
Original file line number Diff line number Diff line change
@@ -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
```
Empty file.
Empty file.
Empty file.
Empty file.
Loading