feature/service-detection #35
@@ -1,12 +1,11 @@
|
|||||||
import json
|
import json
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
url = "http://localhost:5000/monitoring/ServiceDetection"
|
url = "http://localhost:5000/monitoring/service-discovery"
|
||||||
payload = {
|
payload = {
|
||||||
"server_id": 2,
|
"server_id": 7,
|
||||||
"containers": [
|
"containers": ["{\"id\":\"6621c5b67c25\",\"image\":\"git.triggermeelmo.com/donpat1to/watcher-agent:v0.1.26\",\"name\":\"watcher-agent\"}",
|
||||||
{"ContainerId": "hr1nm432143nkj", "Name": "Name des Containers", "Image": "ghcr.io/test/container:latest"}
|
"{\"id\":\"b8c86fb260bd\",\"image\":\"git.triggermeelmo.com/watcher/watcher-server:v0.1.10\",\"name\":\"watcher\"}"]
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data = json.dumps(payload).encode("utf-8")
|
data = json.dumps(payload).encode("utf-8")
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Net.Http.Json;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
@@ -82,7 +85,7 @@ public class MetricDto
|
|||||||
public class ServiceDto
|
public class ServiceDto
|
||||||
{
|
{
|
||||||
public required int server_id { get; set; } // Vom Watcher-Server zugewiesene ID des Hosts
|
public required int server_id { get; set; } // Vom Watcher-Server zugewiesene ID des Hosts
|
||||||
public required JsonContent containers { get; set; }
|
public required List<String> containers { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
@@ -238,8 +241,33 @@ public class MonitoringController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Json zu was brauchbarem machen
|
// Json zu was brauchbarem machen
|
||||||
string containersJson = await dto.containers.ReadAsStringAsync();
|
//string containersJson = await dto.containers.ReadAsStringAsync();
|
||||||
List<Container> newContainers = JsonSerializer.Deserialize<List<Container>>(containersJson)?? new List<Container>();;
|
//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)
|
foreach (Container c in newContainers)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Watcher.Models;
|
namespace Watcher.Models;
|
||||||
|
|
||||||
public class Container
|
public class Container
|
||||||
{
|
{
|
||||||
|
[JsonPropertyName("id")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
public int ServerId { get; set; }
|
public int ServerId { get; set; }
|
||||||
|
|
||||||
public String? ContainerId { get; set; }
|
public String? ContainerId { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("image")]
|
||||||
public String? Image { get; set; }
|
public String? Image { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("name")]
|
||||||
public String? Name { get; set; }
|
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
|
// keine Variable, die vom Agent übergeben wird. Ein container ist immer Running, die Variable dient nur für die Übersicht
|
||||||
|
|||||||
Reference in New Issue
Block a user