diff --git a/Watcher/Controllers/HomeController.cs b/Watcher/Controllers/HomeController.cs index f043b7c..2032eb2 100644 --- a/Watcher/Controllers/HomeController.cs +++ b/Watcher/Controllers/HomeController.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; // Local Namespaces using Watcher.Data; +using Watcher.Models; using Watcher.ViewModels; namespace Watcher.Controllers @@ -41,7 +42,17 @@ namespace Watcher.Controllers OfflineServers = await _context.Servers.CountAsync(s => !s.IsOnline), RunningContainers = await _context.Containers.CountAsync(c => c.IsRunning), FailedContainers = await _context.Containers.CountAsync(c => !c.IsRunning), - LastLogin = user?.LastLogin ?? DateTime.MinValue + LastLogin = user?.LastLogin ?? DateTime.MinValue, + Servers = await _context.Servers + .OrderBy(s => s.Name) + .ToListAsync(), + RecentEvents = await _context.LogEvents + .OrderByDescending(e => e.Timestamp) + .Take(20) + .ToListAsync(), + Containers = await _context.Containers + .OrderBy(s => s.Name) + .ToListAsync() }; return View(viewModel); @@ -49,7 +60,7 @@ namespace Watcher.Controllers // Funktion fΓΌr /Views/Home/Index.cshtml um das DashboardStats-Partial neu zu laden. // Die Funktion wird nicht direkt aufgerufen, sondern nur der /Home/DashboardStats Endpoint angefragt. - public IActionResult DashboardStats() + public async Task DashboardStats() { var servers = _context.Servers.ToList(); var containers = _context.Containers.ToList(); @@ -58,14 +69,20 @@ namespace Watcher.Controllers var model = new DashboardViewModel { - ActiveServers = servers.Count(s => (now - s.LastSeen).TotalSeconds <= 120), - OfflineServers = servers.Count(s => (now - s.LastSeen).TotalSeconds > 120), - - //TODO: anwendbar, wenn Container implementiert wurden. - //RunningContainers = containers.Count(c => (now - c.LastSeen).TotalSeconds <= 120), - //FailedContainers = containers.Count(c => (now - c.LastSeen).TotalSeconds > 120), - - LastLogin = DateTime.Now + ActiveServers = await _context.Servers.CountAsync(s => s.IsOnline), + OfflineServers = await _context.Servers.CountAsync(s => !s.IsOnline), + RunningContainers = await _context.Containers.CountAsync(c => c.IsRunning), + FailedContainers = await _context.Containers.CountAsync(c => !c.IsRunning), + Servers = await _context.Servers + .OrderBy(s => s.Name) + .ToListAsync(), + RecentEvents = await _context.LogEvents + .OrderByDescending(e => e.Timestamp) + .Take(20) + .ToListAsync(), + Containers = await _context.Containers + .OrderBy(s => s.Name) + .ToListAsync() }; return PartialView("_DashboardStats", model); diff --git a/Watcher/Models/HealthStatus.cs b/Watcher/Models/HealthStatus.cs new file mode 100644 index 0000000..9e0012b --- /dev/null +++ b/Watcher/Models/HealthStatus.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace Watcher.Models +{ + public class HealthStatus + { + public DateTime Timestamp { get; set; } + + public bool NetworkOk { get; set; } + public bool DatabaseOk { get; set; } + public List Issues { get; set; } = new List(); + // Optional weitere Checks + public bool ApiOk { get; set; } + public bool DiskOk { get; set; } + } +} diff --git a/Watcher/Program.cs b/Watcher/Program.cs index 0c4e404..c20d108 100644 --- a/Watcher/Program.cs +++ b/Watcher/Program.cs @@ -1,14 +1,12 @@ -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Sqlite; -using Microsoft.IdentityModel.Tokens; using Serilog; using Watcher.Data; using Watcher.Models; +//using Watcher.Services; +//using Watcher.Workers; var builder = WebApplication.CreateBuilder(args); @@ -32,7 +30,6 @@ builder.Host.UseSerilog(); // Add services to the container. builder.Services.AddControllersWithViews(); - // HttpContentAccessor builder.Services.AddHttpContextAccessor(); @@ -112,7 +109,11 @@ builder.Services.AddAuthentication() var db = ctx.HttpContext.RequestServices.GetRequiredService(); var principal = ctx.Principal; +#pragma warning disable CS8602 // Dereference of a possibly null reference. + var pocketId = principal.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier")?.Value; +#pragma warning restore CS8602 // Dereference of a possibly null reference. + var preferredUsername = principal.FindFirst("preferred_username")?.Value; var email = principal.FindFirst("email")?.Value; diff --git a/Watcher/ViewModels/DashboardViewModel.cs b/Watcher/ViewModels/DashboardViewModel.cs index 02bf40f..624c9bd 100644 --- a/Watcher/ViewModels/DashboardViewModel.cs +++ b/Watcher/ViewModels/DashboardViewModel.cs @@ -1,3 +1,5 @@ +using Watcher.Models; + namespace Watcher.ViewModels { public class DashboardViewModel @@ -7,5 +9,10 @@ namespace Watcher.ViewModels public int RunningContainers { get; set; } public int FailedContainers { get; set; } public DateTime LastLogin { get; set; } + + public List Servers { get; set; } = new(); + public List RecentEvents { get; set; } = new(); + public List Containers { get; set; } = new(); + } } diff --git a/Watcher/Views/Home/Index.cshtml b/Watcher/Views/Home/Index.cshtml index 6b61e39..08bdad0 100644 --- a/Watcher/Views/Home/Index.cshtml +++ b/Watcher/Views/Home/Index.cshtml @@ -11,25 +11,6 @@ @await Html.PartialAsync("_DashboardStats", Model) -
- -
-
-

- Systeminfo -

-

- - Benutzer: @User.FindFirst("preferred_username")?.Value -

-

- - Letzter Login: @Model.LastLogin.ToString("g") -

-
-
-
- @section Scripts { +} diff --git a/Watcher/Views/Shared/_Layout.cshtml b/Watcher/Views/Shared/_Layout.cshtml index fbbcff3..aedb283 100644 --- a/Watcher/Views/Shared/_Layout.cshtml +++ b/Watcher/Views/Shared/_Layout.cshtml @@ -71,10 +71,10 @@ Dashboard