Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 05e5a209da | |||
| 0b88292a85 | |||
| 5bae9328d9 | |||
| 3a872980da | |||
| 8cda82111d | |||
| 6e17dcb270 | |||
| a1f9a2008f | |||
| 31da3d14a3 | |||
| ae8b60687a | |||
| 3fff8654fe | |||
| 9cfe9e2ab2 | |||
| fd799d6158 | |||
| 5f53207050 | |||
| 02dfdd2a07 |
@@ -10,7 +10,7 @@ env:
|
|||||||
DOTNET_VERSION: '8.0.x'
|
DOTNET_VERSION: '8.0.x'
|
||||||
DOCKER_IMAGE_NAME: watcher-server
|
DOCKER_IMAGE_NAME: watcher-server
|
||||||
REGISTRY_URL: git.triggermeelmo.com
|
REGISTRY_URL: git.triggermeelmo.com
|
||||||
DOCKER_PLATFORMS: 'linux/amd64,linux/arm64'
|
DOCKER_PLATFORMS: 'linux/amd64'
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
@@ -25,12 +25,14 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
submodules: false
|
submodules: false
|
||||||
|
|
||||||
- name: List files for debugging
|
# NuGet Cache
|
||||||
run: |
|
- name: Cache NuGet packages
|
||||||
pwd
|
uses: actions/cache@v3
|
||||||
ls -la
|
with:
|
||||||
find . -name "*.csproj"
|
path: ~/.nuget/packages
|
||||||
find . -name "*.sln"
|
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-nuget-
|
||||||
|
|
||||||
- name: Setup .NET SDK
|
- name: Setup .NET SDK
|
||||||
uses: actions/setup-dotnet@v3
|
uses: actions/setup-dotnet@v3
|
||||||
@@ -40,10 +42,16 @@ jobs:
|
|||||||
- name: Restore dependencies
|
- name: Restore dependencies
|
||||||
run: dotnet restore watcher-monitoring.sln
|
run: dotnet restore watcher-monitoring.sln
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: dotnet build watcher-monitoring.sln --configuration Release --no-restore
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: dotnet test watcher-monitoring.sln --no-build --verbosity normal
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
set-tag:
|
set-tag:
|
||||||
name: Set Tag Name
|
name: Set Tag Name
|
||||||
needs: [dotnet-build-and-test]
|
needs: [dotnet-build-and-test]
|
||||||
#if: ${{ !failure() && !cancelled() && github.event_name != 'pull_request' }}
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
tag_name: ${{ steps.set_tag.outputs.tag_name }}
|
tag_name: ${{ steps.set_tag.outputs.tag_name }}
|
||||||
@@ -105,6 +113,15 @@ jobs:
|
|||||||
- name: Setup Docker Buildx
|
- name: Setup Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
# Docker Layer Cache
|
||||||
|
- name: Cache Docker layers
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: /tmp/.buildx-cache
|
||||||
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-buildx-
|
||||||
|
|
||||||
- name: Login to Gitea Container Registry
|
- name: Login to Gitea Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
@@ -112,13 +129,23 @@ jobs:
|
|||||||
username: ${{ secrets.AUTOMATION_USERNAME }}
|
username: ${{ secrets.AUTOMATION_USERNAME }}
|
||||||
password: ${{ secrets.AUTOMATION_PASSWORD }}
|
password: ${{ secrets.AUTOMATION_PASSWORD }}
|
||||||
|
|
||||||
- name: Build and Push Multi-Arch Docker Image
|
- name: Build and Push Docker Image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
platforms: ${{ env.DOCKER_PLATFORMS }}
|
||||||
|
push: true
|
||||||
|
tags: ${{ env.REGISTRY_URL }}/triggermeelmo/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.set-tag.outputs.tag_name }}
|
||||||
|
build-args: |
|
||||||
|
VERSION=${{ needs.set-tag.outputs.tag_name }}
|
||||||
|
cache-from: type=local,src=/tmp/.buildx-cache
|
||||||
|
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
|
||||||
|
|
||||||
|
# Workaround für Cache-Größe
|
||||||
|
- name: Move cache
|
||||||
run: |
|
run: |
|
||||||
docker buildx build \
|
rm -rf /tmp/.buildx-cache
|
||||||
--platform ${{ env.DOCKER_PLATFORMS }} \
|
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
||||||
--build-arg VERSION=${{ needs.set-tag.outputs.tag_name }} \
|
|
||||||
-t ${{ env.REGISTRY_URL }}/watcher/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.set-tag.outputs.tag_name }} \
|
|
||||||
--push .
|
|
||||||
|
|
||||||
tag:
|
tag:
|
||||||
name: Create Tag
|
name: Create Tag
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ WORKDIR /app
|
|||||||
|
|
||||||
# Projektdateien kopieren und Abhängigkeiten wiederherstellen
|
# Projektdateien kopieren und Abhängigkeiten wiederherstellen
|
||||||
COPY *.sln .
|
COPY *.sln .
|
||||||
COPY watcher-monitoring/*.csproj ./Watcher/
|
COPY watcher-monitoring/*.csproj ./watcher-monitoring/
|
||||||
RUN dotnet restore
|
RUN dotnet restore
|
||||||
|
|
||||||
# Restliche Dateien kopieren und Build ausführen
|
# Restliche Dateien kopieren und Build ausführen
|
||||||
COPY watcher-monitoring/. ./Watcher/
|
COPY watcher-monitoring/. ./watcher-monitoring/
|
||||||
WORKDIR /app/Watcher
|
WORKDIR /app/watcher-monitoring
|
||||||
RUN dotnet publish -c Release -o /app/publish /p:UseAppHost=false
|
RUN dotnet publish -c Release -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
# 2. Laufzeit-Phase: ASP.NET Core Runtime
|
# 2. Laufzeit-Phase: ASP.NET Core Runtime
|
||||||
@@ -43,6 +43,7 @@ USER watcher
|
|||||||
|
|
||||||
# Expose Port 5000
|
# Expose Port 5000
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
|
|
||||||
ENV ASPNETCORE_URLS=http://*:5000
|
ENV ASPNETCORE_URLS=http://*:5000
|
||||||
ENV ASPNETCORE_ENVIRONMENT=Production
|
ENV ASPNETCORE_ENVIRONMENT=Production
|
||||||
|
|
||||||
@@ -50,4 +51,4 @@ ENV ASPNETCORE_ENVIRONMENT=Production
|
|||||||
ENV WATCHER_VERSION=${VERSION}
|
ENV WATCHER_VERSION=${VERSION}
|
||||||
|
|
||||||
# Anwendung starten
|
# Anwendung starten
|
||||||
ENTRYPOINT ["dotnet", "Watcher.dll"]
|
ENTRYPOINT ["dotnet", "watcher-monitoring.dll"]
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
watcher:
|
watcher:
|
||||||
image: git.triggermeelmo.com/watcher/watcher-server:latest
|
image: git.triggermeelmo.com/triggermeelmo/watcher-server:latest
|
||||||
container_name: watcher
|
container_name: watcher
|
||||||
|
|
||||||
# Resource Management
|
# Resource Management
|
||||||
@@ -8,7 +8,6 @@ services:
|
|||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
memory: 200M
|
memory: 200M
|
||||||
cpus: '0.5'
|
|
||||||
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,96 @@
|
|||||||
// Get Methoden um Metrics abzugreifen
|
// Get Methoden um Metrics abzugreifen
|
||||||
// Get Methden um Informationen über den Status des Servers einzuholen
|
// Get Methden um Informationen über den Status des Servers einzuholen
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using watcher_monitoring.Models;
|
||||||
|
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class APIController : Controller
|
||||||
|
{
|
||||||
|
private readonly WatcherDbContext _context;
|
||||||
|
|
||||||
|
private readonly ILogger<APIController> _logger;
|
||||||
|
|
||||||
|
public APIController(WatcherDbContext context, ILogger<APIController> logger)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server Calls
|
||||||
|
|
||||||
|
[HttpGet("get-server")]
|
||||||
|
public async Task<IActionResult> Servers()
|
||||||
|
{
|
||||||
|
List<Server> servers = await _context.Servers.ToListAsync();
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("add-server")]
|
||||||
|
public async Task<IActionResult> AddServer()
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("delete-server/{id}")]
|
||||||
|
public async Task<IActionResult> DeleteServer(int id)
|
||||||
|
{
|
||||||
|
var server = await _context.Servers.FindAsync(id);
|
||||||
|
if (server == null)
|
||||||
|
{
|
||||||
|
_logger.LogError("Server nicht gefunden");
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.Servers.Remove(server);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation("Server '{server}' erfolgreich gelöscht", server.Name);
|
||||||
|
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPut("edit-server")]
|
||||||
|
public async Task<IActionResult> EditServer()
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Container Calls
|
||||||
|
[HttpGet("get-container")]
|
||||||
|
public async Task<IActionResult> Containers()
|
||||||
|
{
|
||||||
|
List<Container> containers = await _context.Containers.ToListAsync();
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpDelete("delete-container")]
|
||||||
|
public async Task<IActionResult> DeleteContainer(int id)
|
||||||
|
{
|
||||||
|
var container = await _context.Containers.FindAsync(id);
|
||||||
|
if (container == null)
|
||||||
|
{
|
||||||
|
_logger.LogError("Server nicht gefunden");
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_context.Containers.Remove(container);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
_logger.LogInformation("Container '{container}' erfolgreich gelöscht", container.Id);
|
||||||
|
return Ok();
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex.Message);
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,28 +10,19 @@ namespace watcher_monitoring.Controllers;
|
|||||||
|
|
||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly WatcherDbContext _dbContext;
|
private readonly WatcherDbContext _context;
|
||||||
private readonly ILogger<HomeController> _logger;
|
private readonly ILogger<HomeController> _logger;
|
||||||
|
|
||||||
public HomeController(ILogger<HomeController> logger, WatcherDbContext dbContext)
|
public HomeController(ILogger<HomeController> logger, WatcherDbContext dbContext)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_dbContext = dbContext;
|
_context = dbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dashboard
|
// Dashboard
|
||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
List<Server> servers = await _dbContext.Servers.ToListAsync();
|
List<Server> servers = await _context.Servers.ToListAsync();
|
||||||
|
|
||||||
var servers1 = new List<dynamic>
|
|
||||||
{
|
|
||||||
new { Name = "Web Server 01", IPAddress = "192.168.1.10", IsOnline = true },
|
|
||||||
new { Name = "Database Server", IPAddress = "192.168.1.20", IsOnline = true },
|
|
||||||
new { Name = "API Gateway", IPAddress = "192.168.1.30", IsOnline = true },
|
|
||||||
new { Name = "Cache Server", IPAddress = "192.168.1.40", IsOnline = false },
|
|
||||||
new { Name = "Backup Server", IPAddress = "192.168.1.50", IsOnline = true }
|
|
||||||
};
|
|
||||||
|
|
||||||
ViewBag.TotalServers = servers.Count;
|
ViewBag.TotalServers = servers.Count;
|
||||||
ViewBag.OnlineServers = servers.Count(s => s.IsOnline);
|
ViewBag.OnlineServers = servers.Count(s => s.IsOnline);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using watcher_monitoring.Payloads;
|
using watcher_monitoring.Payloads;
|
||||||
using watcher_monitoring.Data;
|
using watcher_monitoring.Data;
|
||||||
using watcher_monitoring.Models;
|
using watcher_monitoring.Models;
|
||||||
|
using Microsoft.AspNetCore.Authorization.Infrastructure;
|
||||||
|
|
||||||
namespace watcher_monitoring.Controllers;
|
namespace watcher_monitoring.Controllers;
|
||||||
|
|
||||||
@@ -20,8 +21,8 @@ public class MonitoringController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Registration Endpoint for watcher-agent
|
// Registration Endpoint for watcher-agent
|
||||||
[HttpPost("registration")]
|
[HttpPost("register")]
|
||||||
public async Task<IActionResult> Registration([FromBody] RegistrationDto dto)
|
public async Task<IActionResult> Register([FromBody] RegistrationDto dto)
|
||||||
{
|
{
|
||||||
// payload check
|
// payload check
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
@@ -35,7 +36,22 @@ public class MonitoringController : Controller
|
|||||||
return BadRequest(new { error = "Invalid registration payload", details = errors });
|
return BadRequest(new { error = "Invalid registration payload", details = errors });
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok();
|
try {
|
||||||
|
Server server = new Server
|
||||||
|
{
|
||||||
|
Name = "test",
|
||||||
|
IPAddress = dto.IpAddress
|
||||||
|
};
|
||||||
|
|
||||||
|
_context.Servers.Add(server);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return Ok();
|
||||||
|
} catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
_logger.LogError(ex.Message);
|
||||||
|
return BadRequest();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hardware Configuration Endpoint for watcher-agent
|
// Hardware Configuration Endpoint for watcher-agent
|
||||||
@@ -56,7 +72,7 @@ public class MonitoringController : Controller
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Find Server in Database
|
// Find Server in Database
|
||||||
Server server = await _context.Servers.FindAsync(dto.Id);
|
var server = await _context.Servers.FindAsync(dto.Id);
|
||||||
|
|
||||||
// Add Hardware Configuration
|
// Add Hardware Configuration
|
||||||
try
|
try
|
||||||
@@ -67,6 +83,7 @@ public class MonitoringController : Controller
|
|||||||
server.RamSize = dto.RamSize;
|
server.RamSize = dto.RamSize;
|
||||||
// Diskspace fehlt
|
// Diskspace fehlt
|
||||||
|
|
||||||
|
_logger.LogInformation("Harware configuration successfull for server {server}", server.Name);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -83,9 +100,24 @@ public class MonitoringController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Server-Metrics endpoint for watcher-agent
|
// Server-Metrics endpoint for watcher-agent
|
||||||
|
[HttpPost("server-metrics/{id}")]
|
||||||
|
public async Task<IActionResult> ServerMetrics ([FromBody] HardwareDto dto)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
// Service-Detection endpoint for watcher-agent
|
// Service-Detection endpoint for watcher-agent
|
||||||
|
[HttpPost("container-detection")]
|
||||||
|
public async Task<IActionResult> ContainerDetection ([FromBody] HardwareDto dto)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
// Service-Metrics endpoint for watcher-agent
|
// Container-Metrics endpoint for watcher-agent
|
||||||
|
[HttpPost("container-metrics/{id}")]
|
||||||
|
public async Task<IActionResult> ContainerMetrics ([FromBody] HardwareDto dto)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -19,4 +19,6 @@ public class WatcherDbContext : DbContext
|
|||||||
public DbSet<Server> Servers { get; set; }
|
public DbSet<Server> Servers { get; set; }
|
||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
|
public DbSet<Container> Containers { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
114
watcher-monitoring/Migrations/20260108112653_containers-new.Designer.cs
generated
Normal file
114
watcher-monitoring/Migrations/20260108112653_containers-new.Designer.cs
generated
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using watcher_monitoring.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(WatcherDbContext))]
|
||||||
|
[Migration("20260108112653_containers-new")]
|
||||||
|
partial class containersnew
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.Container", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("ContainerName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Containers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.Server", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("CpuCores")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("CpuType")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("DiskSpace")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("GpuType")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("IPAddress")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<bool>("IsOnline")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<bool>("IsVerified")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastSeen")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<double>("RamSize")
|
||||||
|
.HasColumnType("REAL");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Servers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime>("LastLogin")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Username")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Users");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class containersnew : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Containers",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||||
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
|
ContainerName = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Containers", x => x.Id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Containers");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,22 @@ namespace watcher_monitoring.Migrations
|
|||||||
#pragma warning disable 612, 618
|
#pragma warning disable 612, 618
|
||||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
||||||
|
|
||||||
|
modelBuilder.Entity("watcher_monitoring.Models.Container", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("ContainerName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Containers");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("watcher_monitoring.Models.Server", b =>
|
modelBuilder.Entity("watcher_monitoring.Models.Server", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
|
|||||||
16
watcher-monitoring/Models/Container.cs
Normal file
16
watcher-monitoring/Models/Container.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace watcher_monitoring.Models;
|
||||||
|
|
||||||
|
public class Container
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(50)]
|
||||||
|
public required string ContainerName { get; set; } = null!;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace watcher_monitoring.Payloads;
|
namespace watcher_monitoring.Payloads;
|
||||||
|
|
||||||
public class RegistrationDto
|
public class RegistrationDto
|
||||||
{
|
{
|
||||||
public required string IpAddress;
|
[Required]
|
||||||
public required string Key;
|
public required string IpAddress { get; set; }
|
||||||
}
|
}
|
||||||
@@ -52,6 +52,31 @@ builder.Services.AddSwaggerGen(options =>
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Stelle sicher, dass das persistence-Verzeichnis existiert
|
||||||
|
var persistenceDir = Path.Combine(Directory.GetCurrentDirectory(), "persistence");
|
||||||
|
if (!Directory.Exists(persistenceDir))
|
||||||
|
{
|
||||||
|
Log.Information("Erstelle persistence-Verzeichnis: {PersistenceDir}", persistenceDir);
|
||||||
|
Directory.CreateDirectory(persistenceDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Datenbank-Migration beim Start ausführen
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var dbContext = scope.ServiceProvider.GetRequiredService<WatcherDbContext>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Log.Information("Führe Datenbank-Migrationen aus...");
|
||||||
|
dbContext.Database.Migrate();
|
||||||
|
Log.Information("Datenbank-Migrationen erfolgreich angewendet");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Fehler beim Ausführen der Datenbank-Migrationen");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user