Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 05e5a209da | |||
| 0b88292a85 | |||
| 5bae9328d9 | |||
| 3a872980da | |||
| 8cda82111d | |||
| 6e17dcb270 | |||
| a1f9a2008f |
@@ -1,2 +1,96 @@
|
||||
// Get Methoden um Metrics abzugreifen
|
||||
// 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
|
||||
{
|
||||
private readonly WatcherDbContext _dbContext;
|
||||
private readonly WatcherDbContext _context;
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger, WatcherDbContext dbContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_dbContext = dbContext;
|
||||
_context = dbContext;
|
||||
}
|
||||
|
||||
// Dashboard
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
List<Server> servers = await _dbContext.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 }
|
||||
};
|
||||
List<Server> servers = await _context.Servers.ToListAsync();
|
||||
|
||||
ViewBag.TotalServers = servers.Count;
|
||||
ViewBag.OnlineServers = servers.Count(s => s.IsOnline);
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using watcher_monitoring.Payloads;
|
||||
using watcher_monitoring.Data;
|
||||
using watcher_monitoring.Models;
|
||||
using Microsoft.AspNetCore.Authorization.Infrastructure;
|
||||
|
||||
namespace watcher_monitoring.Controllers;
|
||||
|
||||
@@ -35,7 +36,22 @@ public class MonitoringController : Controller
|
||||
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();
|
||||
} catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
_logger.LogError(ex.Message);
|
||||
return BadRequest();
|
||||
}
|
||||
}
|
||||
|
||||
// Hardware Configuration Endpoint for watcher-agent
|
||||
@@ -56,7 +72,7 @@ public class MonitoringController : Controller
|
||||
try
|
||||
{
|
||||
// Find Server in Database
|
||||
Server server = await _context.Servers.FindAsync(dto.Id);
|
||||
var server = await _context.Servers.FindAsync(dto.Id);
|
||||
|
||||
// Add Hardware Configuration
|
||||
try
|
||||
@@ -67,6 +83,7 @@ public class MonitoringController : Controller
|
||||
server.RamSize = dto.RamSize;
|
||||
// Diskspace fehlt
|
||||
|
||||
_logger.LogInformation("Harware configuration successfull for server {server}", server.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -83,9 +100,24 @@ public class MonitoringController : Controller
|
||||
}
|
||||
|
||||
// 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
|
||||
[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<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
|
||||
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")
|
||||
|
||||
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;
|
||||
|
||||
public class RegistrationDto
|
||||
{
|
||||
public required string IpAddress;
|
||||
public required string Key;
|
||||
[Required]
|
||||
public required string IpAddress { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user