notify doctors work, audit work, new product advisory sprints
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using StellaOps.DependencyInjection;
|
||||
using StellaOps.Notify.Engine;
|
||||
using StellaOps.Notify.Models;
|
||||
|
||||
namespace StellaOps.Notify.Connectors.Webhook;
|
||||
|
||||
/// <summary>
|
||||
/// Health provider for generic webhook notification channels.
|
||||
/// </summary>
|
||||
[ServiceBinding(typeof(INotifyChannelHealthProvider), ServiceLifetime.Singleton)]
|
||||
public sealed class WebhookChannelHealthProvider : INotifyChannelHealthProvider
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public NotifyChannelType ChannelType => NotifyChannelType.Webhook;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ChannelHealthResult> CheckAsync(ChannelHealthContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var builder = WebhookMetadataBuilder.CreateBuilder(context)
|
||||
.Add("webhook.channel.enabled", context.Channel.Enabled ? "true" : "false")
|
||||
.Add("webhook.validation.endpointPresent", HasConfiguredEndpoint(context.Channel) ? "true" : "false");
|
||||
|
||||
var metadata = builder.Build();
|
||||
var status = ResolveStatus(context.Channel);
|
||||
var message = status switch
|
||||
{
|
||||
ChannelHealthStatus.Healthy => "Webhook channel configuration validated.",
|
||||
ChannelHealthStatus.Degraded => "Webhook channel is disabled; enable it to resume deliveries.",
|
||||
ChannelHealthStatus.Unhealthy => "Webhook channel is missing a target URL or endpoint configuration.",
|
||||
_ => "Webhook channel diagnostics completed."
|
||||
};
|
||||
|
||||
return Task.FromResult(new ChannelHealthResult(status, message, metadata));
|
||||
}
|
||||
|
||||
private static ChannelHealthStatus ResolveStatus(NotifyChannel channel)
|
||||
{
|
||||
if (!HasConfiguredEndpoint(channel))
|
||||
{
|
||||
return ChannelHealthStatus.Unhealthy;
|
||||
}
|
||||
|
||||
if (!channel.Enabled)
|
||||
{
|
||||
return ChannelHealthStatus.Degraded;
|
||||
}
|
||||
|
||||
return ChannelHealthStatus.Healthy;
|
||||
}
|
||||
|
||||
private static bool HasConfiguredEndpoint(NotifyChannel channel)
|
||||
=> !string.IsNullOrWhiteSpace(channel.Config.Endpoint) ||
|
||||
!string.IsNullOrWhiteSpace(channel.Config.Target);
|
||||
}
|
||||
Reference in New Issue
Block a user