StatusService update + AiCheckRoutine
This commit is contained in:
@@ -54,5 +54,14 @@ namespace BeWo.Data.Access
|
|||||||
|
|
||||||
return rtn;
|
return rtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsScriptExecuted(string script)
|
||||||
|
{
|
||||||
|
var sql = "SELECT Name FROM `.executedscripts`";
|
||||||
|
|
||||||
|
var rtn = Session.CreateSQLQuery(sql).List<string>();
|
||||||
|
|
||||||
|
return rtn.Contains(script);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace BeWo.Service
|
|||||||
OpenrouteServiceApiKey,
|
OpenrouteServiceApiKey,
|
||||||
GoogleDistanceMatrixApiKey,
|
GoogleDistanceMatrixApiKey,
|
||||||
GkvSecretKey,
|
GkvSecretKey,
|
||||||
|
AppStatusApiKey
|
||||||
}
|
}
|
||||||
|
|
||||||
[DefaultValue(None)]
|
[DefaultValue(None)]
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
using System.ServiceModel.Web;
|
using System.ServiceModel.Web;
|
||||||
@@ -20,6 +21,24 @@ namespace BeWo.Service.ServiceImplementations.Enhanced
|
|||||||
ConcurrencyMode = ConcurrencyMode.Single)]
|
ConcurrencyMode = ConcurrencyMode.Single)]
|
||||||
public class StatusServiceImp : IStatusService
|
public class StatusServiceImp : IStatusService
|
||||||
{
|
{
|
||||||
|
private readonly List<WebConfigSetting> RequiredWebConfigs = new List<WebConfigSetting>()
|
||||||
|
{
|
||||||
|
WebConfigSetting.OllamaUrl,
|
||||||
|
WebConfigSetting.Ollama2Url,
|
||||||
|
//WebConfigSetting.XRechnungApiUrl,
|
||||||
|
//WebConfigSetting.StoredFilesFolderPath,
|
||||||
|
//WebConfigSetting.StoredTenantFilesFolderPath,
|
||||||
|
//WebConfigSetting.HelloWorldPdfLocation,
|
||||||
|
//WebConfigSetting.BeWoPlanerServiceRoot,
|
||||||
|
WebConfigSetting.AiPromptsUrl
|
||||||
|
};
|
||||||
|
|
||||||
|
private readonly List<WebSecretConfigSetting> RequiredWebSecretConfigs = new List<WebSecretConfigSetting>()
|
||||||
|
{
|
||||||
|
WebSecretConfigSetting.Ollama2Key,
|
||||||
|
WebSecretConfigSetting.AppStatusApiKey
|
||||||
|
};
|
||||||
|
|
||||||
public ServerStatusDC GetStatus()
|
public ServerStatusDC GetStatus()
|
||||||
{
|
{
|
||||||
var result = new ServerStatusDC
|
var result = new ServerStatusDC
|
||||||
@@ -31,30 +50,31 @@ namespace BeWo.Service.ServiceImplementations.Enhanced
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Datenbankverbindung prüfen
|
// Datenbankverbindung prüfen
|
||||||
result.DatabaseOk = CheckDatabase();
|
result.DatabaseOk = executeCheck("Datenbank", CheckDatabase);
|
||||||
|
|
||||||
// Einzelne Subsysteme prüfen
|
// Einzelne Subsysteme prüfen
|
||||||
//result.Services.Add(CheckService("Mail", CheckMail()));
|
result.Services.Add(executeCheck("AIModule", CheckAiModule));
|
||||||
result.Services.Add(CheckService("AIModule", CheckAiModule()));
|
result.Services.Add(executeCheck("Web.config", CheckWebConfig));
|
||||||
result.Services.Add(CheckService("Web.config", CheckWebConfig()));
|
result.Services.Add(executeCheck("Web.Secret.config", CheckWebSecretConfig));
|
||||||
|
|
||||||
|
var allHealthy = result.DatabaseOk.IsOk && result.Services.All(x => x.IsOk);
|
||||||
|
if (!allHealthy)
|
||||||
|
{
|
||||||
|
WebOperationContext.Current.OutgoingResponse.StatusCode =
|
||||||
|
HttpStatusCode.InternalServerError;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private bool CheckDatabase()
|
private string CheckDatabase()
|
||||||
{
|
{
|
||||||
try
|
// Leichter DB-Ping – z.B. eine einfache Abfrage über DAOFactory
|
||||||
{
|
DAOFactory.GenericDAO.GetAll<ApplicationUser>();
|
||||||
// Leichter DB-Ping – z.B. eine einfache Abfrage über DAOFactory
|
|
||||||
DAOFactory.GenericDAO.GetAll<ApplicationUser>();
|
return null;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CheckMail()
|
private bool CheckMail()
|
||||||
@@ -73,51 +93,67 @@ namespace BeWo.Service.ServiceImplementations.Enhanced
|
|||||||
|
|
||||||
private string CheckAiModule()
|
private string CheckAiModule()
|
||||||
{
|
{
|
||||||
try
|
// #1
|
||||||
{
|
var configPath = ConfigReader.GetConfigPath(SpecialConfig.CustomPreSystemPrompt);
|
||||||
// #1
|
if (!File.Exists(configPath))
|
||||||
var configPath = ConfigReader.GetConfigPath(SpecialConfig.CustomPreSystemPrompt);
|
return "SpecialConfig.CustomPreSystemPrompt wurde nicht korrekt konfiguriert";
|
||||||
if (!File.Exists(configPath))
|
|
||||||
return "SpecialConfig.CustomPreSystemPrompt wurde nicht korrekt konfiguriert";
|
|
||||||
|
|
||||||
// #2
|
// #2
|
||||||
if (string.IsNullOrEmpty(MergedConfig.GetSecretSetting(WebSecretConfigSetting.Ollama2Key)))
|
if (string.IsNullOrEmpty(MergedConfig.GetSecretSetting(WebSecretConfigSetting.Ollama2Key)))
|
||||||
return "Ollama2Key wurde nicht korrekt konfiguriert";
|
return "Ollama2Key wurde nicht korrekt konfiguriert";
|
||||||
|
|
||||||
return null;
|
if (checkDatabaseScript("Changes_2026-05-22 AiConv ActionType") is string error)
|
||||||
}
|
return error;
|
||||||
catch
|
|
||||||
{
|
return null;
|
||||||
return "Fehler";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string CheckWebConfig()
|
private string CheckWebConfig()
|
||||||
{
|
{
|
||||||
|
foreach (var webConfig in RequiredWebConfigs)
|
||||||
|
{
|
||||||
|
var url = MergedConfig.GetSetting(webConfig);
|
||||||
|
if (string.IsNullOrWhiteSpace(url))
|
||||||
|
return $"'{webConfig}' wurde nicht korrekt konfiguriert";
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string CheckWebSecretConfig()
|
||||||
|
{
|
||||||
|
foreach (var webSecretConfig in RequiredWebSecretConfigs)
|
||||||
|
{
|
||||||
|
var key = MergedConfig.GetSecretSetting(webSecretConfig);
|
||||||
|
if (string.IsNullOrWhiteSpace(key))
|
||||||
|
return $"'{webSecretConfig}' wurde nicht korrekt konfiguriert";
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string checkDatabaseScript(string name)
|
||||||
|
{
|
||||||
|
var executed = DAOFactory.ScriptDAO.IsScriptExecuted(name);
|
||||||
|
|
||||||
|
return executed ? null : $"Script '{name}' wurde nicht ausgeführt";
|
||||||
|
}
|
||||||
|
|
||||||
|
private ServiceStatusDC executeCheck(string name, Func<string> validation)
|
||||||
|
{
|
||||||
|
string error;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// #1
|
error = validation();
|
||||||
var url = MergedConfig.GetSetting(WebConfigSetting.AiPromptsUrl);
|
|
||||||
if (!string.IsNullOrWhiteSpace(url))
|
|
||||||
return "AiPromptsUrl wurde nicht korrekt konfiguriert";
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return "Fehler";
|
error = ex.ToString();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private ServiceStatusDC CheckService(string name, string error)
|
var ok = string.IsNullOrEmpty(error);
|
||||||
{
|
|
||||||
var ok = error is null;
|
|
||||||
|
|
||||||
return CheckService(name, ok, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ServiceStatusDC CheckService(string name, bool ok, string error)
|
|
||||||
{
|
|
||||||
return new ServiceStatusDC
|
return new ServiceStatusDC
|
||||||
{
|
{
|
||||||
Name = name,
|
Name = name,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace BS.Shared.DataContracts
|
|||||||
public string Version { get; set; }
|
public string Version { get; set; }
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public bool DatabaseOk { get; set; }
|
public ServiceStatusDC DatabaseOk { get; set; }
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public List<ServiceStatusDC> Services { get; set; }
|
public List<ServiceStatusDC> Services { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user