creates simple healthchecks
This commit is contained in:
66
HealthCheckResult.cs
Normal file
66
HealthCheckResult.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using MCVIngenieros.Healthchecks.Abstracts;
|
||||
|
||||
namespace MCVIngenieros.Healthchecks;
|
||||
|
||||
// Health check result model
|
||||
public record HealthCheckResult
|
||||
{
|
||||
public static HealthCheckResult Healthy(
|
||||
string? msg = null,
|
||||
HealthCheckSeverity severity = HealthCheckSeverity.Warning,
|
||||
Exception? exception = null,
|
||||
Dictionary<string, object>? data = null
|
||||
)
|
||||
{
|
||||
return new HealthCheckResult(true)
|
||||
{
|
||||
Details = msg ?? "Healthy",
|
||||
Severity = severity,
|
||||
Exception = exception,
|
||||
Data = data,
|
||||
};
|
||||
}
|
||||
|
||||
public static HealthCheckResult Unhealthy(
|
||||
string? msg = null,
|
||||
HealthCheckSeverity severity = HealthCheckSeverity.Warning,
|
||||
Exception? exception = null,
|
||||
Dictionary<string, object>? data = null
|
||||
)
|
||||
{
|
||||
return new HealthCheckResult(false)
|
||||
{
|
||||
Details = msg ?? "Unhealthy",
|
||||
Severity = severity,
|
||||
Exception = exception,
|
||||
Data = data,
|
||||
};
|
||||
}
|
||||
|
||||
public HealthCheckResult() { }
|
||||
public HealthCheckResult(bool IsHealthy)
|
||||
{
|
||||
this.IsHealthy = IsHealthy;
|
||||
}
|
||||
|
||||
public HealthCheckResult(bool IsHealthy, HealthCheckSeverity severity) : this(IsHealthy)
|
||||
{
|
||||
this.Severity = severity;
|
||||
}
|
||||
|
||||
public HealthCheckResult(bool IsHealthy, string name, string details = "", HealthCheckSeverity severity = HealthCheckSeverity.Info, Exception? exception = null, Dictionary<string, object>? data = null) : this(IsHealthy, severity)
|
||||
{
|
||||
this.Name = name;
|
||||
this.Details = details;
|
||||
this.Exception = exception;
|
||||
this.Data = data;
|
||||
}
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Details { get; set; } = string.Empty;
|
||||
public bool IsHealthy { get; set; }
|
||||
public HealthCheckSeverity Severity { get; set; } = HealthCheckSeverity.Info;
|
||||
public Exception? Exception { get; set; }
|
||||
public Dictionary<string, object>? Data { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user