Skip to content
Open
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,29 @@
using Azure.Communication.Sms;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
using OrchardCore.Sms.Azure.Models;

namespace OrchardCore.Sms.Azure.HealthChecks;

internal sealed class AzureSmsHealthCheck : IHealthCheck
{
private readonly AzureSmsOptions _azureSmsOptions;

public AzureSmsHealthCheck(IOptions<AzureSmsOptions> azureSmsOptions) => _azureSmsOptions = azureSmsOptions.Value;

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
var smsClient = new SmsClient(_azureSmsOptions.ConnectionString);

await smsClient.SendAsync(_azureSmsOptions.PhoneNumber, "+00000", "Test", cancellationToken: cancellationToken);

return HealthCheckResult.Healthy();
}
catch
{
return HealthCheckResult.Unhealthy(description: $"Unable to connect to Azure SMS service.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OrchardCore.Sms.Azure.HealthChecks;

namespace Microsoft.Extensions.DependencyInjection;

public static class AzureSmsHealthCheckExtensions
{
public static IHealthChecksBuilder AddAzureSmsHealthCheck(this IHealthChecksBuilder healthChecksBuilder)
=> healthChecksBuilder.AddCheck<AzureSmsHealthCheck>("Azure SMS Health Check");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Modules;

namespace OrchardCore.Sms.Azure.HealthChecks;

[RequireFeatures("OrchardCore.HealthChecks")]
public sealed class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services
.AddHealthChecks()
.AddAzureSmsHealthCheck();
}
}
4 changes: 4 additions & 0 deletions src/docs/reference/modules/Sms.Azure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ For more information about configurations, please refer to [Configuration](../Co

!!! note
Configuration of the **Default Azure Communication Services** provider cannot be performed through Admin Settings. Instead, use the configuration provider for setup. Note that the provider will only appear if the configuration is present.

## Health Checks

This module provides a health check to report the status for the Azure SMS service. Refer also to the [Health Checks Section](../HealthChecks/README.md).
Loading