Compare commits
71 Commits
main
...
a6d992c874
| Author | SHA1 | Date | |
|---|---|---|---|
| a6d992c874 | |||
| 8475083897 | |||
| f1287314f4 | |||
| e1684d4484 | |||
| f113147972 | |||
| 7c85e338fa | |||
| c01401eb07 | |||
| 7c06f7ee06 | |||
| 6eed3c764e | |||
| f207440ae6 | |||
| ef187f8750 | |||
| 570b5abfa0 | |||
| 8f938f999e | |||
| 2249d1a776 | |||
| 37de21f06b | |||
| b9d5ade0f1 | |||
| 921b4a9664 | |||
| 0e9555e3f7 | |||
| 19c7aaaca1 | |||
| 068c67d0d9 | |||
| 4c6635f989 | |||
| 98080df509 | |||
| 286f72eac7 | |||
| d49977815d | |||
| b012693c21 | |||
| e385eb94f4 | |||
| 285ff89cb0 | |||
| fe45d901e4 | |||
| ba6e201adc | |||
| 5867cfc3e1 | |||
| 8771e1ee02 | |||
| 2be4331a6e | |||
| 98754be109 | |||
| 9ee2750534 | |||
| 9920c94a8b | |||
| b7bc477d2e | |||
| ab11665665 | |||
| 37468b6785 | |||
| 471767c4ed | |||
| 596baba5ef | |||
| 12390031f9 | |||
| daed8c1462 | |||
| 7e5e295590 | |||
| cb91ca3159 | |||
| 340f92ed04 | |||
| 2169b3d45f | |||
| 27792ff7f4 | |||
| 9a59e10b0c | |||
| 7860d7e0f7 | |||
| 2334287437 | |||
| d68022d831 | |||
| b3b97d4c09 | |||
| db45872908 | |||
| 8e0dcc34e7 | |||
| 015cdcb202 | |||
| 2841752870 | |||
| 8ffb220634 | |||
| 120374ebe1 | |||
| 55aa9f546a | |||
| 0974c1d7dd | |||
| 0e72287c6b | |||
| 3918425ef9 | |||
| ec13a51575 | |||
| b8626cb8ea | |||
| 281e9c686b | |||
| 69dd73a079 | |||
| 2e9d41fe60 | |||
| 7e75f3e49e | |||
| 8e362f7271 | |||
| 52c4243efc | |||
| 6248fad147 |
146
.gitea/workflows/build.yml
Normal file
146
.gitea/workflows/build.yml
Normal file
@@ -0,0 +1,146 @@
|
||||
name: Gitea CI/CD
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [ "development", "main", "staging" ]
|
||||
tags: [ "v*.*.*" ]
|
||||
|
||||
env:
|
||||
DOTNET_VERSION: '8.0.x'
|
||||
DOCKER_IMAGE_NAME: watcher-server
|
||||
REGISTRY_URL: git.triggermeelmo.com
|
||||
DOCKER_PLATFORMS: 'linux/amd64,linux/arm64'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
dotnet-build-and-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET SDK
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: ${{ env.DOTNET_VERSION }}
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build
|
||||
run: dotnet build --configuration Release --no-restore
|
||||
|
||||
- name: Test
|
||||
run: dotnet test --no-build --verbosity normal
|
||||
continue-on-error: true
|
||||
|
||||
- name: Publish
|
||||
run: dotnet publish -c Release -o out
|
||||
|
||||
set-tag:
|
||||
name: Set Tag Name
|
||||
needs: [dotnet-build-and-test]
|
||||
#if: ${{ !failure() && !cancelled() && github.event_name != 'pull_request' }}
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
tag_name: ${{ steps.set_tag.outputs.tag_name }}
|
||||
should_tag: ${{ steps.set_tag.outputs.should_tag }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Determine next semantic version tag
|
||||
id: set_tag
|
||||
run: |
|
||||
git fetch --tags
|
||||
|
||||
# Find latest tag matching vX.Y.Z
|
||||
latest_tag=$(git tag --list 'v*.*.*' --sort=-v:refname | head -n 1)
|
||||
if [[ -z "$latest_tag" ]]; then
|
||||
major=0
|
||||
minor=0
|
||||
patch=0
|
||||
else
|
||||
version="${latest_tag#v}"
|
||||
IFS='.' read -r major minor patch <<< "$version"
|
||||
fi
|
||||
|
||||
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
|
||||
major=$((major + 1))
|
||||
minor=0
|
||||
patch=0
|
||||
new_tag="v${major}.${minor}.${patch}"
|
||||
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
||||
echo "should_tag=true" >> $GITHUB_OUTPUT
|
||||
echo "Creating new major version tag: ${new_tag}"
|
||||
|
||||
elif [[ "${GITHUB_REF}" == "refs/heads/development" ]]; then
|
||||
minor=$((minor + 1))
|
||||
patch=0
|
||||
new_tag="v${major}.${minor}.${patch}"
|
||||
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
||||
echo "should_tag=true" >> $GITHUB_OUTPUT
|
||||
echo "Creating new minor version tag: ${new_tag}"
|
||||
|
||||
elif [[ "${GITHUB_REF}" == "refs/heads/staging" ]]; then
|
||||
patch=$((patch + 1))
|
||||
new_tag="v${major}.${minor}.${patch}"
|
||||
echo "tag_name=${new_tag}" >> $GITHUB_OUTPUT
|
||||
echo "should_tag=true" >> $GITHUB_OUTPUT
|
||||
echo "Creating new patch version tag: ${new_tag}"
|
||||
fi
|
||||
|
||||
docker-build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [dotnet-build-and-test, set-tag]
|
||||
if: |
|
||||
needs.set-tag.outputs.should_tag == 'true' &&
|
||||
github.event_name != 'pull_request'
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY_URL}}
|
||||
username: ${{ secrets.AUTOMATION_USERNAME }}
|
||||
password: ${{ secrets.AUTOMATION_PASSWORD }}
|
||||
|
||||
- name: Build and Push Multi-Arch Docker Image
|
||||
run: |
|
||||
docker buildx build \
|
||||
--platform ${{ env.DOCKER_PLATFORMS }} \
|
||||
-t ${{ env.REGISTRY_URL }}/watcher/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.set-tag.outputs.tag_name }} \
|
||||
--push .
|
||||
|
||||
tag:
|
||||
name: Create Tag
|
||||
needs: [docker-build-and-push, set-tag]
|
||||
if: |
|
||||
needs.set-tag.outputs.should_tag == 'true' &&
|
||||
github.event_name != 'pull_request'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Git user
|
||||
run: |
|
||||
git config user.name "GitHub Actions"
|
||||
git config user.email "actions@github.com"
|
||||
|
||||
- name: Create and push tag
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
echo "Creating new tag: ${{ needs.set-tag.outputs.tag_name }}"
|
||||
git tag ${{ needs.set-tag.outputs.tag_name }}
|
||||
git push origin ${{ needs.set-tag.outputs.tag_name }}
|
||||
@@ -1,63 +0,0 @@
|
||||
name: Development Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- development
|
||||
|
||||
env:
|
||||
DOTNET_VERSION: '8.0.x'
|
||||
DOCKER_IMAGE_NAME: 'watcher-server'
|
||||
REGISTRY_URL: 'git.triggermeelmo.com/watcher'
|
||||
DOCKER_PLATFORMS: 'linux/amd64,linux/arm64'
|
||||
RUNNER_TOOL_CACHE: /toolcache # Runner Tool Cache
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup .NET SDK
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: ${{ env.DOTNET_VERSION }}
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build
|
||||
run: dotnet build --configuration Release --no-restore
|
||||
|
||||
- name: Test
|
||||
run: dotnet test --no-build --verbosity normal
|
||||
continue-on-error: true
|
||||
|
||||
- name: Publish
|
||||
run: dotnet publish -c Release -o out
|
||||
|
||||
docker-build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-and-test
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY_URL}}
|
||||
username: ${{ secrets.AUTOMATION_USERNAME }}
|
||||
password: ${{ secrets.AUTOMATION_PASSWORD }}
|
||||
|
||||
- name: Build and Push Multi-Arch Docker Image
|
||||
run: |
|
||||
docker buildx build \
|
||||
--platform ${{ env.DOCKER_PLATFORMS }} \
|
||||
-t ${{ env.REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:development \
|
||||
-t ${{ env.REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.sha }} \
|
||||
--push .
|
||||
@@ -1,62 +0,0 @@
|
||||
name: Release Build and Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
DOTNET_VERSION: '8.0.x'
|
||||
DOCKER_IMAGE_NAME: 'watcher-server'
|
||||
REGISTRY_URL: 'git.triggermeelmo.com/watcher'
|
||||
DOCKER_PLATFORMS: 'linux/amd64,linux/arm64'
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup .NET SDK
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: ${{ env.DOTNET_VERSION }}
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build
|
||||
run: dotnet build --configuration Release --no-restore
|
||||
|
||||
- name: Test
|
||||
run: dotnet test --no-build --verbosity normal
|
||||
continue-on-error: true
|
||||
|
||||
- name: Publish
|
||||
run: dotnet publish -c Release -o out
|
||||
|
||||
docker-build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-and-test
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to Gitea Container Registry
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: git.triggermeelmo.com
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Build and Push Multi-Arch Docker Image
|
||||
run: |
|
||||
docker buildx build \
|
||||
--platform ${{ env.DOCKER_PLATFORMS }} \
|
||||
-t ${{ env.REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:v0.1.0 \
|
||||
-t ${{ env.REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:${{ github.sha }} \
|
||||
--push .
|
||||
27
Tests/servicediscovery.py
Normal file
27
Tests/servicediscovery.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import json
|
||||
import urllib.request
|
||||
|
||||
url = "http://localhost:5000/monitoring/service-discovery"
|
||||
payload = {
|
||||
"server_id": 7,
|
||||
"containers": ["{\"id\":\"6621c5b67c25\",\"image\":\"git.triggermeelmo.com/donpat1to/watcher-agent:v0.1.26\",\"name\":\"watcher-agent\"}",
|
||||
"{\"id\":\"b8c86fb260bd\",\"image\":\"git.triggermeelmo.com/watcher/watcher-server:v0.1.10\",\"name\":\"watcher\"}"]
|
||||
}
|
||||
|
||||
data = json.dumps(payload).encode("utf-8")
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
data=data,
|
||||
headers={"Content-Type": "application/json"},
|
||||
method="POST"
|
||||
)
|
||||
|
||||
try:
|
||||
with urllib.request.urlopen(req) as response:
|
||||
resp_data = response.read().decode("utf-8")
|
||||
print("Status Code:", response.status)
|
||||
print("Response:", resp_data)
|
||||
except Exception as e:
|
||||
print("Fehler beim Senden der Request:", e)
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
// Local Namespaces
|
||||
using Watcher.Data;
|
||||
using Watcher.Models;
|
||||
using Watcher.ViewModels;
|
||||
using Watcher.Services;
|
||||
|
||||
namespace Watcher.Controllers
|
||||
{
|
||||
@@ -18,11 +18,16 @@ namespace Watcher.Controllers
|
||||
// Logging einbinden
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
// Daten der Backgroundchecks abrufen
|
||||
private IDashboardStore _DashboardStore;
|
||||
|
||||
// HomeController Constructor
|
||||
public HomeController(AppDbContext context, ILogger<HomeController> logger)
|
||||
public HomeController(AppDbContext context, ILogger<HomeController> logger, IDashboardStore dashboardStore)
|
||||
{
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
_DashboardStore = dashboardStore;
|
||||
|
||||
}
|
||||
|
||||
// Dashboard unter /home/index
|
||||
@@ -52,9 +57,11 @@ namespace Watcher.Controllers
|
||||
.ToListAsync(),
|
||||
Containers = await _context.Containers
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync()
|
||||
.ToListAsync(),
|
||||
NetworkStatus = _DashboardStore.NetworkStatus,
|
||||
DatabaseStatus = _DashboardStore.DatabaseStatus
|
||||
};
|
||||
|
||||
//ViewBag.NetworkConnection = _NetworkCheckStore.NetworkStatus;
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
@@ -82,11 +89,18 @@ namespace Watcher.Controllers
|
||||
.ToListAsync(),
|
||||
Containers = await _context.Containers
|
||||
.OrderBy(s => s.Name)
|
||||
.ToListAsync()
|
||||
.ToListAsync(),
|
||||
NetworkStatus = _DashboardStore.NetworkStatus,
|
||||
DatabaseStatus = _DashboardStore.DatabaseStatus
|
||||
};
|
||||
|
||||
return PartialView("_DashboardStats", model);
|
||||
}
|
||||
|
||||
public String ReturnNetworkStatus()
|
||||
{
|
||||
return "OK";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Watcher.Data;
|
||||
@@ -11,7 +16,7 @@ using Watcher.ViewModels;
|
||||
|
||||
namespace Watcher.Controllers;
|
||||
|
||||
public class RegistrationDto
|
||||
public class HardwareDto
|
||||
{
|
||||
// Server Identity
|
||||
[Required]
|
||||
@@ -77,6 +82,11 @@ public class MetricDto
|
||||
public double NET_Out { get; set; } // Bytes/s
|
||||
}
|
||||
|
||||
public class ServiceDto
|
||||
{
|
||||
public required int server_id { get; set; } // Vom Watcher-Server zugewiesene ID des Hosts
|
||||
public required List<Container> containers { get; set; }
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
@@ -93,9 +103,9 @@ public class MonitoringController : Controller
|
||||
}
|
||||
|
||||
|
||||
// Endpoint, an dem sich neue Agents registrieren
|
||||
[HttpPost("register-agent-by-id")]
|
||||
public async Task<IActionResult> Register([FromBody] RegistrationDto dto)
|
||||
// Endpoint, an den der Agent seine Hardwareinformationen schickt
|
||||
[HttpPost("hardware-info")]
|
||||
public async Task<IActionResult> Register([FromBody] HardwareDto dto)
|
||||
{
|
||||
// Gültigkeit des Payloads prüfen
|
||||
if (!ModelState.IsValid)
|
||||
@@ -128,13 +138,12 @@ public class MonitoringController : Controller
|
||||
_logger.LogInformation("Agent für '{server}' erfolgreich registriert.", server.Name);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
_logger.LogError("Kein Server für Registrierung gefunden");
|
||||
return NotFound("No Matching Server found.");
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("server-id-by-ip")]
|
||||
// Endpoint, an dem sich ein Agent initial registriert
|
||||
[HttpGet("register")]
|
||||
public async Task<IActionResult> GetServerIdByIp([FromQuery] string IpAddress)
|
||||
{
|
||||
var server = await _context.Servers
|
||||
@@ -215,9 +224,160 @@ public class MonitoringController : Controller
|
||||
|
||||
}
|
||||
|
||||
// Endpoint, an dem Agents Ihre laufenden Services registrieren
|
||||
[HttpPost("service-discovery")]
|
||||
public async Task<IActionResult> ServiceDetection([FromBody] ServiceDto dto)
|
||||
{
|
||||
// Gültigkeit des Payloads prüfen
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
var errors = ModelState.Values
|
||||
.SelectMany(v => v.Errors)
|
||||
.Select(e => e.ErrorMessage)
|
||||
.ToList();
|
||||
|
||||
_logger.LogError("Invalid ServiceDetection-Payload.");
|
||||
return BadRequest(new { error = "Invalid Payload", details = errors });
|
||||
}
|
||||
|
||||
// Json zu was brauchbarem machen
|
||||
//string containersJson = await dto.containers.ReadAsStringAsync();
|
||||
//List<Container> newContainers = JsonSerializer.Deserialize<List<Container>>(containersJson)?? new List<Container>();;
|
||||
|
||||
List<Container> newContainers = new List<Container>();
|
||||
|
||||
foreach (String s in dto.containers)
|
||||
{
|
||||
// JSON zu einem JsonDocument parsen
|
||||
using JsonDocument doc = JsonDocument.Parse(s);
|
||||
JsonElement root = doc.RootElement;
|
||||
|
||||
// Einzelne Werte extrahieren
|
||||
string id = root.GetProperty("id").GetString() ?? "";
|
||||
string image = root.GetProperty("image").GetString() ?? "";
|
||||
string name = root.GetProperty("name").GetString() ?? "";
|
||||
|
||||
Container newContainer = new Container
|
||||
{
|
||||
ServerId = dto.server_id,
|
||||
ContainerId = id,
|
||||
Image = image,
|
||||
Name = name,
|
||||
};
|
||||
|
||||
|
||||
newContainers.Add(newContainer);
|
||||
}
|
||||
|
||||
foreach (Container c in newContainers)
|
||||
{
|
||||
c.ServerId = dto.server_id;
|
||||
// Debug Logs
|
||||
// TODO entfernen wenn fertig getestet
|
||||
Console.WriteLine("---------");
|
||||
Console.WriteLine("ServerId: " + c.ServerId);
|
||||
Console.WriteLine("ContainerId: " + c.ContainerId);
|
||||
Console.WriteLine("Name: " + c.Name);
|
||||
Console.WriteLine("Image: " + c.Image);
|
||||
Console.WriteLine("---------");
|
||||
|
||||
}
|
||||
|
||||
// Container Objekte erstellen
|
||||
//List<Container> newContainers = ParseServiceDiscoveryInput(dto.Server_id, containers);
|
||||
|
||||
// Liste aller Container, die bereits der übergebenen ServerId zugewiesen sind
|
||||
List<Container> existingContainers = _context.Containers
|
||||
.Where(c => c.ServerId == dto.server_id)
|
||||
.ToList();
|
||||
|
||||
|
||||
// Logik, um Container, die mit dem Payload kamen zu verarbeiten
|
||||
foreach (Container c in newContainers)
|
||||
{
|
||||
// Überprüfen, ob ein übergebener Container bereits für den Host registriert ist
|
||||
if (existingContainers.Contains(c))
|
||||
{
|
||||
_logger.LogInformation("Container with id " + c.ContainerId + " already exists.");
|
||||
}
|
||||
// Container auf einen Host/Server registrieren
|
||||
else
|
||||
{
|
||||
// Container in Datenbank einlesen
|
||||
try
|
||||
{
|
||||
_context.Containers.Add(c);
|
||||
await _context.SaveChangesAsync();
|
||||
_logger.LogInformation(c.Name + " added for Host " + c.ServerId);
|
||||
}
|
||||
catch (SqliteException e)
|
||||
{
|
||||
_logger.LogError("Error writing new Containers to Database: " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Logik um abgeschaltene Container aus der Datenbank zu entfernen
|
||||
foreach (Container c in existingContainers)
|
||||
{
|
||||
// Abfrage, ob bereits vorhandener Container im Payload vorhanden war
|
||||
if (!newContainers.Contains(c))
|
||||
{
|
||||
// Container entfernen
|
||||
_context.Containers.Remove(c);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// Metrics für den Container entfernen
|
||||
//Todo
|
||||
|
||||
_logger.LogInformation("Container " + c.Name + " (" + c.Id + ") on Host-Id " + c.ServerId + " was successfully removed from the database.");
|
||||
}
|
||||
}
|
||||
|
||||
return Ok();
|
||||
|
||||
}
|
||||
|
||||
// Endpoint, an den der Agent die Metrics der registrierten Container schickt
|
||||
public async Task<IActionResult> ServiceMetrics([FromBody] ServiceMetricDto dto)
|
||||
{
|
||||
// Gültigkeit des Payloads prüfen
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
var errors = ModelState.Values
|
||||
.SelectMany(v => v.Errors)
|
||||
.Select(e => e.ErrorMessage)
|
||||
.ToList();
|
||||
|
||||
_logger.LogError("Invalid ServiceDetection-Payload.");
|
||||
return BadRequest(new { error = "Invalid Payload", details = errors });
|
||||
}
|
||||
|
||||
// Liste an Metrics aus der dto erstellen
|
||||
List<ContainerMetric> metrics = new List<ContainerMetric>();
|
||||
|
||||
// Metrics in die Datenbank eintragen
|
||||
try
|
||||
{
|
||||
foreach (ContainerMetric m in metrics)
|
||||
{
|
||||
_context.ContainerMetrics.Add(m);
|
||||
await _context.SaveChangesAsync();
|
||||
// _logger.LogInformation(m. + " added for Host " + c.ServerId);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
catch (SqliteException e)
|
||||
{
|
||||
_logger.LogError(e.Message);
|
||||
return StatusCode(500);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
|
||||
}
|
||||
|
||||
// Durchschnittliche Werte Berechnen
|
||||
[HttpGet("median")]
|
||||
public async Task<IActionResult> CalculateMedian(string Metric, int HoursToMonitor, int ServerId)
|
||||
{
|
||||
// Aktuelle Zeit - X Stunden = letzter Wert, der berücksichtigt werden soll
|
||||
@@ -317,6 +477,13 @@ public class MonitoringController : Controller
|
||||
return metric_input;
|
||||
}
|
||||
|
||||
private List<Container> ParseServiceDiscoveryInput(int server_id, List<Container> containers)
|
||||
{
|
||||
List<Container> containerList = new List<Container>();
|
||||
|
||||
// JSON-Objekt auslesen und Container-Objekte erstellen
|
||||
|
||||
|
||||
return containerList;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,8 @@ public class AppDbContext : DbContext
|
||||
|
||||
public DbSet<Tag> Tags { get; set; }
|
||||
|
||||
public DbSet<ContainerMetric> ContainerMetrics { get; set; }
|
||||
|
||||
public DbSet<User> Users { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
|
||||
355
Watcher/Migrations/20251003135555_ContainerUpdate.Designer.cs
generated
Normal file
355
Watcher/Migrations/20251003135555_ContainerUpdate.Designer.cs
generated
Normal file
@@ -0,0 +1,355 @@
|
||||
// <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("20251003135555_ContainerUpdate")]
|
||||
partial class ContainerUpdate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Container", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ContainerId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Image")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ImageId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsRunning")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("TagId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ImageId");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("Containers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Image", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Tag")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("ContainerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Level")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ContainerId");
|
||||
|
||||
b.HasIndex("ServerId");
|
||||
|
||||
b.ToTable("LogEvents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Metric", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("CPU_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Usage")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Vram_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Vram_Usage")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("NET_In")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("NET_Out")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int?>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Metrics");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Server", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("CPU_Load_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Load_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Temp_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Temp_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int>("CpuCores")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("CpuType")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("DISK_Temp_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Temp_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DiskSpace")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("Disk_Usage_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("Disk_Usage_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Load_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Load_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Temp_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Temp_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
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>("RAM_Load_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Load_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RamSize")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int?>("TagId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("Servers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Tag", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("IdentityProvider")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastLogin")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("OIDC_Id")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Container", b =>
|
||||
{
|
||||
b.HasOne("Watcher.Models.Image", null)
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("ImageId");
|
||||
|
||||
b.HasOne("Watcher.Models.Tag", null)
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("TagId");
|
||||
});
|
||||
|
||||
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.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
|
||||
}
|
||||
}
|
||||
}
|
||||
113
Watcher/Migrations/20251003135555_ContainerUpdate.cs
Normal file
113
Watcher/Migrations/20251003135555_ContainerUpdate.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Watcher.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ContainerUpdate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Containers_Servers_HostServerId",
|
||||
table: "Containers");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Containers_HostServerId",
|
||||
table: "Containers");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "CreatedAt",
|
||||
table: "Containers");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ExposedPort",
|
||||
table: "Containers");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Health",
|
||||
table: "Containers");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "HostServerId",
|
||||
table: "Containers");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Status",
|
||||
table: "Containers");
|
||||
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "InternalPort",
|
||||
table: "Containers",
|
||||
newName: "ServerId");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "ContainerId",
|
||||
table: "Containers",
|
||||
type: "TEXT",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ContainerId",
|
||||
table: "Containers");
|
||||
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "ServerId",
|
||||
table: "Containers",
|
||||
newName: "InternalPort");
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "CreatedAt",
|
||||
table: "Containers",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ExposedPort",
|
||||
table: "Containers",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Health",
|
||||
table: "Containers",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "HostServerId",
|
||||
table: "Containers",
|
||||
type: "INTEGER",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Status",
|
||||
table: "Containers",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Containers_HostServerId",
|
||||
table: "Containers",
|
||||
column: "HostServerId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Containers_Servers_HostServerId",
|
||||
table: "Containers",
|
||||
column: "HostServerId",
|
||||
principalTable: "Servers",
|
||||
principalColumn: "Id");
|
||||
}
|
||||
}
|
||||
}
|
||||
355
Watcher/Migrations/20251029105954_container-changed.Designer.cs
generated
Normal file
355
Watcher/Migrations/20251029105954_container-changed.Designer.cs
generated
Normal file
@@ -0,0 +1,355 @@
|
||||
// <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("20251029105954_container-changed")]
|
||||
partial class containerchanged
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Container", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ContainerId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Image")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ImageId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsRunning")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("TagId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ImageId");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("Containers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Image", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Tag")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("ContainerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Level")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ContainerId");
|
||||
|
||||
b.HasIndex("ServerId");
|
||||
|
||||
b.ToTable("LogEvents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Metric", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("CPU_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Usage")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Vram_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Vram_Usage")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("NET_In")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("NET_Out")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int?>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Metrics");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Server", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("CPU_Load_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Load_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Temp_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Temp_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int>("CpuCores")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("CpuType")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("DISK_Temp_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Temp_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DiskSpace")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("Disk_Usage_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("Disk_Usage_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Load_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Load_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Temp_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Temp_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
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>("RAM_Load_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Load_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RamSize")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int?>("TagId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("Servers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Tag", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("IdentityProvider")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastLogin")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("OIDC_Id")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Container", b =>
|
||||
{
|
||||
b.HasOne("Watcher.Models.Image", null)
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("ImageId");
|
||||
|
||||
b.HasOne("Watcher.Models.Tag", null)
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("TagId");
|
||||
});
|
||||
|
||||
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.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
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Watcher/Migrations/20251029105954_container-changed.cs
Normal file
22
Watcher/Migrations/20251029105954_container-changed.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Watcher.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class containerchanged : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
355
Watcher/Migrations/20251029125404_ContainerMetrics-Added.Designer.cs
generated
Normal file
355
Watcher/Migrations/20251029125404_ContainerMetrics-Added.Designer.cs
generated
Normal file
@@ -0,0 +1,355 @@
|
||||
// <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("20251029125404_ContainerMetrics-Added")]
|
||||
partial class ContainerMetricsAdded
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Container", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ContainerId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Image")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ImageId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsRunning")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("TagId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ImageId");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("Containers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Image", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Tag")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("ContainerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Level")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ContainerId");
|
||||
|
||||
b.HasIndex("ServerId");
|
||||
|
||||
b.ToTable("LogEvents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Metric", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("CPU_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Usage")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Vram_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Vram_Usage")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("NET_In")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("NET_Out")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int?>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Metrics");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Server", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("CPU_Load_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Load_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Temp_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Temp_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int>("CpuCores")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("CpuType")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("DISK_Temp_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Temp_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DiskSpace")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("Disk_Usage_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("Disk_Usage_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Load_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Load_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Temp_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Temp_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
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>("RAM_Load_Critical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Load_Warning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RamSize")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int?>("TagId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("Servers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Tag", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("IdentityProvider")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastLogin")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("OIDC_Id")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Container", b =>
|
||||
{
|
||||
b.HasOne("Watcher.Models.Image", null)
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("ImageId");
|
||||
|
||||
b.HasOne("Watcher.Models.Tag", null)
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("TagId");
|
||||
});
|
||||
|
||||
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.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
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Watcher/Migrations/20251029125404_ContainerMetrics-Added.cs
Normal file
22
Watcher/Migrations/20251029125404_ContainerMetrics-Added.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Watcher.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ContainerMetricsAdded : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,45 +23,29 @@ namespace Watcher.Migrations
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
b.Property<string>("ContainerId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("ExposedPort")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Health")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("HostServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Image")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ImageId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("InternalPort")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsRunning")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
b.Property<int>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("TagId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("HostServerId");
|
||||
|
||||
b.HasIndex("ImageId");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
@@ -320,10 +304,6 @@ namespace Watcher.Migrations
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Container", b =>
|
||||
{
|
||||
b.HasOne("Watcher.Models.Server", "HostServer")
|
||||
.WithMany()
|
||||
.HasForeignKey("HostServerId");
|
||||
|
||||
b.HasOne("Watcher.Models.Image", null)
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("ImageId");
|
||||
@@ -331,8 +311,6 @@ namespace Watcher.Migrations
|
||||
b.HasOne("Watcher.Models.Tag", null)
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("TagId");
|
||||
|
||||
b.Navigation("HostServer");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
|
||||
|
||||
@@ -1,25 +1,23 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Watcher.Models;
|
||||
|
||||
public class Container
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
// Container Details
|
||||
public string? Name { get; set; }
|
||||
public int ServerId { get; set; }
|
||||
|
||||
public int ExposedPort { get; set; }
|
||||
public String? ContainerId { get; set; }
|
||||
|
||||
public int InternalPort { get; set; }
|
||||
[JsonPropertyName("image")]
|
||||
public String? Image { get; set; }
|
||||
|
||||
public string Status { get; set; } = string.Empty;
|
||||
|
||||
public string Health { get; set; } = string.Empty;
|
||||
|
||||
public string? Image { get; set; }
|
||||
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
[JsonPropertyName("name")]
|
||||
public String? Name { get; set; }
|
||||
|
||||
// keine Variable, die vom Agent übergeben wird. Ein container ist immer Running, die Variable dient nur für die Übersicht
|
||||
// auf dem Dashboard.
|
||||
public Boolean IsRunning { get; set; } = true;
|
||||
|
||||
public Server? HostServer { get; set; }
|
||||
}
|
||||
|
||||
24
Watcher/Models/ContainerMetric.cs
Normal file
24
Watcher/Models/ContainerMetric.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace Watcher.Models;
|
||||
|
||||
public class ContainerMetric
|
||||
{
|
||||
// Metric Metadata
|
||||
public int Id { get; set; }
|
||||
public DateTime Timestamp { get; set; }
|
||||
|
||||
|
||||
// Zuordnung zu einem Container -- Foreign Key
|
||||
public int? ContainerId { get; set; }
|
||||
|
||||
|
||||
// CPU-Daten
|
||||
public double CPU_Load { get; set; } = 0.0; // %
|
||||
|
||||
public double CPU_Temp { get; set; } = 0.0; // deg C
|
||||
|
||||
// RAM-Daten
|
||||
public double RAM_Size { get; set; } = 0.0; // GB
|
||||
|
||||
public double RAM_Load { get; set; } = 0.0; // %
|
||||
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
using Serilog;
|
||||
|
||||
using Watcher.Data;
|
||||
using Watcher.Models;
|
||||
using Watcher.Services;
|
||||
//using Watcher.Services;
|
||||
//using Watcher.Workers;
|
||||
|
||||
@@ -15,7 +17,7 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
// Serilog konfigurieren – nur Logs, die nicht von Microsoft stammen
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Information()
|
||||
.MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning) // <--
|
||||
.MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.File(
|
||||
"logs/watcher-.log",
|
||||
@@ -33,6 +35,19 @@ builder.Services.AddControllersWithViews();
|
||||
// HttpContentAccessor
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
// Storage Singleton
|
||||
builder.Services.AddSingleton<IDashboardStore, DashboardStore>();
|
||||
builder.Services.AddSingleton<ISystemStore, SystemStore>();
|
||||
|
||||
// Background Services
|
||||
builder.Services.AddHostedService<NetworkCheck>();
|
||||
builder.Services.AddHostedService<DatabaseCheck>();
|
||||
|
||||
// Swagger API-Dokumentation
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Watcher-Server API", Version = "v1" });
|
||||
});
|
||||
|
||||
// ---------- Konfiguration ----------
|
||||
DotNetEnv.Env.Load();
|
||||
@@ -196,19 +211,27 @@ using (var scope = app.Services.CreateScope())
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
// 🔹 Swagger aktivieren
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Watcher-Server API v1");
|
||||
options.RoutePrefix = "api/v1/swagger";
|
||||
});
|
||||
|
||||
// 🔹 Authentifizierung & Autorisierung
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
// 🔹 MVC-Routing
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}"
|
||||
|
||||
8
Watcher/Services/DashboardStore.cs
Normal file
8
Watcher/Services/DashboardStore.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Watcher.Services;
|
||||
|
||||
public class DashboardStore : IDashboardStore
|
||||
{
|
||||
public String? NetworkStatus { get; set; }
|
||||
|
||||
public String? DatabaseStatus { get; set; }
|
||||
}
|
||||
67
Watcher/Services/DatabaseCheck.cs
Normal file
67
Watcher/Services/DatabaseCheck.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Microsoft.Data.Sqlite;
|
||||
|
||||
namespace Watcher.Services;
|
||||
|
||||
public class DatabaseCheck : BackgroundService
|
||||
{
|
||||
private readonly ILogger<DatabaseCheck> _logger;
|
||||
|
||||
private IDashboardStore _dashboardStore;
|
||||
|
||||
public DatabaseCheck(ILogger<DatabaseCheck> logger, IDashboardStore dashboardStore)
|
||||
{
|
||||
_logger = logger;
|
||||
_dashboardStore = dashboardStore;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
var timer = new PeriodicTimer(TimeSpan.FromSeconds(30));
|
||||
|
||||
while (await timer.WaitForNextTickAsync(stoppingToken))
|
||||
{
|
||||
// Hintergrundprozess abwarten
|
||||
await checkDatabaseIntegrity();
|
||||
// 5 Sekdunden Offset
|
||||
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
|
||||
}
|
||||
}
|
||||
|
||||
// String sqliteConnectionString als Argument übergeben
|
||||
public Task checkDatabaseIntegrity()
|
||||
{
|
||||
using var conn = new SqliteConnection("Data Source=./persistence/watcher.db");
|
||||
_logger.LogInformation("Sqlite Integrity-Check started...");
|
||||
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using var command = conn.CreateCommand();
|
||||
command.CommandText = """
|
||||
SELECT integrity_check FROM pragma_integrity_check;
|
||||
""";
|
||||
|
||||
using var reader = command.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
string status = reader.GetString(0);
|
||||
_dashboardStore.DatabaseStatus = status;
|
||||
_logger.LogInformation("Sqlite DatabaseIntegrity: ${status}", status);
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
}
|
||||
catch (SqliteException e)
|
||||
{
|
||||
conn.Close();
|
||||
_logger.LogError(e.Message);
|
||||
|
||||
// TODO: LogEvent erstellen
|
||||
}
|
||||
|
||||
_logger.LogInformation("Database Integrity-Check finished.");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
7
Watcher/Services/IDashboardStore.cs
Normal file
7
Watcher/Services/IDashboardStore.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Watcher.Services;
|
||||
|
||||
public interface IDashboardStore
|
||||
{
|
||||
String? NetworkStatus { get; set; }
|
||||
String? DatabaseStatus { get; set; }
|
||||
}
|
||||
9
Watcher/Services/ISystemStore.cs
Normal file
9
Watcher/Services/ISystemStore.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Watcher.Services;
|
||||
|
||||
public interface ISystemStore
|
||||
{
|
||||
Boolean NewVersionAvailable { get; set; }
|
||||
|
||||
Double DatabaseSize { get; set; }
|
||||
|
||||
}
|
||||
59
Watcher/Services/NetworkCheck.cs
Normal file
59
Watcher/Services/NetworkCheck.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace Watcher.Services;
|
||||
public class NetworkCheck : BackgroundService
|
||||
{
|
||||
private readonly ILogger<NetworkCheck> _logger;
|
||||
|
||||
private IDashboardStore _DashboardStore;
|
||||
|
||||
public NetworkCheck(ILogger<NetworkCheck> logger, IDashboardStore DashboardStore)
|
||||
{
|
||||
_logger = logger;
|
||||
_DashboardStore = DashboardStore;
|
||||
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
var timer = new PeriodicTimer(TimeSpan.FromSeconds(30));
|
||||
|
||||
while (await timer.WaitForNextTickAsync(stoppingToken))
|
||||
{
|
||||
// Hintergrundprozess abwarten
|
||||
await checkConnectionAsync();
|
||||
|
||||
// 5 Sekdunden Offset
|
||||
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
|
||||
}
|
||||
}
|
||||
|
||||
public Task checkConnectionAsync()
|
||||
{
|
||||
_logger.LogInformation("Networkcheck started.");
|
||||
|
||||
string host = "8.8.8.8";
|
||||
Ping p = new Ping();
|
||||
|
||||
try
|
||||
{
|
||||
PingReply reply = p.Send(host, 3000);
|
||||
if (reply.Status == IPStatus.Success)
|
||||
{
|
||||
_DashboardStore.NetworkStatus = "online";
|
||||
_logger.LogInformation("Ping successfull. Watcher is online.");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
_DashboardStore.NetworkStatus = "offline";
|
||||
_logger.LogError("Ping failed. Watcher appears to have no network connection.");
|
||||
|
||||
// LogEvent erstellen
|
||||
}
|
||||
|
||||
_logger.LogInformation("Networkcheck finished.");
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
42
Watcher/Services/SystemMangement.cs
Normal file
42
Watcher/Services/SystemMangement.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Net.Http;
|
||||
|
||||
namespace Watcher.Services;
|
||||
|
||||
public class SystemManagement : BackgroundService
|
||||
{
|
||||
private readonly ILogger<NetworkCheck> _logger;
|
||||
|
||||
private ISystemStore _SystemStore;
|
||||
|
||||
public SystemManagement(ILogger<NetworkCheck> logger, ISystemStore SystemStore)
|
||||
{
|
||||
_logger = logger;
|
||||
_SystemStore = SystemStore;
|
||||
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
// Todo: Umstellen auf einmal alle 24h
|
||||
var timer = new PeriodicTimer(TimeSpan.FromSeconds(30));
|
||||
|
||||
while (await timer.WaitForNextTickAsync(stoppingToken))
|
||||
{
|
||||
// Hintergrundprozess abwarten
|
||||
await checkForNewDockerImageVersion();
|
||||
|
||||
// 5 Sekdunden Offset
|
||||
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
|
||||
}
|
||||
}
|
||||
|
||||
public Task checkForNewDockerImageVersion()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task createDailySqliteBackup()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
9
Watcher/Services/SystemStore.cs
Normal file
9
Watcher/Services/SystemStore.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Watcher.Services;
|
||||
|
||||
public class SystemStore: ISystemStore
|
||||
{
|
||||
public Boolean NewVersionAvailable { get; set; }
|
||||
|
||||
public Double DatabaseSize { get; set; }
|
||||
|
||||
}
|
||||
@@ -14,5 +14,8 @@ namespace Watcher.ViewModels
|
||||
public List<LogEvent> RecentEvents { get; set; } = new();
|
||||
public List<Container> Containers { get; set; } = new();
|
||||
|
||||
public String? NetworkStatus { get; set; } = "?";
|
||||
public String? DatabaseStatus { get; set; } = "?";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,27 +10,24 @@
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
<div >
|
||||
<!-- TODO: Später auf > 0 ändern! -->
|
||||
<table class="ServiceList">
|
||||
<!-- foreach (var container in Model.Containers)-->
|
||||
<tr>
|
||||
<th>Service</th>
|
||||
<th>HostServer</th>
|
||||
<th>Status</th>
|
||||
<th>SSL/TLS</th>
|
||||
<th>Proxy</th>
|
||||
<th>Deployment</th>
|
||||
<th>Container-ID</th>
|
||||
<th>Name</th>
|
||||
<th>Image</th>
|
||||
<th>Host-ID</th>
|
||||
<th>Aktionen</th>
|
||||
|
||||
</tr>
|
||||
@for (int i = 0; i < 3; i++)
|
||||
@foreach (Container container in Model.Containers)
|
||||
{
|
||||
<tr class="ServiceRow">
|
||||
<td>test</td>
|
||||
<td><a class="ServiceEntry" href="/Server/Details/7">test</a></td>
|
||||
<td>Online</td>
|
||||
<td>true</td>
|
||||
<td>true</td>
|
||||
<td>Docker</td>
|
||||
<td>@container.ContainerId</td>
|
||||
<td>@container.Name</td>
|
||||
<td>@container.Image</td>
|
||||
<!-- TODO: Link Hardcoded -->
|
||||
<td><a class="ServiceEntry" href="/Server/Details/2">@container.ServerId</a></td>
|
||||
<td>nicht verfügbar</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@using Microsoft.IdentityModel.Tokens
|
||||
@model Watcher.ViewModels.DashboardViewModel
|
||||
|
||||
@{
|
||||
@@ -57,18 +58,54 @@
|
||||
<div class="card-body">
|
||||
<h5 class="fw-bold mb-3"><i class="bi bi-heart-pulse me-2 text-danger"></i>Systemstatus</h5>
|
||||
|
||||
@if (!Model.NetworkStatus.IsNullOrEmpty())
|
||||
{
|
||||
@if (Model.NetworkStatus == "online")
|
||||
{
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<span>Netzwerk</span>
|
||||
<span class="badge bg-success">OK</span>
|
||||
<span class="badge bg-success">@Model.NetworkStatus</span>
|
||||
</div>
|
||||
<div class="progress mb-3" style="height: 6px;">
|
||||
<div class="progress-bar bg-success w-100"></div>
|
||||
</div>
|
||||
} else if (Model.NetworkStatus == "offline")
|
||||
{
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<span>Netzwerk</span>
|
||||
<span class="badge bg-danger">@Model.NetworkStatus</span>
|
||||
</div>
|
||||
<div class="progress mb-3" style="height: 6px;">
|
||||
<div class="progress-bar bg-danger w-100"></div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@if (!Model.DatabaseStatus.IsNullOrEmpty())
|
||||
{
|
||||
@if (Model.DatabaseStatus == "ok")
|
||||
{
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<span>Datenbank</span>
|
||||
<span class="badge bg-success">OK</span>
|
||||
<span class="badge bg-success">healthy</span>
|
||||
</div>
|
||||
} else
|
||||
{
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<span>Datenbank</span>
|
||||
<span class="badge bg-danger">unhealthy</span>
|
||||
</div>
|
||||
}
|
||||
} else
|
||||
{
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<span>Datenbank</span>
|
||||
|
||||
<span class="badge bg-primary">Missing Data</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
<div class="progress mb-3" style="height: 6px;">
|
||||
<div class="progress-bar bg-success w-100"></div>
|
||||
</div>
|
||||
@@ -97,34 +134,37 @@
|
||||
</div>
|
||||
|
||||
<!-- Services -->
|
||||
<!-- TODO
|
||||
<div class="col-12 col-lg-6">
|
||||
<div class="card shadow rounded-3 p-4 h-100">
|
||||
<h2 class="h5 fw-semibold mb-3">Services</h2>
|
||||
<ul class="list-group list-group-flush serverlist">
|
||||
@foreach (var service in Model.Containers)
|
||||
@foreach (var container in Model.Containers)
|
||||
{
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<span>@service.Name</span>
|
||||
<span class="badge @(service.Status == "Running" ? "bg-success" : "bg-warning")">
|
||||
@service.Status
|
||||
<span>@container.Name</span>
|
||||
<span class="badge @(container.Name == "Running" ? "bg-success" : "bg-warning")">
|
||||
@container.Name
|
||||
</span>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
|
||||
<!-- Server Liste -->
|
||||
<!-- TODO
|
||||
<div class="col-12 col-lg-6">
|
||||
<div class="card shadow rounded-3 p-4 h-100">
|
||||
<h2 class="h5 fw-semibold mb-3">Server</h2>
|
||||
<ul class="list-group list-group-flush">
|
||||
@foreach (var server in Model.Servers)
|
||||
@foreach (Server server in Model.Servers)
|
||||
{
|
||||
<li class="list-group-item d-flex justify-content-between align-items-center serverlist">
|
||||
<span>@server.Name</span>
|
||||
<span class="badge bg-info" )">
|
||||
CPU: 30.45%
|
||||
CPU:
|
||||
</span>
|
||||
<span class="badge bg-info" )">
|
||||
RAM: 65.09%
|
||||
@@ -136,6 +176,7 @@
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.6" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user