Merge branch 'release/AddHealthCheck01'
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>WebDoorCreator - Egalware</i>
|
||||
<h4>Version: 0.9.2404.2311</h4>
|
||||
<h4>Version: 0.9.2404.2315</h4>
|
||||
<br /> Release note:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
0.9.2404.2311
|
||||
0.9.2404.2315
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>0.9.2404.2311</version>
|
||||
<version>0.9.2404.2315</version>
|
||||
<url>http://nexus.steamware.net/repository/SWS/WDC/stable/WDC.UI.zip</url>
|
||||
<changelog>http://nexus.steamware.net/repository/SWS/WDC/stable/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<WebPublishMethod>MSDeploy</WebPublishMethod>
|
||||
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
|
||||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||
<SiteUrlToLaunchAfterPublish>https://wdc.egalware.com/UI/swagger/index.html</SiteUrlToLaunchAfterPublish>
|
||||
<ExcludeApp_Data>false</ExcludeApp_Data>
|
||||
<ProjectGuid>c2109e71-4eae-4167-9052-175123ccc2bc</ProjectGuid>
|
||||
<SelfContained>false</SelfContained>
|
||||
<MSDeployServiceURL>https://wdc-w-iis-02.ovh:8172/MsDeploy.axd</MSDeployServiceURL>
|
||||
<DeployIisAppPath>wdc.egalware.com/SRV</DeployIisAppPath>
|
||||
<RemoteSitePhysicalPath />
|
||||
<SkipExtraFilesOnServer>false</SkipExtraFilesOnServer>
|
||||
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
|
||||
<EnableMSDeployBackup>true</EnableMSDeployBackup>
|
||||
<EnableMsDeployAppOffline>true</EnableMsDeployAppOffline>
|
||||
<UserName>steamware</UserName>
|
||||
<_SavePWD>true</_SavePWD>
|
||||
<_TargetId>IISWebDeploy</_TargetId>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
|
||||
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<TimeStampOfAssociatedLegacyPublishXmlFile />
|
||||
<EncryptedPassword>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAs/7D3mNhw0uqUXeNq4OiHAAAAAACAAAAAAADZgAAwAAAABAAAACWZ0w5h84UFtYYB4xT+4rFAAAAAASAAACgAAAAEAAAAIcwjcdAiCDZN1OwNWoZSfQYAAAAiyiNcp/zeuC6Vt16+OALvsaO0rbkiVMVFAAAAHS264wElPIM4sYvPHMhW0YsXNe9</EncryptedPassword>
|
||||
<History>True|2024-04-19T17:27:31.3742108Z;False|2024-04-19T16:51:43.3272308+02:00;False|2024-04-19T16:41:46.2086401+02:00;False|2024-04-19T16:41:31.3019711+02:00;False|2024-04-19T16:08:22.4275238+02:00;False|2024-04-19T16:05:18.6039531+02:00;False|2024-04-19T15:59:02.0838144+02:00;True|2024-02-15T19:34:35.8362293+01:00;False|2024-02-15T19:33:47.6399861+01:00;True|2024-02-13T17:40:01.6315651+01:00;False|2024-02-13T17:37:21.2072257+01:00;False|2024-02-13T17:33:33.1471911+01:00;True|2023-05-22T15:37:00.8611764+02:00;True|2023-05-11T17:35:09.5858697+02:00;True|2022-01-27T10:34:09.2346456+01:00;True|2022-01-27T10:13:36.3080675+01:00;True|2022-01-27T10:05:45.6649507+01:00;True|2022-01-26T14:34:16.5263189+01:00;True|2022-01-26T13:04:22.2336648+01:00;False|2022-01-26T13:04:06.0677616+01:00;True|2021-11-08T09:03:37.7855257+01:00;True|2021-11-08T09:03:34.8263479+01:00;True|2021-11-08T09:03:31.8889390+01:00;True|2021-10-29T16:19:33.6539408+02:00;True|2021-10-29T16:19:28.2082360+02:00;True|2021-10-26T16:12:11.7740950+02:00;True|2021-10-26T16:11:56.2014641+02:00;True|2021-10-26T16:11:22.2897842+02:00;False|2021-10-26T16:10:58.3733037+02:00;False|2021-10-26T16:10:29.4793991+02:00;True|2021-10-21T17:35:11.9761128+02:00;True|2021-10-18T20:22:00.9305399+02:00;True|2021-10-18T18:32:29.4558070+02:00;True|2021-10-18T18:32:22.8950294+02:00;True|2021-10-18T18:16:13.7563877+02:00;True|2021-10-18T18:15:48.5678387+02:00;True|2021-10-18T12:45:45.7228681+02:00;True|2021-10-18T12:14:22.3221605+02:00;True|2021-10-18T12:14:15.7373530+02:00;True|2021-10-18T12:10:43.8607301+02:00;</History>
|
||||
<LastFailureDetails />
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -8,8 +8,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_WebToolingArtifacts Remove="Properties\PublishProfiles\IIS-OVH-IIS01.pubxml" />
|
||||
<_WebToolingArtifacts Remove="Properties\PublishProfiles\IIS-OVH-IIS02.pubxml" />
|
||||
<_WebToolingArtifacts Remove="Properties\PublishProfiles\IIS-OVH-PROD-test.pubxml" />
|
||||
<_WebToolingArtifacts Remove="Properties\PublishProfiles\IIS-OVH-PROD.pubxml" />
|
||||
<_WebToolingArtifacts Remove="Properties\PublishProfiles\IIS-PROD.pubxml" />
|
||||
<_WebToolingArtifacts Remove="Properties\PublishProfiles\IIS01.pubxml" />
|
||||
<_WebToolingArtifacts Remove="Properties\PublishProfiles\IIS02.pubxml" />
|
||||
@@ -17,8 +18,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="Properties\PublishProfiles\IIS-OVH-IIS02.pubxml.user" />
|
||||
<None Include="Properties\PublishProfiles\IIS-OVH-PROD-test.pubxml.user" />
|
||||
<None Include="Properties\PublishProfiles\IIS-OVH-PROD.pubxml.user" />
|
||||
<None Include="Properties\PublishProfiles\IIS-OVH-IIS01.pubxml.user" />
|
||||
<None Include="Properties\PublishProfiles\IIS-PROD.pubxml.user" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using NLog;
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace WebDoorCreator.UI.Health
|
||||
{
|
||||
public class Checks
|
||||
{
|
||||
#region Private Fields
|
||||
|
||||
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public static async Task<HealthCheckResult> DbIdentity(string dbName)
|
||||
{
|
||||
string description = "Try check Table IdentityUsers";
|
||||
var healthCheckData = new Dictionary<string, object>();
|
||||
#if false
|
||||
using (var appDb = new UserIdentityDbContext())
|
||||
{
|
||||
List<TableCount> recordList = new List<TableCount>();
|
||||
try
|
||||
{
|
||||
string sqlQuery = $"SELECT 'AspNetUsers' AS TableName, COUNT(*) AS Count FROM information_schema.tables WHERE table_schema = '{dbName}' AND table_name = 'AspNetUsers' LIMIT 1;";
|
||||
var table = await Task.FromResult(appDb.DbSetCounts.FromSqlRaw(sqlQuery).ToList());
|
||||
|
||||
// provo a controllare se ho tab utenti
|
||||
if (table != null && table.Count > 0)
|
||||
{
|
||||
// controllo valore
|
||||
if (table[0].Count > 0)
|
||||
{
|
||||
description = $"Check IdentityUsers table, found!";
|
||||
return HealthCheckResult.Healthy(description, healthCheckData);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Errore in esecuzione DbIdentity");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return HealthCheckResult.Degraded(description + $" {dbName}", null, healthCheckData);
|
||||
}
|
||||
|
||||
public static async Task<HealthCheckResult> DbPlantTable(string dbName)
|
||||
{
|
||||
string description = "Try check Table PlantLog";
|
||||
var healthCheckData = new Dictionary<string, object>();
|
||||
#if false
|
||||
using (var appDb = new GWMSContext())
|
||||
{
|
||||
List<GWMS.Data.DatabaseModels.PlantDetailModel> recordList = new List<GWMS.Data.DatabaseModels.PlantDetailModel>();
|
||||
try
|
||||
{
|
||||
// provo a controllare se ho tab utenti
|
||||
recordList = await Task.FromResult(appDb.DbSetPlant.ToList()).ConfigureAwait(false);
|
||||
if (recordList.Count > 0)
|
||||
{
|
||||
description = $"Check PlantDetail table, found {recordList.Count} records";
|
||||
return HealthCheckResult.Healthy(description, healthCheckData);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Errore in esecuzione PlantDetail Table");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return HealthCheckResult.Degraded(description + $" {dbName}", null, healthCheckData);
|
||||
}
|
||||
|
||||
public static async Task<HealthCheckResult> DbUserRoot(string dbName)
|
||||
{
|
||||
string description = "Try check MySql User table";
|
||||
var healthCheckData = new Dictionary<string, object>();
|
||||
#if false
|
||||
using (var adminDb = new AdminContext())
|
||||
{
|
||||
List<GWMS.Data.DatabaseModels.UserPriv> userList = new List<GWMS.Data.DatabaseModels.UserPriv>();
|
||||
try
|
||||
{
|
||||
// provo a controllare se ho tab utenti
|
||||
userList = await Task.FromResult(adminDb.UserList.ToList()).ConfigureAwait(false);
|
||||
if (userList.Count > 0)
|
||||
{
|
||||
description = $"Check MySql User table, found {userList.Count} records";
|
||||
return HealthCheckResult.Healthy(description, healthCheckData);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Log.Error(exc, "Errore in esecuzione DbUserRoot");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return HealthCheckResult.Unhealthy(description + $" {dbName}", null, healthCheckData);
|
||||
}
|
||||
|
||||
public static async Task<HealthCheckResult> PingCheck(string hostName)
|
||||
{
|
||||
var description = $"Ping to {hostName}";
|
||||
var healthCheckData = new Dictionary<string, object>();
|
||||
using (var thePing = new Ping())
|
||||
{
|
||||
var pingResult = await thePing.SendPingAsync(hostName);
|
||||
healthCheckData.Add("RoundTripMS", pingResult.RoundtripTime);
|
||||
healthCheckData.Add("ActualIPAddress", pingResult.Address.ToString());
|
||||
if (pingResult.Status == IPStatus.Success)
|
||||
{
|
||||
description += $" - {pingResult.RoundtripTime}ms";
|
||||
return HealthCheckResult.Healthy(description, healthCheckData);
|
||||
}
|
||||
|
||||
}
|
||||
return HealthCheckResult.Unhealthy(description + $" {hostName}", null, healthCheckData);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,31 @@
|
||||
using Blazored.LocalStorage;
|
||||
using Blazored.SessionStorage;
|
||||
using HealthChecks.UI.Client;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.UI;
|
||||
using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using StackExchange.Redis;
|
||||
using System.Configuration;
|
||||
using System.Globalization;
|
||||
using System.Text.Json.Serialization;
|
||||
using WebDoorCreator.Data;
|
||||
using WebDoorCreator.Data.Services;
|
||||
using WebDoorCreator.UI;
|
||||
using WebDoorCreator.UI.Areas.Identity;
|
||||
using WebDoorCreator.UI.Data;
|
||||
using static Org.BouncyCastle.Math.EC.ECCurve;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
// configuration setup
|
||||
ConfigurationManager configuration = builder.Configuration;
|
||||
Microsoft.Extensions.Configuration.ConfigurationManager configuration = builder.Configuration;
|
||||
|
||||
// AspNetCore Identity setup
|
||||
var connectionString = builder.Configuration.GetConnectionString("Identity.DB");
|
||||
@@ -30,6 +36,49 @@ string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"))
|
||||
// avvio oggetto shared x redis...
|
||||
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
||||
|
||||
string dbServerAddr = "127.0.0.1";
|
||||
if(connectionString.Contains("Server"))
|
||||
{
|
||||
var dbTokens = connectionString.Split(";");
|
||||
bool trovato = false;
|
||||
int numTok = dbTokens.Count();
|
||||
int idx = 0;
|
||||
while(!trovato && idx< numTok)
|
||||
{
|
||||
if (dbTokens[idx].StartsWith("Server="))
|
||||
{
|
||||
dbServerAddr = dbTokens[idx].Replace("Server=", "");
|
||||
trovato = true;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
// healthchecks
|
||||
builder.Services.AddHealthChecks()
|
||||
//.AddSqlServer(connectionString, "MsSql instance")
|
||||
.AddAsyncCheck($"DB PING ({dbServerAddr})", () => WebDoorCreator.UI.Health.Checks.PingCheck(dbServerAddr))
|
||||
.AddAsyncCheck($"Redis PING ({redisSrvAddr})", () => WebDoorCreator.UI.Health.Checks.PingCheck(redisSrvAddr))
|
||||
//.AddProcessAllocatedMemoryHealthCheck(512, "Max Process memory (<512MB)", failureStatus: HealthStatus.Degraded) // 512 MB max allocated memory
|
||||
.AddRedis(connStringRedis, "Redis", failureStatus: HealthStatus.Degraded)
|
||||
//.AddAsyncCheck($"MsSql Root User", () => WebDoorCreator.UI.Health.Checks.DbUserRoot("MsSql"))
|
||||
//.AddAsyncCheck($"MsSql Identity", () => WebDoorCreator.UI.Health.Checks.DbIdentity(DbConfig.DATABASE_NAME))
|
||||
//.AddAsyncCheck($"MsSql PlantLog", () => WebDoorCreator.UI.Health.Checks.DbPlantTable(DbConfig.DATABASE_NAME))
|
||||
;
|
||||
|
||||
builder.Services
|
||||
.AddHealthChecksUI(s =>
|
||||
{
|
||||
s.AddHealthCheckEndpoint("GWMS_Services", "health");
|
||||
s.SetEvaluationTimeInSeconds(60);
|
||||
//s.SetEvaluationTimeInSeconds(60);
|
||||
s.SetMinimumSecondsBetweenFailureNotifications(120);
|
||||
s.SetApiMaxActiveRequests(5);
|
||||
s.SetHeaderText("GWMS Health Check Status");
|
||||
})
|
||||
.AddInMemoryStorage();
|
||||
|
||||
|
||||
|
||||
// abilitazione x email management con MailKit
|
||||
builder.Services.AddTransient<IEmailSender, MailKitEmailSender>();
|
||||
builder.Services.Configure<MailKitEmailSenderOptions>(options =>
|
||||
@@ -126,6 +175,11 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
app.MapBlazorHub();
|
||||
app.MapHealthChecks("/health", new HealthCheckOptions
|
||||
{
|
||||
Predicate = _ => true,
|
||||
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
|
||||
});
|
||||
app.MapFallbackToPage("/_Host");
|
||||
|
||||
app.Run();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>0.9.2404.2311</Version>
|
||||
<Version>0.9.2404.2315</Version>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>aspnet-WebDoorCreator.UI-dfe95fed-1398-4144-bd43-8b3a765d6608</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
@@ -37,6 +37,13 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.Redis" Version="6.0.4" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI" Version="6.0.5" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="6.0.5" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Core" Version="6.0.5" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="6.0.5" />
|
||||
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="6.0.3" />
|
||||
<PackageReference Include="Blazored.LocalStorage" Version="4.3.0" />
|
||||
<PackageReference Include="Blazored.SessionStorage" Version="2.3.0" />
|
||||
<PackageReference Include="DiffMatchPatch" Version="1.0.3" />
|
||||
@@ -50,6 +57,8 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="6.0.29" />
|
||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="6.0.29" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.14" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NLog" Version="5.2.2" />
|
||||
|
||||
Reference in New Issue
Block a user