68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Data.Sqlite;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Text.Json;
|
|
|
|
using watcher_monitoring.Payloads;
|
|
using watcher_monitoring.Data;
|
|
|
|
namespace watcher_monitoring.Controllers;
|
|
|
|
[Route("[controller]")]
|
|
public class MonitoringController : Controller
|
|
{
|
|
private readonly WatcherDbContext _context;
|
|
|
|
private readonly ILogger<MonitoringController> _logger;
|
|
|
|
public MonitoringController(WatcherDbContext context, ILogger<MonitoringController> logger)
|
|
{
|
|
_context = context;
|
|
_logger = logger;
|
|
}
|
|
|
|
// Registration Endpoint for watcher-agent
|
|
[HttpPost("registration")]
|
|
public async Task<IActionResult> Registration([FromBody] RegistrationDto dto)
|
|
{
|
|
// payload check
|
|
if (!ModelState.IsValid)
|
|
{
|
|
var errors = ModelState.Values
|
|
.SelectMany(v => v.Errors)
|
|
.Select(e => e.ErrorMessage)
|
|
.ToList();
|
|
|
|
_logger.LogError("Invalid registration payload");
|
|
return BadRequest(new { error = "Invalid registration payload", details = errors });
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
// Hardware Configuration Endpoint for watcher-agent
|
|
[HttpPost("hardware-configuration")]
|
|
public async Task<IActionResult> HardwareConfiguration ([FromBody] HardwareDto dto)
|
|
{
|
|
// payload check
|
|
if (!ModelState.IsValid)
|
|
{
|
|
var errors = ModelState.Values
|
|
.SelectMany(v => v.Errors)
|
|
.Select(e => e.ErrorMessage)
|
|
.ToList();
|
|
|
|
_logger.LogError("Invalid hardware configuration");
|
|
return BadRequest(new { error = "Invalid Hardware Configuration Payload", details = errors });
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
|
|
// Server-Metrics endpoint for watcher-agent
|
|
|
|
// Service-Detection endpoint for watcher-agent
|
|
|
|
// Service-Metrics endpoint for watcher-agent
|
|
|
|
} |