stuff
This commit is contained in:
25
Dockerfile
25
Dockerfile
@@ -1,22 +1,25 @@
|
||||
# Build-Stage
|
||||
# 1. Build-Phase: SDK-Image
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
WORKDIR /app
|
||||
|
||||
# Projektdateien kopieren und Abhängigkeiten wiederherstellen
|
||||
COPY *.csproj ./
|
||||
COPY *.sln .
|
||||
COPY Watcher/*.csproj ./Watcher/
|
||||
RUN dotnet restore
|
||||
|
||||
# Restlichen Code kopieren und veröffentlichen
|
||||
COPY . ./
|
||||
RUN dotnet publish -c Release -o out
|
||||
# Restliche Dateien kopieren und Build ausführen
|
||||
COPY Watcher/. ./Watcher/
|
||||
WORKDIR /app/Watcher
|
||||
RUN dotnet publish -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# Runtime-Stage
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
|
||||
# 2. Laufzeit-Phase: ASP.NET Core Runtime
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0
|
||||
WORKDIR /app
|
||||
COPY --from=build /app/publish .
|
||||
|
||||
COPY --from=build /app/out ./
|
||||
|
||||
EXPOSE 5000
|
||||
EXPOSE 5001
|
||||
# Exponiere Port 80 und 443 (HTTP + HTTPS)
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
# Anwendung starten
|
||||
ENTRYPOINT ["dotnet", "Watcher.dll"]
|
||||
|
43
Watcher/Controllers/HeartbeatController.cs
Normal file
43
Watcher/Controllers/HeartbeatController.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Watcher.Data;
|
||||
using Watcher.Models;
|
||||
using Watcher.ViewModels;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class HeartbeatController : Controller
|
||||
{
|
||||
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public HeartbeatController(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpPost("receive")]
|
||||
public async Task<IActionResult> Receive([FromForm] int serverId)
|
||||
{
|
||||
var server = await _context.Servers.FirstOrDefaultAsync(s => s.Id == serverId);
|
||||
|
||||
// Je nachdem, ob dier Datenbankeintrag für einen neuen Server vorher oder nacher passiert, ist das hier überflüssig
|
||||
if (server != null)
|
||||
{
|
||||
server.LastSeen = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
293
Watcher/Migrations/20250615102649_ServerAnpassung.Designer.cs
generated
Normal file
293
Watcher/Migrations/20250615102649_ServerAnpassung.Designer.cs
generated
Normal file
@@ -0,0 +1,293 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Watcher.Data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Watcher.Migrations
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20250615102649_ServerAnpassung")]
|
||||
partial class ServerAnpassung
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Container", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Hostname")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("ImageId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("IsRunning")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("TagId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ImageId");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("Containers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Image", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Tag")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("ContainerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Level")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("ServerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ContainerId");
|
||||
|
||||
b.HasIndex("ServerId");
|
||||
|
||||
b.ToTable("LogEvents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Metric", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("ContainerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("ServerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<double>("Value")
|
||||
.HasColumnType("double");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ContainerId");
|
||||
|
||||
b.HasIndex("ServerId");
|
||||
|
||||
b.ToTable("Metrics");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Server", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Hostname")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("IPAddress")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<bool>("IsOnline")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<DateTime>("LastSeen")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int?>("TagId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("Servers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Tag", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<DateTime>("LastLogin")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("PocketId")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("PreferredUsername")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Container", b =>
|
||||
{
|
||||
b.HasOne("Watcher.Models.Image", "Image")
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("ImageId");
|
||||
|
||||
b.HasOne("Watcher.Models.Tag", null)
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("TagId");
|
||||
|
||||
b.Navigation("Image");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
|
||||
{
|
||||
b.HasOne("Watcher.Models.Container", "Container")
|
||||
.WithMany()
|
||||
.HasForeignKey("ContainerId");
|
||||
|
||||
b.HasOne("Watcher.Models.Server", "Server")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServerId");
|
||||
|
||||
b.Navigation("Container");
|
||||
|
||||
b.Navigation("Server");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Metric", b =>
|
||||
{
|
||||
b.HasOne("Watcher.Models.Container", "Container")
|
||||
.WithMany()
|
||||
.HasForeignKey("ContainerId");
|
||||
|
||||
b.HasOne("Watcher.Models.Server", "Server")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServerId");
|
||||
|
||||
b.Navigation("Container");
|
||||
|
||||
b.Navigation("Server");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Server", b =>
|
||||
{
|
||||
b.HasOne("Watcher.Models.Tag", null)
|
||||
.WithMany("Servers")
|
||||
.HasForeignKey("TagId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Image", b =>
|
||||
{
|
||||
b.Navigation("Containers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Tag", b =>
|
||||
{
|
||||
b.Navigation("Containers");
|
||||
|
||||
b.Navigation("Servers");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
30
Watcher/Migrations/20250615102649_ServerAnpassung.cs
Normal file
30
Watcher/Migrations/20250615102649_ServerAnpassung.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Watcher.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ServerAnpassung : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "LastSeen",
|
||||
table: "Servers",
|
||||
type: "datetime(6)",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "LastSeen",
|
||||
table: "Servers");
|
||||
}
|
||||
}
|
||||
}
|
@@ -159,6 +159,9 @@ namespace Watcher.Migrations
|
||||
b.Property<bool>("IsOnline")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<DateTime>("LastSeen")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
@@ -18,4 +18,6 @@ public class Server
|
||||
public string Type { get; set; } = "VPS";
|
||||
|
||||
public Boolean IsOnline { get; set; } = false;
|
||||
|
||||
public DateTime LastSeen { get; set; }
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h1 class="text-2xl font-bold">Serverübersicht</h1>
|
||||
<a asp-action="AddServer" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700">
|
||||
<a asp-controller="Server" asp-action="AddServer" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700">
|
||||
+ Server hinzufügen
|
||||
</a>
|
||||
</div>
|
||||
|
@@ -68,10 +68,10 @@
|
||||
<a class="nav-link" href="/Uptime">Uptime</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/Monitoring/Servers">Servers</a>
|
||||
<a class="nav-link" href="/Server/Overview">Servers</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/Container">Container</a>
|
||||
<a class="nav-link" href="/Container/Overview">Container</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@@ -7,7 +7,7 @@
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "server=192.168.178.68;port=3306;database=watcher;user=monitoringuser;password=ssp123;"
|
||||
"DefaultConnection": "server=100.64.0.5;port=3306;database=watcher;user=monitoringuser;password=ssp123;"
|
||||
},
|
||||
"Authentication": {
|
||||
"PocketID": {
|
||||
|
Reference in New Issue
Block a user