8 Commits

Author SHA1 Message Date
05e5a209da logs eingefügt
All checks were successful
Gitea CI/CD / dotnet-build-and-test (push) Successful in 10m40s
Gitea CI/CD / Set Tag Name (push) Successful in 5s
Gitea CI/CD / docker-build-and-push (push) Successful in 12m32s
Gitea CI/CD / Create Tag (push) Successful in 5s
2026-01-08 14:54:26 +01:00
0b88292a85 Delete Calls for Containers and Servers 2026-01-08 12:48:26 +01:00
5bae9328d9 Added Containers to Database 2026-01-08 12:29:03 +01:00
3a872980da removed registration key 2026-01-08 12:15:02 +01:00
8cda82111d Server gets created at registration now 2026-01-08 12:13:49 +01:00
6e17dcb270 removed old sample data 2026-01-08 12:08:13 +01:00
a1f9a2008f Fixed RegistrationDto 2026-01-08 12:07:59 +01:00
31da3d14a3 Pipeline update for act runner cache and registration endpoint name change
All checks were successful
Gitea CI/CD / dotnet-build-and-test (push) Successful in 10m40s
Gitea CI/CD / Set Tag Name (push) Successful in 5s
Gitea CI/CD / docker-build-and-push (push) Successful in 13m9s
Gitea CI/CD / Create Tag (push) Successful in 5s
2026-01-08 08:58:57 +01:00
10 changed files with 364 additions and 34 deletions

View File

@@ -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 linux/amd64 \ mv /tmp/.buildx-cache-new /tmp/.buildx-cache
--build-arg VERSION=${{ needs.set-tag.outputs.tag_name }} \
-t ${{ env.REGISTRY_URL }}/triggermeelmo/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.set-tag.outputs.tag_name }} \
--push .
tag: tag:
name: Create Tag name: Create Tag

View File

@@ -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();
}
}
}

View File

@@ -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);

View File

@@ -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 });
} }
try {
Server server = new Server
{
Name = "test",
IPAddress = dto.IpAddress
};
_context.Servers.Add(server);
await _context.SaveChangesAsync();
return Ok(); 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();
}
} }

View File

@@ -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; }
} }

View 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
}
}
}

View File

@@ -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");
}
}
}

View File

@@ -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")

View 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!;
}

View File

@@ -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; }
} }