Compare commits
4 Commits
9a59e10b0c
...
v0.1.3
Author | SHA1 | Date | |
---|---|---|---|
340f92ed04 | |||
2169b3d45f | |||
27792ff7f4 | |||
2334287437 |
28
Tests/servicediscovery.py
Normal file
28
Tests/servicediscovery.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import json
|
||||
import urllib.request
|
||||
|
||||
url = "http://localhost:5000/monitoring/service-discovery"
|
||||
payload = {
|
||||
"ServerId": 1,
|
||||
"ContainerId": "aaaaaaaaaaaa",
|
||||
"Name": "test-Name",
|
||||
"Image": "test-Image"
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
|
@@ -12,7 +12,7 @@ using Watcher.ViewModels;
|
||||
|
||||
namespace Watcher.Controllers;
|
||||
|
||||
public class RegistrationDto
|
||||
public class HardwareDto
|
||||
{
|
||||
// Server Identity
|
||||
[Required]
|
||||
@@ -101,9 +101,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)
|
||||
@@ -140,7 +140,8 @@ public class MonitoringController : Controller
|
||||
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
|
||||
@@ -252,6 +253,8 @@ public class MonitoringController : Controller
|
||||
Name = dto.Name
|
||||
};
|
||||
|
||||
_logger.LogInformation(container.Name + " added for Host " + container.ServerId);
|
||||
|
||||
_context.Containers.Add(container);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
Reference in New Issue
Block a user