12 Commits

Author SHA1 Message Date
0974c1d7dd Merge pull request 'feature/db-check' (#21) from feature/db-check into development
All checks were successful
Development Build / build-and-test (push) Successful in 54s
Development Build / docker-build-and-push (push) Successful in 6m7s
Reviewed-on: #21
2025-10-03 13:11:17 +02:00
0e72287c6b Cache aktiviert 2025-10-03 13:10:56 +02:00
3918425ef9 Merge branch 'development' of https://git.triggermeelmo.com/Watcher/watcher into feature/db-check 2025-10-03 13:04:18 +02:00
ec13a51575 Merge pull request 'feature/network-check' (#20) from feature/network-check into development
All checks were successful
Development Build / build-and-test (push) Successful in 57s
Development Build / docker-build-and-push (push) Successful in 6m7s
Reviewed-on: #20
2025-10-03 13:03:31 +02:00
b8626cb8ea Debug Logs entfernt 2025-10-03 13:02:36 +02:00
281e9c686b Ui Anzeige fixed 2025-10-03 12:48:05 +02:00
69dd73a079 UI Anpassungen 2025-10-03 01:39:15 +02:00
2e9d41fe60 Sqlite Data Source angepasst 2025-10-02 17:55:06 +02:00
7e75f3e49e Background Service erstellt 2025-10-02 17:12:29 +02:00
8e362f7271 Merge branch 'feature/network-check' of https://git.triggermeelmo.com/Watcher/watcher into feature/db-check 2025-10-02 11:24:49 +02:00
52c4243efc Live Anzeige des Netzwerkstatus funktioniert 2025-10-01 10:15:50 +02:00
6248fad147 Background Service läuft im 60 Sekunden Rythmus. Ergebnis wird noch nciht gespeichert 2025-10-01 08:14:36 +02:00
12 changed files with 236 additions and 26 deletions

View File

@@ -10,11 +10,12 @@ env:
DOCKER_IMAGE_NAME: 'watcher-server'
REGISTRY_URL: 'git.triggermeelmo.com/watcher'
DOCKER_PLATFORMS: 'linux/amd64,linux/arm64'
RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache
jobs:
build-and-test:
runs-on: ubuntu-latest
env:
RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache
steps:
- name: Checkout code
uses: actions/checkout@v3
@@ -39,6 +40,8 @@ jobs:
docker-build-and-push:
runs-on: ubuntu-latest
env:
RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache
needs: build-and-test
steps:
- name: Checkout code

View File

@@ -50,13 +50,13 @@ jobs:
uses: docker/login-action@v2
with:
registry: git.triggermeelmo.com
username: ${{ secrets.AUTOMATION_USERNAME }}
password: ${{ secrets.AUTOMATION_PASSWORD }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Multi-Arch Docker Image
run: |
docker buildx build \
--platform ${{ env.DOCKER_PLATFORMS }} \
-t ${{ env.REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:v0.1.1 \
-t ${{ env.REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:v0.1.0 \
-t ${{ env.REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.sha }} \
--push .

View File

@@ -4,8 +4,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
// Local Namespaces
using Watcher.Data;
using Watcher.Models;
using Watcher.ViewModels;
using Watcher.Services;
namespace Watcher.Controllers
{
@@ -18,11 +18,16 @@ namespace Watcher.Controllers
// Logging einbinden
private readonly ILogger<HomeController> _logger;
// Daten der Backgroundchecks abrufen
private IDashboardStore _DashboardStore;
// HomeController Constructor
public HomeController(AppDbContext context, ILogger<HomeController> logger)
public HomeController(AppDbContext context, ILogger<HomeController> logger, IDashboardStore dashboardStore)
{
_context = context;
_logger = logger;
_DashboardStore = dashboardStore;
}
// Dashboard unter /home/index
@@ -52,9 +57,11 @@ namespace Watcher.Controllers
.ToListAsync(),
Containers = await _context.Containers
.OrderBy(s => s.Name)
.ToListAsync()
.ToListAsync(),
NetworkStatus = _DashboardStore.NetworkStatus,
DatabaseStatus = _DashboardStore.DatabaseStatus
};
//ViewBag.NetworkConnection = _NetworkCheckStore.NetworkStatus;
return View(viewModel);
}
@@ -82,11 +89,18 @@ namespace Watcher.Controllers
.ToListAsync(),
Containers = await _context.Containers
.OrderBy(s => s.Name)
.ToListAsync()
.ToListAsync(),
NetworkStatus = _DashboardStore.NetworkStatus,
DatabaseStatus = _DashboardStore.DatabaseStatus
};
return PartialView("_DashboardStats", model);
}
public String ReturnNetworkStatus()
{
return "OK";
}
}
}

View File

@@ -5,6 +5,7 @@ using Serilog;
using Watcher.Data;
using Watcher.Models;
using Watcher.Services;
//using Watcher.Services;
//using Watcher.Workers;
@@ -15,7 +16,7 @@ var builder = WebApplication.CreateBuilder(args);
// Serilog konfigurieren nur Logs, die nicht von Microsoft stammen
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning) // <--
.MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.File(
"logs/watcher-.log",
@@ -33,6 +34,13 @@ builder.Services.AddControllersWithViews();
// HttpContentAccessor
builder.Services.AddHttpContextAccessor();
// Storage Singleton
builder.Services.AddSingleton<IDashboardStore, DashboardStore>();
// Background Services
builder.Services.AddHostedService<NetworkCheck>();
builder.Services.AddHostedService<DatabaseCheck>();
// ---------- Konfiguration ----------
DotNetEnv.Env.Load();
@@ -214,4 +222,4 @@ app.MapControllerRoute(
pattern: "{controller=Home}/{action=Index}/{id?}"
);
app.Run();
app.Run();

View File

@@ -0,0 +1,8 @@
namespace Watcher.Services;
public class DashboardStore : IDashboardStore
{
public String? NetworkStatus { get; set; }
public String? DatabaseStatus { get; set; }
}

View File

@@ -0,0 +1,67 @@
using Microsoft.Data.Sqlite;
namespace Watcher.Services;
public class DatabaseCheck : BackgroundService
{
private readonly ILogger<DatabaseCheck> _logger;
private IDashboardStore _dashboardStore;
public DatabaseCheck(ILogger<DatabaseCheck> logger, IDashboardStore dashboardStore)
{
_logger = logger;
_dashboardStore = dashboardStore;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var timer = new PeriodicTimer(TimeSpan.FromSeconds(30));
while (await timer.WaitForNextTickAsync(stoppingToken))
{
// Hintergrundprozess abwarten
await checkDatabaseIntegrity();
// 5 Sekdunden Offset
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
}
// String sqliteConnectionString als Argument übergeben
public Task checkDatabaseIntegrity()
{
using var conn = new SqliteConnection("Data Source=./persistence/watcher.db");
_logger.LogInformation("Sqlite Integrity-Check started...");
try
{
conn.Open();
using var command = conn.CreateCommand();
command.CommandText = """
SELECT integrity_check FROM pragma_integrity_check;
""";
using var reader = command.ExecuteReader();
while (reader.Read())
{
string status = reader.GetString(0);
_dashboardStore.DatabaseStatus = status;
_logger.LogInformation("Sqlite DatabaseIntegrity: ${status}", status);
}
conn.Close();
}
catch (SqliteException e)
{
conn.Close();
_logger.LogError(e.Message);
// TODO: LogEvent erstellen
}
_logger.LogInformation("Database Integrity-Check finished.");
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,7 @@
namespace Watcher.Services;
public interface IDashboardStore
{
String? NetworkStatus { get; set; }
String? DatabaseStatus { get; set; }
}

View File

@@ -0,0 +1,59 @@
using System.Net.NetworkInformation;
namespace Watcher.Services;
public class NetworkCheck : BackgroundService
{
private readonly ILogger<NetworkCheck> _logger;
private IDashboardStore _DashboardStore;
public NetworkCheck(ILogger<NetworkCheck> logger, IDashboardStore DashboardStore)
{
_logger = logger;
_DashboardStore = DashboardStore;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var timer = new PeriodicTimer(TimeSpan.FromSeconds(30));
while (await timer.WaitForNextTickAsync(stoppingToken))
{
// Hintergrundprozess abwarten
await checkConnectionAsync();
// 5 Sekdunden Offset
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
}
}
public Task checkConnectionAsync()
{
_logger.LogInformation("Networkcheck started.");
string host = "8.8.8.8";
Ping p = new Ping();
try
{
PingReply reply = p.Send(host, 3000);
if (reply.Status == IPStatus.Success)
{
_DashboardStore.NetworkStatus = "online";
_logger.LogInformation("Ping successfull. Watcher is online.");
}
}
catch
{
_DashboardStore.NetworkStatus = "offline";
_logger.LogError("Ping failed. Watcher appears to have no network connection.");
// LogEvent erstellen
}
_logger.LogInformation("Networkcheck finished.");
return Task.CompletedTask;
}
}

View File

@@ -14,5 +14,8 @@ namespace Watcher.ViewModels
public List<LogEvent> RecentEvents { get; set; } = new();
public List<Container> Containers { get; set; } = new();
public String? NetworkStatus { get; set; } = "?";
public String? DatabaseStatus { get; set; } = "?";
}
}

View File

@@ -1,3 +1,4 @@
@using Microsoft.IdentityModel.Tokens
@model Watcher.ViewModels.DashboardViewModel
@{
@@ -57,18 +58,54 @@
<div class="card-body">
<h5 class="fw-bold mb-3"><i class="bi bi-heart-pulse me-2 text-danger"></i>Systemstatus</h5>
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Netzwerk</span>
<span class="badge bg-success">OK</span>
</div>
<div class="progress mb-3" style="height: 6px;">
<div class="progress-bar bg-success w-100"></div>
</div>
@if (!Model.NetworkStatus.IsNullOrEmpty())
{
@if (Model.NetworkStatus == "online")
{
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Netzwerk</span>
<span class="badge bg-success">@Model.NetworkStatus</span>
</div>
<div class="progress mb-3" style="height: 6px;">
<div class="progress-bar bg-success w-100"></div>
</div>
} else if (Model.NetworkStatus == "offline")
{
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Netzwerk</span>
<span class="badge bg-danger">@Model.NetworkStatus</span>
</div>
<div class="progress mb-3" style="height: 6px;">
<div class="progress-bar bg-danger w-100"></div>
</div>
}
}
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Datenbank</span>
<span class="badge bg-success">OK</span>
</div>
@if (!Model.DatabaseStatus.IsNullOrEmpty())
{
@if (Model.DatabaseStatus == "ok")
{
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Datenbank</span>
<span class="badge bg-success">healthy</span>
</div>
} else
{
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Datenbank</span>
<span class="badge bg-danger">unhealthy</span>
</div>
}
} else
{
<div class="d-flex justify-content-between align-items-center mb-2">
<span>Datenbank</span>
<span class="badge bg-primary">Missing Data</span>
</div>
}
<div class="progress mb-3" style="height: 6px;">
<div class="progress-bar bg-success w-100"></div>
</div>
@@ -97,6 +134,7 @@
</div>
<!-- Services -->
<!-- TODO
<div class="col-12 col-lg-6">
<div class="card shadow rounded-3 p-4 h-100">
<h2 class="h5 fw-semibold mb-3">Services</h2>
@@ -113,20 +151,22 @@
</ul>
</div>
</div>
-->
<!-- Server Liste -->
<!-- TODO
<div class="col-12 col-lg-6">
<div class="card shadow rounded-3 p-4 h-100">
<h2 class="h5 fw-semibold mb-3">Server</h2>
<ul class="list-group list-group-flush">
@foreach (var server in Model.Servers)
@foreach (Server server in Model.Servers)
{
<li class="list-group-item d-flex justify-content-between align-items-center serverlist">
<span>@server.Name</span>
<span class="badge bg-info")">
CPU: 30.45%
<span class="badge bg-info" )">
CPU:
</span>
<span class="badge bg-info")">
<span class="badge bg-info" )">
RAM: 65.09%
</span>
<span class="badge @(server.IsOnline ? "bg-success" : "bg-danger")">
@@ -136,6 +176,7 @@
}
</ul>
</div>
-->
</div>

Binary file not shown.