-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from TomaszKandula/dev
merge: dev to stage
- Loading branch information
Showing
42 changed files
with
674 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
EmailSender.Backend/EmailSender.Backend.Application/Logger/GetLogFileContentQuery.cs
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
EmailSender.Backend/EmailSender.Backend.Application/Logger/GetLogFileContentQueryHandler.cs
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
...lSender.Backend/EmailSender.Backend.Application/Logger/GetLogFileContentQueryValidator.cs
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
EmailSender.Backend/EmailSender.Backend.Application/Logger/GetLogFilesListQuery.cs
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
EmailSender.Backend/EmailSender.Backend.Application/Logger/GetLogFilesListQueryHandler.cs
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
EmailSender.Backend/EmailSender.Backend.Application/Logger/GetLogFilesListQueryResult.cs
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
EmailSender.Backend/EmailSender.Backend.Application/Mailcow/GetMailcowStatusQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using MediatR; | ||
|
||
namespace EmailSender.Backend.Application.Mailcow; | ||
|
||
public class GetMailcowStatusQuery : IRequest<GetMailcowStatusQueryResult> { } |
103 changes: 103 additions & 0 deletions
103
EmailSender.Backend/EmailSender.Backend.Application/Mailcow/GetMailcowStatusQueryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System.Reflection; | ||
using EmailSender.Backend.Application.Mailcow.Models; | ||
using EmailSender.Backend.Core.Utilities.LoggerService; | ||
using EmailSender.Services.HttpClientService.Abstractions; | ||
using EmailSender.Services.HttpClientService.Models; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace EmailSender.Backend.Application.Mailcow; | ||
|
||
public class GetMailcowStatusQueryHandler : RequestHandler<GetMailcowStatusQuery, GetMailcowStatusQueryResult> | ||
{ | ||
private readonly IHttpClientServiceFactory _httpClientServiceFactory; | ||
|
||
private readonly ILoggerService _loggerService; | ||
|
||
private readonly IConfiguration _configuration; | ||
|
||
private const BindingFlags Flags = BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetField; | ||
|
||
public GetMailcowStatusQueryHandler(IHttpClientServiceFactory httpClientServiceFactory, ILoggerService loggerService, IConfiguration configuration) | ||
{ | ||
_httpClientServiceFactory = httpClientServiceFactory; | ||
_loggerService = loggerService; | ||
_configuration = configuration; | ||
} | ||
|
||
public override async Task<GetMailcowStatusQueryResult> Handle(GetMailcowStatusQuery request, CancellationToken cancellationToken) | ||
{ | ||
var headers = new Dictionary<string, string> | ||
{ | ||
["X-API-Key"] = _configuration.GetValue<string>("Mailcow_API_Key") | ||
}; | ||
|
||
var configuration = new Configuration | ||
{ | ||
Url = _configuration.GetValue<string>("Mailcow_Status_Url"), | ||
Method = "GET", | ||
Headers = headers | ||
}; | ||
|
||
var client = _httpClientServiceFactory.Create(false, _loggerService); | ||
var result = await client.Execute<MailcowStatus>(configuration, cancellationToken); | ||
|
||
var healthyCount = 0; | ||
var unhealthyCount = 0; | ||
var data = new List<StatusItem>(); | ||
|
||
var resultType = result.GetType(); | ||
var resultProps = resultType.GetProperties(Flags); | ||
|
||
foreach (var prop in resultProps) | ||
{ | ||
var item = prop.GetValue(result, null); | ||
if (item is null) | ||
continue; | ||
|
||
var statusItem = item as StatusItem; | ||
data.Add(statusItem!); | ||
|
||
if (statusItem?.State == "running") | ||
{ | ||
healthyCount += 1; | ||
} | ||
else | ||
{ | ||
unhealthyCount += 1; | ||
} | ||
} | ||
|
||
if (healthyCount == data.Count) | ||
{ | ||
return new GetMailcowStatusQueryResult | ||
{ | ||
Status = StatusTypes.Healthy, | ||
Results = data | ||
}; | ||
} | ||
|
||
if (healthyCount != unhealthyCount) | ||
{ | ||
return new GetMailcowStatusQueryResult | ||
{ | ||
Status = StatusTypes.Degraded, | ||
Results = data | ||
}; | ||
} | ||
|
||
if (healthyCount == 0) | ||
{ | ||
return new GetMailcowStatusQueryResult | ||
{ | ||
Status = StatusTypes.Unhealthy, | ||
Results = data | ||
}; | ||
} | ||
|
||
return new GetMailcowStatusQueryResult | ||
{ | ||
Status = StatusTypes.Unknown, | ||
Results = data | ||
}; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
EmailSender.Backend/EmailSender.Backend.Application/Mailcow/GetMailcowStatusQueryResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using EmailSender.Backend.Application.Mailcow.Models; | ||
|
||
namespace EmailSender.Backend.Application.Mailcow; | ||
|
||
public class GetMailcowStatusQueryResult | ||
{ | ||
public StatusTypes Status { get; set; } | ||
|
||
public IList<StatusItem>? Results { get; set; } | ||
} |
63 changes: 63 additions & 0 deletions
63
EmailSender.Backend/EmailSender.Backend.Application/Mailcow/Models/MailcowStatus.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace EmailSender.Backend.Application.Mailcow.Models; | ||
|
||
public class MailcowStatus | ||
{ | ||
[JsonProperty("ipv6nat-mailcow")] | ||
public StatusItem? Ipv6Nat { get; set; } | ||
|
||
[JsonProperty("watchdog-mailcow")] | ||
public StatusItem? Watchdog { get; set; } | ||
|
||
[JsonProperty("acme-mailcow")] | ||
public StatusItem? Acme { get; set; } | ||
|
||
[JsonProperty("ofelia-mailcow")] | ||
public StatusItem? Ofelia { get; set; } | ||
|
||
[JsonProperty("rspamd-mailcow")] | ||
public StatusItem? Rspamd { get; set; } | ||
|
||
[JsonProperty("nginx-mailcow")] | ||
public StatusItem? Nginx { get; set; } | ||
|
||
[JsonProperty("postfix-mailcow")] | ||
public StatusItem? Postfix { get; set; } | ||
|
||
[JsonProperty("dovecot-mailcow")] | ||
public StatusItem? DoveCot { get; set; } | ||
|
||
[JsonProperty("php-fpm-mailcow")] | ||
public StatusItem? PhpFpm { get; set; } | ||
|
||
[JsonProperty("mysql-mailcow")] | ||
public StatusItem? MySql { get; set; } | ||
|
||
[JsonProperty("redis-mailcow")] | ||
public StatusItem? Redis { get; set; } | ||
|
||
[JsonProperty("solr-mailcow")] | ||
public StatusItem? Solr { get; set; } | ||
|
||
[JsonProperty("clamd-mailcow")] | ||
public StatusItem? Clamd { get; set; } | ||
|
||
[JsonProperty("dockerapi-mailcow")] | ||
public StatusItem? DockerApi { get; set; } | ||
|
||
[JsonProperty("memcached-mailcow")] | ||
public StatusItem? MemCached { get; set; } | ||
|
||
[JsonProperty("sogo-mailcow")] | ||
public StatusItem? SoGo { get; set; } | ||
|
||
[JsonProperty("unbound-mailcow")] | ||
public StatusItem? Unbound { get; set; } | ||
|
||
[JsonProperty("netfilter-mailcow")] | ||
public StatusItem? NetFilter { get; set; } | ||
|
||
[JsonProperty("olefy-mailcow")] | ||
public StatusItem? Olefy { get; set; } | ||
} |
21 changes: 21 additions & 0 deletions
21
EmailSender.Backend/EmailSender.Backend.Application/Mailcow/Models/StatusItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace EmailSender.Backend.Application.Mailcow.Models; | ||
|
||
public class StatusItem | ||
{ | ||
[JsonProperty("type")] | ||
public string? Type { get; set; } | ||
|
||
[JsonProperty("container")] | ||
public string? Container { get; set; } | ||
|
||
[JsonProperty("state")] | ||
public string? State { get; set; } | ||
|
||
[JsonProperty("started_at")] | ||
public DateTime? StartedAt { get; set; } | ||
|
||
[JsonProperty("image")] | ||
public string? Image { get; set; } | ||
} |
9 changes: 9 additions & 0 deletions
9
EmailSender.Backend/EmailSender.Backend.Application/Mailcow/Models/StatusTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace EmailSender.Backend.Application.Mailcow.Models; | ||
|
||
public enum StatusTypes | ||
{ | ||
Unknown, | ||
Healthy, | ||
Degraded, | ||
Unhealthy | ||
} |
18 changes: 18 additions & 0 deletions
18
EmailSender.Backend/EmailSender.Backend.Shared/Resources/ErrorCodes.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.