diff --git a/watcher-monitoring/Controllers/ApiController.cs b/watcher-monitoring/Controllers/ApiController.cs index cae55cf..8a97db1 100644 --- a/watcher-monitoring/Controllers/ApiController.cs +++ b/watcher-monitoring/Controllers/ApiController.cs @@ -75,7 +75,7 @@ public class APIController : Controller GpuType = serverDto.GpuType, RamSize = serverDto.RamSize, DiskSpace = serverDto.DiskSpace, - IsOnline = serverDto.IsOnline, + State = serverDto.State, IsVerified = serverDto.IsVerified }; diff --git a/watcher-monitoring/Controllers/HomeController.cs b/watcher-monitoring/Controllers/HomeController.cs index 95fa93e..8821364 100644 --- a/watcher-monitoring/Controllers/HomeController.cs +++ b/watcher-monitoring/Controllers/HomeController.cs @@ -32,8 +32,8 @@ public class HomeController : Controller servers = _servers, containers = _containers, serversCount = _servers.Count, - serversOnline = (from server in _servers where server.IsOnline select server).Count(), - serversOffline = _servers.Count - (from server in _servers where server.IsOnline select server).Count() + serversOnline = (from server in _servers where server.State=="online" select server).Count(), + serversOffline = (from server in _servers where server.State=="offline" select server).Count() }; return View(homeVm); diff --git a/watcher-monitoring/Migrations/20260121112553_changedServerAndContainerAttributeState.Designer.cs b/watcher-monitoring/Migrations/20260121112553_changedServerAndContainerAttributeState.Designer.cs new file mode 100644 index 0000000..9ab29c1 --- /dev/null +++ b/watcher-monitoring/Migrations/20260121112553_changedServerAndContainerAttributeState.Designer.cs @@ -0,0 +1,186 @@ +// +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("20260121112553_changedServerAndContainerAttributeState")] + partial class changedServerAndContainerAttributeState + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.6"); + + modelBuilder.Entity("watcher_monitoring.Models.ApiKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("Description") + .HasColumnType("TEXT"); + + b.Property("ExpiresAt") + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("Key") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT"); + + b.Property("LastUsedAt") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("ApiKeys"); + }); + + modelBuilder.Entity("watcher_monitoring.Models.Container", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ContainerName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.Property("State") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Containers"); + }); + + 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("IsVerified") + .HasColumnType("INTEGER"); + + b.Property("LastSeen") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("RamSize") + .HasColumnType("REAL"); + + b.Property("State") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Servers"); + }); + + modelBuilder.Entity("watcher_monitoring.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreatedAt") + .HasColumnType("TEXT"); + + b.Property("Email") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsActive") + .HasColumnType("INTEGER"); + + b.Property("LastLogin") + .HasColumnType("TEXT"); + + b.Property("OidcSubject") + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("watcher_monitoring.Models.ApiKey", b => + { + b.HasOne("watcher_monitoring.Models.User", "User") + .WithMany("ApiKeys") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("watcher_monitoring.Models.User", b => + { + b.Navigation("ApiKeys"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/watcher-monitoring/Migrations/20260121112553_changedServerAndContainerAttributeState.cs b/watcher-monitoring/Migrations/20260121112553_changedServerAndContainerAttributeState.cs new file mode 100644 index 0000000..5461e8c --- /dev/null +++ b/watcher-monitoring/Migrations/20260121112553_changedServerAndContainerAttributeState.cs @@ -0,0 +1,51 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace watcher_monitoring.Migrations +{ + /// + public partial class changedServerAndContainerAttributeState : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "IsOnline", + table: "Servers"); + + migrationBuilder.AddColumn( + name: "State", + table: "Servers", + type: "TEXT", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "State", + table: "Containers", + type: "TEXT", + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "State", + table: "Servers"); + + migrationBuilder.DropColumn( + name: "State", + table: "Containers"); + + migrationBuilder.AddColumn( + name: "IsOnline", + table: "Servers", + type: "INTEGER", + nullable: false, + defaultValue: false); + } + } +} diff --git a/watcher-monitoring/Migrations/WatcherDbContextModelSnapshot.cs b/watcher-monitoring/Migrations/WatcherDbContextModelSnapshot.cs index 0cfda56..f089f40 100644 --- a/watcher-monitoring/Migrations/WatcherDbContextModelSnapshot.cs +++ b/watcher-monitoring/Migrations/WatcherDbContextModelSnapshot.cs @@ -69,6 +69,10 @@ namespace watcher_monitoring.Migrations .HasMaxLength(50) .HasColumnType("TEXT"); + b.Property("State") + .IsRequired() + .HasColumnType("TEXT"); + b.HasKey("Id"); b.ToTable("Containers"); @@ -99,9 +103,6 @@ namespace watcher_monitoring.Migrations .IsRequired() .HasColumnType("TEXT"); - b.Property("IsOnline") - .HasColumnType("INTEGER"); - b.Property("IsVerified") .HasColumnType("INTEGER"); @@ -115,6 +116,10 @@ namespace watcher_monitoring.Migrations b.Property("RamSize") .HasColumnType("REAL"); + b.Property("State") + .IsRequired() + .HasColumnType("TEXT"); + b.HasKey("Id"); b.ToTable("Servers"); diff --git a/watcher-monitoring/Models/Container.cs b/watcher-monitoring/Models/Container.cs index 031df47..38e4394 100644 --- a/watcher-monitoring/Models/Container.cs +++ b/watcher-monitoring/Models/Container.cs @@ -13,4 +13,6 @@ public class Container [StringLength(50)] public required string ContainerName { get; set; } = null!; + public required string State { get; set; } + } diff --git a/watcher-monitoring/Models/Server.cs b/watcher-monitoring/Models/Server.cs index b12e869..0ecb670 100644 --- a/watcher-monitoring/Models/Server.cs +++ b/watcher-monitoring/Models/Server.cs @@ -27,7 +27,7 @@ public class Server // Metadata public DateTime CreatedAt { get; set; } = DateTime.UtcNow; - public bool IsOnline { get; set; } = false; + public string State { get; set; } public DateTime LastSeen { get; set; } diff --git a/watcher-monitoring/Views/Home/Index.cshtml b/watcher-monitoring/Views/Home/Index.cshtml index acd2dea..784a91b 100644 --- a/watcher-monitoring/Views/Home/Index.cshtml +++ b/watcher-monitoring/Views/Home/Index.cshtml @@ -14,16 +14,20 @@
-
-
Total Servers
-
@Model.serversCount
-
+ +
+
Total Servers
+
@Model.serversCount
+
+
-
-
Online
-
@Model.serversOnline
-
+ +
+
Online
+
@Model.serversOnline
+
+
@@ -42,21 +46,24 @@
-

Monitored Servers

+

Server Issues

    @if (Model.servers != null && Model.servers.Count > 0) { @foreach (var server in Model.servers) { -
  • + @if (server.State != "online") + { +
  • @server.Name @server.IPAddress
    - - @(server.IsOnline ? "Online" : "Offline") + + @(server.State=="warning" ? "Warning" : "Offline")
  • + } } } else