From f09434d66d9a4b5d6ea29ccc74de422aa10cea1c Mon Sep 17 00:00:00 2001 From: triggermeelmo Date: Wed, 7 Jan 2026 12:47:23 +0100 Subject: [PATCH] test --- .../Controllers/HomeController.cs | 8 +- .../Controllers/MonitoringController.cs | 12 +++ ...260107105629_serverhardwareadd.Designer.cs | 86 ++++++++++++++++ .../20260107105629_serverhardwareadd.cs | 70 +++++++++++++ .../20260107110229_servermetadata.Designer.cs | 98 +++++++++++++++++++ .../20260107110229_servermetadata.cs | 63 ++++++++++++ .../WatcherDbContextModelSnapshot.cs | 27 +++++ watcher-monitoring/Models/Server.cs | 16 +++ watcher-monitoring/Payloads/HardwareDto.cs | 16 +++ 9 files changed, 394 insertions(+), 2 deletions(-) create mode 100644 watcher-monitoring/Migrations/20260107105629_serverhardwareadd.Designer.cs create mode 100644 watcher-monitoring/Migrations/20260107105629_serverhardwareadd.cs create mode 100644 watcher-monitoring/Migrations/20260107110229_servermetadata.Designer.cs create mode 100644 watcher-monitoring/Migrations/20260107110229_servermetadata.cs diff --git a/watcher-monitoring/Controllers/HomeController.cs b/watcher-monitoring/Controllers/HomeController.cs index a8fa45c..4f90f2c 100644 --- a/watcher-monitoring/Controllers/HomeController.cs +++ b/watcher-monitoring/Controllers/HomeController.cs @@ -3,6 +3,8 @@ using Microsoft.AspNetCore.Mvc; using watcher_monitoring.Models; using watcher_monitoring.Data; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; namespace watcher_monitoring.Controllers; @@ -18,9 +20,11 @@ public class HomeController : Controller } // Dashboard - public IActionResult Index() + public async Task Index() { - var servers = new List + List servers = await _dbContext.Servers.ToListAsync(); + + var servers1 = new List { new { Name = "Web Server 01", IPAddress = "192.168.1.10", IsOnline = true }, new { Name = "Database Server", IPAddress = "192.168.1.20", IsOnline = true }, diff --git a/watcher-monitoring/Controllers/MonitoringController.cs b/watcher-monitoring/Controllers/MonitoringController.cs index a70aeb2..bed6845 100644 --- a/watcher-monitoring/Controllers/MonitoringController.cs +++ b/watcher-monitoring/Controllers/MonitoringController.cs @@ -59,7 +59,19 @@ public class MonitoringController : Controller Server server = await _context.Servers.FindAsync(dto.Id); // Add Hardware Configuration + try + { + server.CpuType = dto.CpuType; + server.CpuCores = dto.CpuCores; + server.GpuType = dto.GpuType; + server.RamSize = dto.RamSize; + // Diskspace fehlt + } + catch (Exception ex) + { + _logger.LogError(ex.Message); + } } catch (Exception ex) { diff --git a/watcher-monitoring/Migrations/20260107105629_serverhardwareadd.Designer.cs b/watcher-monitoring/Migrations/20260107105629_serverhardwareadd.Designer.cs new file mode 100644 index 0000000..be4f67d --- /dev/null +++ b/watcher-monitoring/Migrations/20260107105629_serverhardwareadd.Designer.cs @@ -0,0 +1,86 @@ +// +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("20260107105629_serverhardwareadd")] + partial class serverhardwareadd + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.6"); + + modelBuilder.Entity("watcher_monitoring.Models.Server", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CpuCores") + .HasColumnType("INTEGER"); + + b.Property("CpuType") + .HasColumnType("TEXT"); + + b.Property("DiskSpace") + .HasColumnType("TEXT"); + + b.Property("GpuType") + .HasColumnType("TEXT"); + + b.Property("IPAddress") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RamSize") + .HasColumnType("REAL"); + + b.HasKey("Id"); + + b.ToTable("Servers"); + }); + + modelBuilder.Entity("watcher_monitoring.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Email") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LastLogin") + .HasColumnType("TEXT"); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/watcher-monitoring/Migrations/20260107105629_serverhardwareadd.cs b/watcher-monitoring/Migrations/20260107105629_serverhardwareadd.cs new file mode 100644 index 0000000..3fadc35 --- /dev/null +++ b/watcher-monitoring/Migrations/20260107105629_serverhardwareadd.cs @@ -0,0 +1,70 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace watcher_monitoring.Migrations +{ + /// + public partial class serverhardwareadd : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "CpuCores", + table: "Servers", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "CpuType", + table: "Servers", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "DiskSpace", + table: "Servers", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "GpuType", + table: "Servers", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "RamSize", + table: "Servers", + type: "REAL", + nullable: false, + defaultValue: 0.0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "CpuCores", + table: "Servers"); + + migrationBuilder.DropColumn( + name: "CpuType", + table: "Servers"); + + migrationBuilder.DropColumn( + name: "DiskSpace", + table: "Servers"); + + migrationBuilder.DropColumn( + name: "GpuType", + table: "Servers"); + + migrationBuilder.DropColumn( + name: "RamSize", + table: "Servers"); + } + } +} diff --git a/watcher-monitoring/Migrations/20260107110229_servermetadata.Designer.cs b/watcher-monitoring/Migrations/20260107110229_servermetadata.Designer.cs new file mode 100644 index 0000000..855f35d --- /dev/null +++ b/watcher-monitoring/Migrations/20260107110229_servermetadata.Designer.cs @@ -0,0 +1,98 @@ +// +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("20260107110229_servermetadata")] + partial class servermetadata + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.6"); + + modelBuilder.Entity("watcher_monitoring.Models.Server", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CpuCores") + .HasColumnType("INTEGER"); + + b.Property("CpuType") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DiskSpace") + .HasColumnType("TEXT"); + + b.Property("GpuType") + .HasColumnType("TEXT"); + + b.Property("IPAddress") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsOnline") + .HasColumnType("INTEGER"); + + b.Property("IsVerified") + .HasColumnType("INTEGER"); + + b.Property("LastSeen") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RamSize") + .HasColumnType("REAL"); + + b.HasKey("Id"); + + b.ToTable("Servers"); + }); + + modelBuilder.Entity("watcher_monitoring.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Email") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LastLogin") + .HasColumnType("TEXT"); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/watcher-monitoring/Migrations/20260107110229_servermetadata.cs b/watcher-monitoring/Migrations/20260107110229_servermetadata.cs new file mode 100644 index 0000000..2a0aaf5 --- /dev/null +++ b/watcher-monitoring/Migrations/20260107110229_servermetadata.cs @@ -0,0 +1,63 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace watcher_monitoring.Migrations +{ + /// + public partial class servermetadata : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "CreatedAt", + table: "Servers", + type: "TEXT", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + + migrationBuilder.AddColumn( + name: "IsOnline", + table: "Servers", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "IsVerified", + table: "Servers", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "LastSeen", + table: "Servers", + type: "TEXT", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "CreatedAt", + table: "Servers"); + + migrationBuilder.DropColumn( + name: "IsOnline", + table: "Servers"); + + migrationBuilder.DropColumn( + name: "IsVerified", + table: "Servers"); + + migrationBuilder.DropColumn( + name: "LastSeen", + table: "Servers"); + } + } +} diff --git a/watcher-monitoring/Migrations/WatcherDbContextModelSnapshot.cs b/watcher-monitoring/Migrations/WatcherDbContextModelSnapshot.cs index c88c6eb..ce0b993 100644 --- a/watcher-monitoring/Migrations/WatcherDbContextModelSnapshot.cs +++ b/watcher-monitoring/Migrations/WatcherDbContextModelSnapshot.cs @@ -23,14 +23,41 @@ namespace watcher_monitoring.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("CpuCores") + .HasColumnType("INTEGER"); + + b.Property("CpuType") + .HasColumnType("TEXT"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("DiskSpace") + .HasColumnType("TEXT"); + + b.Property("GpuType") + .HasColumnType("TEXT"); + b.Property("IPAddress") .IsRequired() .HasColumnType("TEXT"); + b.Property("IsOnline") + .HasColumnType("INTEGER"); + + b.Property("IsVerified") + .HasColumnType("INTEGER"); + + b.Property("LastSeen") + .HasColumnType("TEXT"); + b.Property("Name") .IsRequired() .HasColumnType("TEXT"); + b.Property("RamSize") + .HasColumnType("REAL"); + b.HasKey("Id"); b.ToTable("Servers"); diff --git a/watcher-monitoring/Models/Server.cs b/watcher-monitoring/Models/Server.cs index 40fb04b..b12e869 100644 --- a/watcher-monitoring/Models/Server.cs +++ b/watcher-monitoring/Models/Server.cs @@ -16,4 +16,20 @@ public class Server [Required] // TODO: [RegularExpression("^(((?!25?[6-9])[12]\d|[1-9])?\d\.?\b){4}$")] public required string IPAddress { get; set; } + + // Hardware Infos + public string? CpuType { get; set; } = string.Empty; + public int CpuCores { get; set; } = 0; + public string? GpuType { get; set; } = string.Empty; + public double RamSize { get; set; } = 0; + public string? DiskSpace { get; set; } = string.Empty; + + // Metadata + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + + public bool IsOnline { get; set; } = false; + + public DateTime LastSeen { get; set; } + + public bool IsVerified { get; set; } = false; } \ No newline at end of file diff --git a/watcher-monitoring/Payloads/HardwareDto.cs b/watcher-monitoring/Payloads/HardwareDto.cs index 9f799be..97f4387 100644 --- a/watcher-monitoring/Payloads/HardwareDto.cs +++ b/watcher-monitoring/Payloads/HardwareDto.cs @@ -7,4 +7,20 @@ public class HardwareDto { [Required] public required int Id; + + [Required] + public string? IpAddress { get; set; } + + // Hardware Info + [Required] + public string? CpuType { get; set; } + + [Required] + public int CpuCores { get; set; } + + [Required] + public string? GpuType { get; set; } + + [Required] + public double RamSize { get; set; } } \ No newline at end of file